akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std ;

int main(void){
    int A,B,ans=0;

    cin >> A >> B;

    for(int i=A; i<=B; i++){
        int a = i %10;
        int b = i / 10 % 10;
        int c = i / 1000 % 10;
        int d = i / 10000 % 10;
        if(a==d && b==c) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
const long long INF = 1LL << 60;

ll N,sum = 0;

int main(){
  cin >> N;
  for(ll i = 1; i < N; ++i) sum += i;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let n: usize = read_as_vec()[0];
    let mut cur = (0, 0, 0);
    for i in 0..n{
        let line = read_as_vec::<i32>();
        let (t, x, y) = (line[0], line[1], line[2]);
        let distance = (x - cur.1).abs() + (y - cur.2).abs();
        let time = t - cur.0;
        if distance > time || distance%2 != time%2{
            println!("No");
            return;
        }
        cur = (t, x, y);
    }
    println!("Yes");
}


Measured memory_bytes: 4352
//////////////////////////////////*STRIKER(Devesh Ranjan)*////////////////////////////////////////////////////////////////////

#include<bits/stdc++.h>

using namespace std;
using ull=unsigned long long;
using ll=long long int;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 10000007
#define mod1 1000003
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define fr1(i,a,b) for(ll i=a;i<=b;i++)

/*BINARY EXPONENTIATION*/

ll binpow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b>>=1;
    }
    return res;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve()
{
    //Start Here:
    ll n;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    fr(i,0,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n+2][3];
    memset(dp,0,sizeof(dp));
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    fr(i,1,n)
    {
        fr(j,0,3)
        {
            fr(k,0,3)
            {
                if(k==j)
                {
                    continue;
                }
                if(j==0)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i]);
                }
                else if(j==1)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+b[i]);
                }
                else if(j==2)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+c[i]);
                }
            }
        }
    }
    int res=max(dp[n-1][0],dp[n-1][1]);
    res=max(res,dp[n-1][2]);
    cout<<res<<endl;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
    fastio;
    solve();
}

Measured memory_bytes: 2560
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	m := make(map[rune]int, 0)
	for _, v := range s { // 文字種の出現回数を数える
		m[v]++
	}
	ans := 1
	for _, v := range m { // 全ての文字種について、[選ばない, 1番目を選ぶ, 2番目を選ぶ, ... ]を掛け算する
		ans *= v + 1
		ans %= 1000000007 // 非常に大きな数になり得るので、10^9+7で割ったあまりを求めておく
	}
	fmt.Println(ans - 1) // 空文字列の場合を引く
}


Measured memory_bytes: 1280
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n, INF);
    dp[0] = 0;
    rep(i, n-1){
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        if(i + 2 < n){
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys


def solve(s: str):
    print(s[::2])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <cstdio>

int main(void) {
	int n;
	int p[20];

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

	int result = 0;
	for(int i = 1; i < n - 1; i++) {
		if((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
		   (p[i + 1] < p[i] && p[i] < p[i - 1])) {
			result++;
		}
	}

	printf("%d\n", result);

	return 0;
}

Measured memory_bytes: 128
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
if A[0]>X or A[-1]<X:
  print(0)
else:
  for i in range(M-1):
    if A[i]<X<A[i+1]:
      now=i
      break
  print(min(now+1,M-(now+1)))

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

class rational {
private:
  static ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
public:
  ll p, q;
  rational(ll _p, ll _q) {
    ll g = gcd(_p, _q);
    p = _p / g;
    q = _q / g;
  }
  bool operator==(const rational r) const { return p * r.q == q * r.p; }
  bool operator<(const rational r) const { return p * r.q < q * r.p; }
};

int main(void) {
  ll H, W;
  cin >> H >> W;
  vector<string> S(H + 1);
  REP(i, 0, H) {
    cin >> S[H - i - 1];
    S[H - i - 1] += '.';
  }
  S[H] = "";
  REP(i, 0, W + 1) S[H] += '.';

  vector<rational> vec;
  vec.push_back(rational(0, 1));
  vec.push_back(rational(1LL << 50, 1));
  REP(i, 0, H) REP(j, 0, W) {
    if(j != 0) vec.push_back(rational(i + 1, j));
    if(i != 0) vec.push_back(rational(i, j + 1));
    vec.push_back(rational(i + 1, j + 1));
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());

  vector<ll> imos(vec.size() + 1, 0);
  REP(i, 0, H) REP(j, 0, W) {
    if(S[i][j] != S[i + 1][j]) {
      ll s = lower_bound(vec.begin(), vec.end(), rational(i + 1, j + 1)) - vec.begin();
      ll e = lower_bound(vec.begin(), vec.end(), j != 0 ? rational(i + 1, j) : rational(1LL << 50, 1)) - vec.begin();
      imos[s + 1]++;
      imos[e + 1]--;
    }
    if(S[i][j] != S[i][j + 1]) {
      ll s = lower_bound(vec.begin(), vec.end(), i != 0 ? rational(i, j + 1) : rational(0, 1)) - vec.begin();
      ll e = lower_bound(vec.begin(), vec.end(), rational(i + 1, j + 1)) - vec.begin();
      imos[s + 1]++;
      imos[e + 1]--;
    }
  }
  REP(i, 0, imos.size() - 1) imos[i + 1] += imos[i];

  ll ans = 0;
  REP(i, 0, imos.size() - 1) ans = max(ans, imos[i]);
  cout << (ans + 1) / 2 + 1 << endl;
}



Measured memory_bytes: 36592
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG /GCC環境下で[]による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
 int64_t n;
 cin>>n;
 int64_t a =sqrt(n);
 int64_t b;
 for(int64_t i=a;i>0;i--){
   if(n%i==0){
     b=n/i;
     break;
   }
 }
 string str=to_string(b);
 cout<<str.size()<<endl;
}
    
   

  

Measured memory_bytes: 3756
S = input()
Y = int(S[:2])
M = int(S[2:])
if M >= 1 and M <= 12:
    if  Y>= 1 and Y <= 12:
        print("AMBIGUOUS")
    else:
        print("YYMM")
else:
    if Y>= 1 and Y <= 12:
        print("MMYY")
    else:
        print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    ll h,w,k;cin>>h>>w>>k;
    string s[h];rep(i,0,h-1)cin>>s[i];
    ll a[h][w];memset(a,0,sizeof(a));
    ll lasi=0;
    bool ex[h];memset(ex,false,sizeof(ex));
    rep(i,0,h-1){
        rep(j,0,w-1)if(s[i][j]=='#')ex[i]=true;
    }
    for(ll i=h-1;i>=0;i--)rep(j,0,w-1)if(s[i][j]=='#'){lasi=i;break;}
    
    ll count=1;
    rep(i,0,h-1){
        if(!ex[i])continue;
        vector<ll>v;
        rep(j,0,w-1){
            if(s[i][j]=='#'){
                a[i][j]=count;count++;
            }
        }
        rep(j,0,w-2){
            if(a[i][j]!=0&&a[i][j+1]==0)a[i][j+1]=a[i][j];
        }
        for(ll j=w-1;j>=1;j--){
            if(a[i][j]!=0&&a[i][j-1]==0)a[i][j-1]=a[i][j];
        }
    }
    rep(j,0,w-1){
        rep(i,0,h-2){
            if(a[i][j]!=0&&a[i+1][j]==0)a[i+1][j]=a[i][j];
        }
        for(ll i=h-1;i>=1;i--){
            if(a[i][j]!=0&&a[i-1][j]==0)a[i-1][j]=a[i][j];
        }
    }
    rep(i,0,h-1){
        rep(j,0,w-1)cout<<a[i][j]<<" ";cout<<endl;
    }
    
    return 0;
}


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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int N, Q, K;
vector<int> x, y;
vector<vector<pair<int, int>>> g;
vector<ll> homon;

void dfs(int c, ll dist){
  homon[c] = dist;
  REP(i, g[c].size()){
    if( homon[g[c][i].first] == -1){
      dfs(g[c][i].first, dist+g[c][i].second);
    }
  }
}
int main(){
  cin >> N;
  int a, b, c;
  g.resize(N);
  homon.resize(N, -1);
  REP(i, N-1){
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  cin >> Q >> K;
  x.resize(Q), y.resize(Q);
  REP(i, Q){
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
  }
  K--;
  dfs(K, 0);
  REP(i, Q){
    cout << homon[x[i]]+ homon[y[i]] << endl;
  }

  return 0;
}


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

const int N = 2010, mod = 1e9+7;
int f[N];

int main(){
	int n;
	cin >> n;
	for(int i = 3; i <= n; i++){
		f[i] = 1;
	}
	for(int i = 4; i <= n; i++){
		for(int j = 3; j <= i; j++){
			f[i] = (f[i] + f[i - j]) % mod;
		}
	}	
	cout << f[n] << endl;
}

Measured memory_bytes: 3608
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n, m, l = map(int, readline().split())
graph = [[0] * n for _ in range(n)]
inf = float('inf')
for i in range(m):
    a, b, c = map(int, readline().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c
cost = floyd_warshall(csr_matrix(graph))
cnt = [[0] * n for _ in range(n)]
for i, cost_i in enumerate(cost):
    for j, v in enumerate(cost_i):
        if l >= v:
            cnt[i][j] = 1
cnt = floyd_warshall(csr_matrix(cnt))
q = int(readline())
for _ in range(q):
    s, t = map(int, readline().split())
    if cnt[s - 1][t - 1] == inf:
        print(-1)
    else:
        print(int(cnt[s - 1][t - 1] - 1))


Measured memory_bytes: 21140
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll n,m,c=0; cin>>n>>m;
  vector<pair<int,int>> p(n);
  rep(i,0,n) cin>>p[i].first>>p[i].second;
  sort(all(p));
  rep(i,0,n){
    ll a=p[i].first,b=p[i].second;
    if(m>=b){c+=a*b; m-=b; continue;}
    c+=a*m; 
    break;
  }
  co(c);
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

ll gcd(ll a, ll b)
{
	if (a == 0)
		return 0;
	if (b == 0)
		return 0;
	ll x;
	while (1)
	{
		x = a % b;
		if (x == 0)
			return b;
		else
		{
			a = b;
			b = x;
		}
	}
}

ll lcm(ll a, ll b)
{
	ll ans, gcd_ab;
	gcd_ab = gcd(a, b);
	ans = a * b / gcd_ab;
	return ans;
}

int main() {
	ll N, M;
	cin >> N >> M;
	ll L = 1;
	ll mod2 = -1;
	rep(i, N) {
		ll a;
		cin >> a;
		L = lcm(L, a);
		ll mod2tmp = 0;
		while (1) {
			if (a % 2 == 1)
				break;
			a /= 2;
			mod2tmp++;
		}
		if (mod2 == -1)
			mod2 = mod2tmp;
		else {
			if (mod2 != mod2tmp) {
				cout << "0" << endl;
				return 0;
			}

		}
	}
	M += (L / 2);
	ll ans = M / L;
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  cin >>s;
  int check =0;
  for(int i=0;i<3;i++){
    if(s.at(i)==s.at(i+1)){
      cout << "Bad" <<endl;
      check++;
      break;
    }
  }
  if(check!=1){
    cout << "Good" << endl;
  }
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int a, b; cin >> a >> b;
	int ret;
	if (a>9 || b>9) ret = -1;
	else ret = a * b;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
/*author:revolIA*/
/*明日を変えるなら今日変えなきゃ*/
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+7;
long long n,dp[maxn],v[maxn],cnt;
int main(){
    scanf("%lld",&n);
    int Sqrt_n = sqrt(n);
    for(int i=Sqrt_n;i>=2;i--){
        if(n%i == 0)return 0*printf("%lld",n/i+i-2);
    }
    printf("%lld\n",n-1);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = sorted([int(s) for s in input().split()])
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if L[i] == L[j]:
            continue
        for k in range(j + 1, N):
            if L[j] == L[k]:
                continue
            cnt += 1 if L[i] + L[j] > L[k] else 0
print(cnt)

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

int main()
{
	ll n;
	cin>>n;
	string s[n];
	ll a[n],i;
	for(i=0;i<n;i++)
	{
		cin>>s[i]>>a[i];
	}
	string b;
	cin>>b;
	ll p=0,f=0;
	for(i=0;i<n;i++)
	{
		if(f==-1)
			p+=a[i];
		if(s[i]==b)
		{
			f=-1;
		}
	}
	cout<<p<<"\n";
}

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

namespace ConsoleApp106 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long sum = a.Sum();

            long[] E = new long[N + 3];

            E[0] = a[0];

            for (int i = 1; i < N; i++) {
                E[i] = E[i - 1] + a[i];
            }

            long ans = Math.Abs((a.Sum() - a[0]) - a[0]);
            long kari = 0;

            for (int i = 0; i < N - 1; i++) {
                kari = Math.Abs((sum - E[i]) - E[i]);
                ans = Math.Min(ans, kari);
            }
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 35908
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
      
  int a, b, t;
  cin >> a >> b >> t;
  int time = (t + 0.5) / a;
  cout << time * b << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(int,n,k);
  VEC(int,l,n);
  sort(ALL(l));
  reverse(ALL(l));
  int ans = 0;
  REP(i,k){
    ans += l[i];
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define MAX_V 100001
#define COSTBIAS 10000
#define INF (1e9+1)
ll n,ans,k,c,ans2=0;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	ans=n;
	k=0;
	while(1){
		if(n!=0)k++;
		else break;
		if(n%10!=9&&n>9)ans2=1;
		c=n;
		n/=10;
	}
	n=ans;
	ans=c+9*(k-1);
	if(ans2)ans--;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll N, noZN, al, noZoN, tmp, ans;
    ll md = 1000000007;

    cin >> N;

    al = modpow(10, N, md);
    noZN = modpow(8, N, md);
    noZoN = modpow(9, N, md);

    ans = al - 2*noZoN + noZN;

    if(ans<0) ans += md;
    if(ans<0) ans += md;

    cout << ans%md << endl;

    return 0;
    
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define err(A) cout << #A << " = " << (A) << endl
using namespace std;

const int N=1e2+10,mod=1e9+7,M=1e5+100;
/*E*/

ll dp[N][M];
ll w[N];
ll v[N];

int32_t main(){
    ll n,k;
    cin >> n >> k;
    for (int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=k;j++){
            dp[i][j]=dp[i-1][j];
            if (w[i]<=j){
                dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[n][k];
}


Measured memory_bytes: 79360
#include<cstdio>
int n;
struct node{
	int to,next,v;
}e[200001];
int ans[100001];
int head[100001],cnt;
inline void AddEdge(int u,int v,int val) {
	e[++cnt].to=v;
	e[cnt].v=val;
	e[cnt].next=head[u];
	head[u]=cnt;
}
inline void dfs(int now,int prt,int sum) {
	ans[now]=sum;
	for(int i=head[now];i;i=e[i].next) {
		int lv=e[i].to;
		if(lv!=prt) {
			if(e[i].v%2) dfs(lv,now,sum^1);
			else dfs(lv,now,sum);
		}
	}
}
int main() {
	scanf("%d",&n);
	for(int i=1,u,v,w;i<n;i++) {
		scanf("%d %d %d",&u,&v,&w);
		AddEdge(u,v,w);
		AddEdge(v,u,w);
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 7644
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,a[222222],b[222222],cur,ans,pos,cnt,sum;
int main()
{
	scanf("%lld",&n);
	ans=1e18;
	for (long long i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&b[i]);
		if (a[i]>b[i]) ans=min(ans,b[i]);
		sum+=a[i];
	}
	ans=min(ans,sum);
	ans=sum-ans;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	ll H, N;
	cin >> H >> N;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		ll A;
		cin >> A;
		sum += A;
	}
	if (sum >= H)puts("Yes");
	else puts("No");


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN=500100;
const int MAXK=16;
const int INF = 1e9;
const ll MOD = 1e9+7;

ll N,M,K,Q,u,v,w,a,b,c;
vpi V[MAXN];

ll fact[MAXN];
ll finv[MAXN];

ll qexp(ll a, ll b){
	if(b==0)return 1;
	ll h=qexp(a,b/2);
	h=h*h%MOD;
	if(b%2)h=h*a%MOD;
	return h;
}

ll qinv(ll a){return qexp(a,MOD-2);}

ll choose(ll a, ll b){
	return fact[a]*finv[b]%MOD*finv[a-b]%MOD;
}

int main(){
	cin>>N>>M;
	fact[0]=1;
	for(int i=1;i<=M;++i){
		fact[i]=fact[i-1]*i%MOD;
	}
	for(int i=0;i<=M;++i)finv[i]=qinv(fact[i]);
	ll A = fact[M]*finv[M-N]%MOD;
	ll B=A;
	for(int i=1;i<=N;++i){
		ll a=choose(N,i);
		ll lft=M-i;
		ll r=fact[lft]*finv[M-N]%MOD;
		if(i%2==1)A=(A+MOD-(a*r)%MOD)%MOD;
		else A=(A+a*r)%MOD;
	}
	cout<<A*B%MOD;
}

Measured memory_bytes: 23096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

ll dfs(string S,int K){
  if(K==0){
    return 1;
  }
  if(S.size()==1){
    if(K==1){
      return S.at(0)-'0';
    }else{
      return 0;
    }
  }
  if(S.at(0)=='0'){
    return dfs(S.substr(1),K);
  }
  int N=S.size();
  ll ret1;
  ll ret2;
  if(K==3){
    ret1=(N-1)*(N-2)*(N-3)*729/6;
    ret2=(N-1)*(N-2)*81/2;
  }else if(K==2){
    ret1=(N-1)*(N-2)*81/2;
    ret2=(N-1)*9;
  }else{
    ret1=(N-1)*9;
    ret2=1;
  }

  return ret1+ret2*(S.at(0)-'0'-1)+dfs(S.substr(1),K-1);
}

int main()
{
  string S;
  cin >> S;
  int K;
  cin >> K;

  cout << dfs(S,K) << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define add(a, b) a = (a+b < M ? a+b : a+b-M)

using namespace std;
typedef long long ll;
const ll M = 1e9+7;
const int K = 102;
const int SQ = 80000;

int n, k;
int sz;
int mx[SQ];
int f2[K][SQ];
int pf[K][SQ];
int L[SQ], R[SQ];
int main(){
    ios::sync_with_stdio(0);
    cin >> n >> k;
    set <int> fracts;
    for (int i = 1; i*i <= n; ++ i){
        int x = n/i;
        fracts.insert(x);
        fracts.insert(n/x);
    }

    for (int i: fracts){
        L[sz] = n/(i+1)+1;
        R[sz] = n/i;
        ++ sz;
    }

    for (int i = 0; i < sz; ++ i)
        mx[i] = sz-i-1;

    for (int j = 0; j < sz; ++ j)
        f2[0][j] = R[j]-L[j]+1;
    for (int j = sz-1; j >= 0; -- j){
        pf[0][j] = pf[0][j+1]+f2[0][j];
    }

    for (int i = 1; i < k; ++ i){
        for (int j = 0; j < sz; ++ j){
            f2[i][j] = ((R[j]-L[j]+1)*1LL*pf[i-1][mx[j]])%M;
        }
        for (int j = sz-1; j >= 0; -- j){
            pf[i][j] = (pf[i][j+1]+f2[i][j])%M;
        }
    }

    ll ans = 0;
    for (int j = 0; j < sz; ++ j){
        ans += f2[k-1][j];
        ans %= M;
    }
    cout << ans << endl;

}


Measured memory_bytes: 66816
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <utility>
#include <map>
using pii = pair<int, int>;
pii parse(int a) {
    int lst = a % 10;
    int fst = -1;
    while (a) {
        fst = a;
        a /= 10;
    }
    return {fst, lst};
}
#include <tuple>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    map<pii, int> store;
    REP(i, 1, n + 1) {
        int fst, lst;
        tie(fst, lst) = parse(i);
        store[{fst, lst}]++;
    }
    REP (i, 1, n + 1) {
        int fst, lst;
        tie(fst, lst) = parse(i);
        ans += store[{lst, fst}];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <sstream>
#include <iomanip>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main(){
    int n;int k;
    cin >> n >> k;
    double res = 0;
    for(int i=1;i<=n;i++){
        int q = i;
        int f = 0;
        while(q < k){
            f++;q*=2;
        }
        res += 1. / n * pow(2, -f);
    }
    cout << fixed << setprecision(10) << res << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

vector<P> vec[110000];
int k;
ll d[110000];

void dfs(int p){
  for(P x : vec[p]){
    if(d[x.first] != 0 || x.first == k-1) continue;
    d[x.first] = d[p] + x.second;
    dfs(x.first);
  }
}

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n - 1; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    vec[a].push_back(P(b, c));
    vec[b].push_back(P(a, c));
  }
  int q;
  cin >> q >> k;
  d[k-1] = 0;
  dfs(k-1);
  for(int i = 0; i < q; i++){
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << d[x] + d[y] <<endl;
  }
}
  

Measured memory_bytes: 11392
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

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

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long llINF = 1e18;
#pragma endregion

int main () {
    llint n, a, b; cin >> n >> a >> b;
    llint ab = a + b;
    llint ans = 0;
    if (n > ab) {
        llint kaisuu = n / (ab);
        llint nokori = n - ((ab) * kaisuu);
        if (nokori <= a) {
            ans += a * kaisuu + nokori;
        } else {
            ans += a * kaisuu + a;
        }
        cout << ans << endl;
        return 0;
    } else if (a == 0) {
        cout << "0" << endl;
        return 0;
    } else if (n <= ab) {
        if (n - a >= 0) {
            cout << a << endl;
            return 0;
        } else {
            cout << n << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import Data.Char

main = interact $ unlines . map (show' . koto_subway) . read' . lines
 where
  read' ("0 0":_) = []
  read' (de:xs) = map read (words de) : read' xs
  show' r = normalize (show r)

koto_subway [d,e] = minimum [abs (distance x y - fromIntegral e) | x<-[0..d], y<-[0..d], x+y==d]
 where distance x y = sqrt (fromIntegral (x^2 + y^2))

normalize xs
 | notElem 'e' xs = xs
 | otherwise = ("0." ++ replicate (read [e] - 1) '0' ++ (filter isDigit ns))
  where (ns,['e','-',e]) = break (=='e') xs

Measured memory_bytes: 4396
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define forin(x,y) for(ll i=x;i<y;i++)
#define vii vector<ll>
#define pii  pair<ll,ll>
#define pb push_back
#define mp make_pair
#define md (ll)(1e9 + 7)
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<vii>v ;
vector<vii> dp;

ll evaluate(ll h,ll w)
{
    if(h<1 || w<1) return 0;
    if(dp[h][w] != -1)  return dp[h][w];
    if(v[h][w] == -1)
    {
        dp[h][w] =0;
    }
    else
    {
        dp[h][w] = (evaluate(h,w-1) + evaluate(h-1,w))%md;
    }
    return dp[h][w];
}
int main()
{
    ios::sync_with_stdio(false);    cin.tie(0);     cout.tie(0);
    ll h,w;     char c; cin>>h>>w; 
    
    v.resize(h+1);
    for(auto &i : v)   i.resize(w+1,0);
    
    dp.resize(h+1);
    for(auto &i: dp)    i.resize(w+1,-1);

    for(ll i=1;i<=h;++i)
    {
        for(ll j=1;j<=w;++j)
        {
            cin>>c;
            if(c=='.')  v[i][j]=0;
            else v[i][j] = -1;
        }
    }
    dp[1][1] = 1;
    evaluate(h,w);
    cout<<dp[h][w]%md<<endl;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5, M = 2e5;
const ll LINF = 1e18 + 5;
int n, a[N];
ll m, sum[N];
int find(int x) //rightmost higher
{
	int l = 1, r = n, p = 0;
	while(l<=r)
	{
		int mid = (l+r)>>1;
		if(a[mid]>=x) l = mid + 1, p = mid;
		else r = mid - 1;
	}
	return p;
}
bool check(int x)
{
	ll cur = 0;
	for(int i=1; i<=n; i++)
	{
		cur += find(x-a[i]);
		if(cur>=m) return 1;
	}
	return 0;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> m;
 	for(int i=1; i<=n; i++) cin >> a[i];
 	sort(a+1, a+n+1, greater<int>());
 	for(int i=1; i<=n; i++) sum[i] = sum[i-1] + a[i];
 	int l = 1, r = M, low = 0;
 	while(l<=r)
 	{
 		int mid = (l+r)>>1;
 		if(check(mid)) l = mid + 1, low = mid;
 		else r = mid - 1;
 	}
 	ll res = 0, cur = 0;
 	for(int i=1; i<=n; i++)
 	{
 		int p = find(low-a[i]);
 		res += sum[p] + 1ll*p*a[i];
 		cur += p;
 	}
 	res -= 1ll*low*(cur-m);
 	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 1536
import sys
sys.setrecursionlimit(1000000)
n = int(input())
hs = list(map(int, input().split()))

def best(plants, counter):
    all0 = True
    started = False
    for i,p in enumerate(plants):    
        if p > 0:
            all0 = False
        if p == 0:
            if started:
                break
            else:
                continue
        plants[i] -= 1
        started = True

    if all0:
        return counter
    return best(plants, counter+1)
    
cnt = best(hs, 0)
print(cnt)



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

void fnInput(int& rnHighNum, int& rnMinSum, int& rnMaxSum)
{
  cin >> rnHighNum >> rnMinSum >> rnMaxSum;
}

int fnDigitsSum(int nNum)
{
  int nDigitsSum = 0;
  while ( nNum )
  {
    nDigitsSum += nNum % 10;
    nNum /= 10;
  }
  return nDigitsSum;
}

int fnSomeSums(int nHighNum, int nMinSum, int nMaxSum)
{
  int nTotal = 0;
  for (int n = 1; n <= nHighNum; n++)
  {  
    int nDigitsSum = 0;
    nDigitsSum += fnDigitsSum(n);
    if (nMinSum <= nDigitsSum && nDigitsSum <= nMaxSum)
      nTotal += n;
  }
  return nTotal;
}

int main()
{
  int nHighNum, nMinSum, nMaxSum;
  fnInput(nHighNum, nMinSum, nMaxSum);

  cout << fnSomeSums(nHighNum, nMinSum, nMaxSum) << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

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

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

	int res = min(b, d) - max(a, c);

	cout << ((res > 0) ? res : 0) << '\n';
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long n,a[100005],b[100005],sa=0,sb=0,sm=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i],sa+=a[i];
	for(int i=0;i<n;i++)cin>>b[i],sb+=b[i];
	if(sa<sb){cout<<-1<<endl;return 0;}
	for(int i=0;i<n;i++)a[i]-=b[i];
	sort(a,a+n);
	if(a[0]>=0){cout<<0<<endl;return 0;}
	for(int i=0;i<n;i++){if(a[i]<0){sm+=a[i]*(-1);ans++;}}
	for(int i=n-1;i>=0;i--)
	{
		sm-=a[i];
		ans++;
		if(sm<=0)
		{
			cout<<ans<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(void){
    int n, b, f, r, v, data[5][4][11] = {};
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> b >> f >> r >> v;
        data[b][f][r] += v;
    }
    for(int B=1; B<=4; B++){
        for(int F=1; F<=3; F++){
            for(int R=1; R<=10; R++){
                cout << " " << data[B][F][R];
            }
            cout << endl;
        }
        if(B<=3)cout << "####################" << endl;
    }
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

// 愚直計算による二項係数計算
mint com(long long n, long long r) {
mint res = 1;
for (long long i = 0; i < r; ++i) {
res *= (n-i);
res /= (i+1);
}
return res;
}

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

int N;
cin >> N;
vl c(N);
rep(i,N) cin >> c[i];
sort(all(c));

mint U = modpow((mint)2, N);
mint sum = 0;
rep(i,N) {
    sum += (mint)c[i] * U / 4 * (N + 1 - i);
}

mint ans = sum * U;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int d, l, r;
	cin >> l >> r >> d;
	int ans= 0;
	for(int i = l; i<=r;i++){
		if( i % d == 0) ans ++;
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
   signed short n,i,j;
   signed long result=0;
   scanf("%hd",&n);
   signed short* d = (signed short*) malloc(n * sizeof(signed short));
   for(i = 0;i<n;i++)
   {
       scanf("%hd",d+i);
   }
   for(i=0;i<n;i++)
   {
       for(j=i+1;j<n;j++)
       {
           result = result + d[i]*d[j];
       }
   }
   
   printf("%ld",result);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int maxn = 15;
const int inf = 0x3f3f3f3f;

int mmap[maxn][maxn];
LL in[1 << maxn];
LL dp[1 << maxn][maxn];
int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0, f, t, d; i < m; ++i)
	{
		scanf("%d%d%d", &f, &t, &d);
		mmap[t - 1][f - 1] = mmap[f - 1][t - 1] = d;
	}
	for (int i = 0; i < (1 << n); ++i)
		for (int j = 0; j < n; ++j)
			if (i & (1 << j))
				for (int k = j + 1; k < n; ++k)
					if (i & (1 << k))
						in[i] += mmap[j][k];
	for (int i = 0; i < (1 << n); ++i)
		for (int j = 0; j < n; ++j)
			dp[i][j] = -inf;
	for (int i = 0; i < (1 << n); ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i & (1 << j))
			{
				if (!j)
					dp[i][j] = in[i];
				else
				{
					for (int k = 0; k < n; ++k)
						if (j != k && (i & (1 << k)) && mmap[k][j])
							dp[i][j] = max(dp[i][j], dp[i ^ (1 << j)][k] + mmap[k][j]);
					for (int tmp = (i ^ (1 << j)), k = tmp; k; k = (k - 1) & tmp)
						dp[i][j] = max(dp[i][j], dp[i ^ k][j] + in[k | (1 << j)]);
				}
			}
		}
	}
//	 cout << in[(1 << n) - 1] << endl;
	printf("%lld\n", in[(1 << n) - 1] - dp[(1 << n) - 1][n - 1]);
	return 0;
}


Measured memory_bytes: 4352
n = int(input())
s = str(input())
l_w = [0]
l_e = [0]
cnt = 0
lists = []
for i in range(n):
    if s[i] == "W":
        cnt += 1
        l_w.append(cnt)
    else:
        l_w.append(cnt)
cnt = 0
for i in range(n):
    if s[i] == "E":
        cnt += 1
        l_e.append(cnt)
    else:
        l_e.append(cnt)
for i in range(len(l_e)-1):
    ans = l_w[i] + (l_e[-1] - l_e[i+1])
    lists.append(ans)
print(min(lists)) 


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

int main() {
    string s;
    int x, y, j = 0, k = 0;
    cin >> s >> x >> y;
    list<int> nums[2];
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            nums[j].emplace_back(k);
            k = 0;
            j = 1 - j;
        } else {
            k++;
        }
    }
    nums[j].emplace_back(k);
    x -= nums[0].front();
    nums[0].pop_front();
    auto knapsack = [&](list<int>& nums, int target)->bool {
        int size = s.size() * 2 + 1;
        if (s.size() + target >= size) {
            return false;
        }
        vector<bool> table(size);
        auto dp = [&](int i) {
            return table[s.size() + i];
        };
        dp(0) = true;
        for (int i : nums) {
            vector<bool> next(size);
            for (int j = 0; j < size; j++) {
                if (j - i >= 0) {
                    next[j] = next[j] || table[j - i];
                }
                if (j + i < size) {
                    next[j] = next[j] || table[j + i];
                }
            }
            swap(next, table);
        }
        return dp(target);
    };
    if (knapsack(nums[0], x) && knapsack(nums[1], y)) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a+b < 10){
        cout << a+b << endl;
    }
    else{
        cout << "error" << endl;
    }
}


Measured memory_bytes: 256
N, M = map(int, input().split())

broken = [False] * (N + 1)
for i in range(M):
    broken[int(input())] = True
dp = [0] * (N + 2)
mod = 1000000007
dp[N] = 1
for i in range(N-1,-1,-1):
    if broken[i]:
        dp[i] == 0
        continue
    dp[i] = (dp[i+1]+ dp[i+2]) % mod
    
print(dp[0])


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

ll N;
string S;

int main() { 
    cin >> N >> S;
    S.push_back('%');
    ll out = 0;
    for (int i = 0; i < N; i++) {
      if (S[i] == S[i + 1]) {
        continue;
      } else {
        out++;
      }
    }
    cout << out << endl;
    return 0; 
}

Measured memory_bytes: 3768
#include<iostream>
using namespace std;
int n, w[100009],w_copy[100009], k, p, n_copy;
bool used[100009];
void insertionSort(int*, int, int);
void shellSort(int*, int);
bool check(int);
bool binarySearch(int);

int main() {
	cin >> n >> k;
	n_copy = n;
	int sum = 0, max = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		sum += w[i];
		if (max < w[i]) max = w[i];
	}

	//shellSort(w, n);

	for (int i = 0; i < n; i++) {
		//cerr << w[i] << " ";
		w_copy[i] = w[i];
	}
	
	if (sum / k > max) {
		if(sum % k == 0) p = sum / k;
		else p = sum / k + 1;
	}
	else p = max;
	
	

	//if (check(10)) ////cerr << "10 is ok" << endl;
	//else ////cerr << "10 is NG" <<  " n: " << n << endl;
	
	
	while (1) {
		//cerr << "start: " << p << endl;
		if (check(p)) {
			cout << p << endl;
			break;
		}
		p++;
	}
	
	return 0;
	
}

void insertionSort(int A[], int n, int g) {
	for (int i = g; i <= n - 1; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v)
		{
			A[j + g] = A[j];
			j = j - g;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	int G[1000];
	int j = 0;
	for (int i = 1; i <= n / 9 +1; i = i * 3 + 1) {
		G[j++] = i;
	}
	int m = j - 1;
	for (int i = m; i >= 0; i--) {
		////cerr << "G" << i << ": " << G[i] << endl;
		insertionSort(A, n, G[i]);
	}
}

bool check(int p) {
	n = n_copy;
	for (int i = 0; i < n; i++) {
		w[i] = w_copy[i];
	}

	int j = 0;

	for (int i = 0; i < k; i++) {
		//cerr << "Track number: " << i + 1 << endl;
		int empty = p;
		while (empty > 0) {
			if (j == n) {
				return true;
				//cerr << "Check OK: " << p << endl;
			}
			if (w[j] <= empty) {
				//cerr << j << " was loaded "<<  endl;
				empty -= w[j++];
				//cerr << "empty: " << empty << endl;

			}
			else {
				//cerr << j << " was not loaded" << endl;
				//cerr << "empty: " << empty << endl;
				break;
			}
		}

	}
	if (j == n) {
		//cerr << "Check OK: " << p << endl;
		return true;
		
	}

	//cerr << "Check NG: " << p << endl;
	return false;

	/*
	for (int i = 0; i < k; i++) {
		////cerr << "Track number: " << i + 1 << endl;
		int key = p;
		int empty = p;
		while (1) {
			if (empty == 0) break;
			if (key == 0) break;
			if (n == 0) {
				////cerr << "Check OK: " << p << endl;
				return true;
			}
			if (binarySearch(key)) {
				empty -= key;
				if(empty < key) key = empty;
			}
			else key--;
		}
	}
	if (n > 0) {
		////cerr << "Check NG: " << p  << endl;
		return false;
	}
	else return true;
	*/
}

bool binarySearch(int key) {
	////cerr << "binarySearch key: " << key << endl;
	int left = 0;
	int right = n;
	while (left < right) {
		int mid = (left + right) / 2;
		if (w[mid] == key){
			////cerr << "Search : Successful" << endl;
			for (int i = mid; i < n; i++) {
				if(i != n-1) w[i] = w[i + 1];
				else w[i] = 0;
			}
			n--;
			return true;
		}
		else if (key < w[mid]) right = mid;
		else left = mid + 1;
	}
	////cerr << "Search : False" << endl;
	return false;
}

Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
int sz = 100002;
int n, m;
vector<int>ar;
//vector<int>tree[sz];
int main() {
// freopen("input.txt", "r", stdin); 
// freopen("output.txt", "w", stdout); 
	int ans = -1;
	cin>>n>>m;
	ar.resize(m);
	ll sum  = 0;
	for(int i = 0; i<m; i++) {
		cin>>ar[i];
		sum+=ar[i];
	}
	if(sum>n) {
		cout<<ans<<endl;
	}
	else {
		cout<<n-sum<<endl;
	}
	
}


Measured memory_bytes: 3640
//abc148_a.cpp
//Sun Dec 22 20:45:47 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int ans[3];
	fill(ans,ans+3,1);

	ans[a]--;
	ans[b]--;

	if (ans[0]){
		cout << 1 << endl;
	}else if (ans[1]){
		cout << 2 << endl;
	}else if (ans[2]){
		cout << 3 << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,t=0,ans=0;
    cin >> N;
    vector<long> a(N);
    for (int i=0;i<N;i++){
        cin >> a.at(i);
    }
    while (true){
        for (int i=0;i<N;i++){
        if (a.at(i)%2==0) t++;
        a.at(i)=a.at(i)/2;
    }
    if (t==N) {ans++;t=0;}
    else break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256