akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

map<string,string> m;

string b2f(string bin) {
  if (bin.size() % 2) bin = string("0") + bin;
  
  string ret;
  for (int i = 0; i < bin.size(); i+=2) {
    string temp = bin.substr(i, 2);
    ret += m[temp];
  }
  return ret;
}

string d2b(int a) {
  if (a == 0) return string("0");
  string s;
  while (a) {
    string b(" ");
    char c = '0' + (a % 2);
    b[0] = c;
    s += b;
    a /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}

int main() {
  const string b[4] = {"00", "01", "10", "11"};
  const string d[4] = {"0", "1", "2", "3"};
  rep (i,4) m.insert(make_pair(b[i], d[i]));

  int n;
  while (cin >> n) {
    if (n == -1) break;
    cout << b2f(d2b(n)) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int a,b;
  cin >> a >> b;
  if(a+b==15){
    cout << "+" << endl;
  } else if(a*b==15){
    cout << "*" << endl;
  } else {
    cout << "x" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<time.h>
using namespace std;

int main()
{
	char C1[4], C2[4];
	cin >> C1 >> C2;
	if (C1[0] == C2[2] && C1[1] == C2[1] && C1[2] == C2[0])cout << "YES";
	else cout << "NO";
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Dynamic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 0; i < 2000; i++)
            {
                var n = ReadInt();
                if (n == -1) break;
                if (n == 0) WriteLine(0);
                else WriteLine(IntToNString(n,4));
            }
        }
        public static string IntToNString(int x, int n)
        {
            var nstring = "";
            var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
            int r = 1; 
            int q = x;  
            while (q > 0)
            {
                r = q % n;
                nstring += numbers[r];
                q = q / n;
            }
            return string.Join("", nstring.Reverse());
        }
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int sum=0;
	if(k<=a)cout<<k;
	else if(k<=a+b)cout<<a;
	else cout<<2*a+b-k;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 1; i < (int) s.size(); ++i) {
        if (s[i] != s[i-1]) ++cnt;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int H, W, K;
    cin >> H >> W >> K;
    int sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    --sh, --sw, --gh, --gw;
    vector<string> fi(H);
    REP(i,H) cin >> fi[i];

    queue<pair<int, int>> q;
    q.emplace(sh, sw);
    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[sh][sw] = 0;
    while(!q.empty()){
        auto [h, w] = q.front(); q.pop();
        REP(i,4){
            for(int k=1;k<=K;k++){
                int nh = h + k * dx[i], nw = w + k * dy[i];
                if(nh < 0 || nh >= H || nw < 0 || nw >= W) break;
                if(fi[nh][nw] == '@') break;
                if(dist[nh][nw] <= dist[h][w]) break;
                if(dist[nh][nw] > dist[h][w] + 1){
                    dist[nh][nw] = dist[h][w] + 1;
                    q.emplace(nh, nw);
                }
            }
        }
    }

    if(dist[gh][gw] == INF) dist[gh][gw] = -1;
    cout << dist[gh][gw] << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 12192
#include <stdio.h>

using namespace std;

int main(){
	int a,b,c,count = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(int i = a; i <= b; i++){
		if(c%i == 0) count++;
	}
	printf("%d\n",count);
}


Measured memory_bytes: 2736
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[202020];
int main()
{
	int n,l=1,r=1;
	long long ans=0;
	int nowv=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	while(l<=n)
	{
		while(r<=n&&(nowv&a[r])==0)
		{
			nowv|=a[r];
			r++;
		}
		ans+=r-l;
		nowv^=a[l];
		l++;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
/*---> 16 January 2020 <--- > 13:25:06 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;
int fact[2*N],factInv[2*N],inv[2*N];
int ncr(int n,int r){
	if(n<r)
		return 0;
	if(r==1)
		return n;
	if(n==r || r==0)
		return 1;
	return (((fact[n]*factInv[n-r])%mod)*factInv[r])%mod;
}
int32_t main(){__
	int n,k;
	cin>>n>>k;
	fact[0]=fact[1]=inv[1]=factInv[1]=factInv[0]=1;
	for(int i=2;i<=2*n;i++){
		fact[i]=(i*fact[i-1])%mod;
		inv[i]=mod-((mod/i)*inv[mod%i])%mod;
		factInv[i]=(inv[i]*factInv[i-1])%mod;
	}
	vi a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(all(a));
	int add=0,sub=0;
	for(int i=0;i<n;i++){
		if(n-i-1<k-1)
			break;
		sub+=(a[i]*ncr(n-i-1,k-1))%mod;
		sub%=mod;
	}
	reverse(all(a));
	for(int i=0;i<n;i++){
		if(n-i-1<k-1)
			break;
		add+=(a[i]*ncr(n-i-1,k-1))%mod;
		add%=mod;
	}
	// debug()<< imie(add) imie(sub) imie(ncr(4,2)) imie(fact[5]);
	int ans=add-sub;
	while(ans<0)
		ans+=mod;
	ans%=mod;
	cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int n,m;
signed int result;
void solve() {
    cin >> n;
    multimap<string, int> s;
    set<string> word;
    for (int i = 0; i < n; i++) {
        string tmp_s;
        cin >> tmp_s;
        word.insert(tmp_s);
        s.insert(make_pair(tmp_s, 1));
    }
    cin >> m;
    multimap<string, int> t;
    for (int i = 0; i < m; i++) {
        string tmp_s;
        cin >> tmp_s;
        word.insert(tmp_s);
        t.insert(make_pair(tmp_s, 1));
    }
    result = -INF;
    for (auto x : word) {
        int cnt1, cnt2;
        cnt1 = s.count(x);
        cnt2 = t.count(x);
        result = max(result , (cnt1 - cnt2));
    }
    if (result < 0) {
        cout << 0 << endl;
    } else {
        cout << result << endl;
    }
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

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

int main() {

    char c1[10];
    char c2[100];
    char c3[10];
    
    scanf("%s%s%s", c1,c2,c3);

    printf("A%cC",c2[0]);
    
    return 0;

}


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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    int n = 0;
    cin >> n;

    for (int i = 1; i <= 9; i++) {
        if (n % i == 0) {
            if (n / i < 10) {
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';

    // system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <math.h>

using namespace std;

int main() {

	int N,X;
    int sum=0;
    int ans = 10000000;
    cin >> N ;
    vector<int>v(N);
    
    for(int i=0;i<N;i++){
        cin >> v[i] ;
    }
    
     for(int i=0;i<100;i++){
         int sum = 0;
         for(int j=0;j<N;j++){
            sum +=  (v[j]-i)*(v[j]-i);
            //cout << v[j] << " " << sum << endl;
        }
        ans = min (ans,sum);
     }   
      
        cout << ans << endl  ;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};




int main(){
    LL N;cin >> N;
    LL pa,pb,pc,pd;cin >> pa >> pb >> pc >> pd;
    LL ta,tb,tc,td;cin >> ta >> tb >> tc >> td;
    LL ans = 1e18;
    for(int i = 0;i <= N;i++){
        for(int j = 0;j <= N;j++){
            for(int k = 0;k <= N;k++){
                for(int l = 0;l <= N;l++){
                    LL sum = ta * i + tb * j + tc *k + l * td;
                    if(sum >= N){
                        ans = min(ans, pa * i + pb * j + pc * k + pd * l);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}



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

int main(void)
{
  int sum=0;
  int l,r,d;
  scanf("%d %d %d",&l,&r,&d);

  for(int i=l;i<=r;i++)
  {
    if(i%d==0) sum++;
  }
  
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 1724
s = input()

blist = [0 for i in range(len(s))]
for i in range(len(s)):
    if s[i] == "B":
        blist[i] = 1

for i in range(len(s)-1):
    blist[i+1] += blist[i]

count = 0
for i in range(len(s)):
    if s[i] == "W":
        count += blist[i]

print(count)

Measured memory_bytes: 11368
/*
AOJ - ALDS1_1_A
Date: 20190307
Author: Mikoron * ♡mikoiwate_351♡
*/

#define N 101

#include<stdio.h>

void Print_Array(short A[], short num_of_A);

int main(void) {
        short i, j, num_of_A, A[N], key;

        scanf("%hd", &num_of_A);
        for(i = 0; i < num_of_A; i++) {
                scanf("%hd", &A[i]);
        }

        for(i = 1; i < num_of_A; i++) {
                Print_Array(A,num_of_A);
                key = A[i];
                j = i-1;
                while(j >= 0 && A[j] > key) {
                        A[j+1] = A[j];
                        j--;
                }
                A[j+1] = key;
        }
        Print_Array(A,num_of_A);
        return 0;
}

void Print_Array(short A[], short num_of_A) {
        short i;

        for(i = 0; i < num_of_A; i++) {
                if(i > 0) printf(" ");
                printf("%hd", A[i]);
        }
        printf("\n");
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, W;
  cin >> N >> W;
  static int w[100], v[100];
  REP(i,N) cin >> w[i] >> v[i];

  // dp[n][v] ... n番目(1-index)までの品物の中で、合計価値v(1-index)以上とする最小重量
  static int dp[101][100001];
  REP(i,101) REP(j,100001) dp[i][j] = INF;
  dp[0][0] = 0;

  // 貰うdp
  for (int i=1; i<=N; i++) {
    for (int j=0; j<=100000; j++) {
      //i番目を選ばない場合
      chmin(dp[i][j], dp[i-1][j]);

      //i番目を選ぶ場合
      if (j-v[i-1]>=0) chmin(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1]);
    }
  }

  // dp[N][v] <= Wを満たすvの最大値を求める。
  int ans = 0;
  for (int j=0; j<=100000; j++) {
    if (dp[N][j] <= W) chmax(ans, j);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 79232
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,v,w,t,i,j;
    cin >> a  >> v >> b >> w >> t;
    
    if(a > b)
    {
       swap(a,b);
    }
    
    if(a == b)
    {
        cout << "YES";
        return 0;
    }
    
    ll ans1 = a + v * t;
    ll ans2 = b + w * t;
    if(ans1 >= ans2)
        cout << "YES";
    else
        cout << "NO";

}


Measured memory_bytes: 3636
// Dmitry _kun_ Sayutin (2020)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    vector<int> a(n+1);
    input_seq(ALL(a));

    int64_t sum = std::accumulate(ALL(a), int64_t(0));

    int64_t ans = 0;
    int64_t cur = 1;

    for (int i = 0; i <= n; ++i) {
        if (cur < a[i]) {
            cout << "-1\n";
            exit(0);
        }

        cur -= a[i], sum -= a[i];
        ans += a[i] + min(sum, cur);
        
        cur = 2 * cur;
        cur = min(cur, sum);

    }

    cout << ans << "\n";

    return 0;
}


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

int main() {
	long long N;
	cin >> N;
	
	long long A, B;
	for (int i = sqrt(N); i >= 1; i--) {
		if (N%i == 0) {
			A = i * 1LL;
			B = N / i;
			break;
		}
	}

	string a = to_string(A), b = to_string(B);
	cout << max(a.size(), b.size()) << endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int n, m, x;
  cin >> n >> m >> x;
  int count_left = 0;
  int count_right = 0;
  rep(i, m){
    int a;
    cin >> a;
    if(a > x){
      count_left++;
    }else{
      count_right++;
    }
  }
  cout << min(count_left, count_right) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

const int MAX = 1000001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int X,Y;
  cin>>X>>Y;
  ll ans=0;
  ll mod=1000000007;
  if((X+Y)%3==0){
    int A=Y-(X+Y)/3;
    int B=X-(X+Y)/3;
    COMinit();
    ans=COM(A+B,A);
  }
  cout<<ans<<endl;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,a; cin>>n;
	set <int> st;
	for (int i=0; i<n; i++) {
		cin>>a;st.insert(a);
	}
	if (st.size()==n) cout<<"YES";
	else cout<<"NO";
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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


  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];

  ll ans=0;
  REP(i,n){
    if((i%2==0) && (a[i]%2==1))
      ans++;
  }

  cout<<ans<<endl;
}



Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
using namespace std;

int main(){
    int a;
    cin >> a;
    if(a<1200){
        cout << "ABC";
    }else if(a<2800){
        cout << "ARC";
    }else{
        cout << "AGC";
    }
}


Measured memory_bytes: 256
/**
 * 
 */
import java.util.*;
/**
 * @author akira
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
		while(scan.hasNext()){
			xa1 = scan.nextDouble(); ya1 = scan.nextDouble();
			xa2 = scan.nextDouble(); ya2 = scan.nextDouble();
			xb1 = scan.nextDouble(); yb1 = scan.nextDouble();
			xb2 = scan.nextDouble(); yb2 = scan.nextDouble();
			
			if(contain(xa1,ya1,xa2,ya2,xb1,yb2) || contain(xa1,ya1,xa2,ya2,xb2,yb2) || contain(xa1,ya1,xa2,ya2,xb1,yb1) || contain(xa1,ya1,xa2,ya2,xb2,yb1) || contain(xb1,yb1,xb2,yb2,xa1,ya2) || contain(xb1,yb1,xb2,yb2,xa2,ya2) || contain(xb1,yb1,xb2,yb2,xa1,ya1) || contain(xb1,yb1,xb2,yb2,ya2,ya1)){
				System.out.println("YES");	
			}else{
				System.out.println("NO");
			}
			
		}
	}
	static boolean contain(/*left-down*/double ldx,double ldy,/*right-up*/double rux,double ruy,double x,double y){
		if(ldx <= x && x <= rux && ldy <= y && y <= ruy){
			return true;
		}else{
			return false;
		}
	}

}

Measured memory_bytes: 20748
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
a = hi(n)
ans = 1
D = deque()
D.append(a[0])
for i in range(1, n):
    index = bisect_left(D, a[i])
    if 0 == index:
        D.appendleft(a[i])
    else:
        D[index - 1] = a[i]
print(len(D))

Measured memory_bytes: 11280
a, b, c = map(int, input().split())
# 少なくとも一つ、奇数が存在する場合
if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
    print(0)
    exit()
# 全て偶数で、A=B=Cの場合
if a == b and b == c:
    print(-1)
    exit()

cnt = 0

while True:
    cnt += 1
    next_a = b // 2 + c // 2
    next_b = a // 2 + c // 2
    next_c = a // 2 + b // 2
    a = next_a
    b = next_b
    c = next_c
    # 処理を行った結果、奇数が発生してしまったらそこで終了
    # 奇数がなければwhileを続ける
    if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
        break

print(cnt)

Measured memory_bytes: 9220
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c;
    
    if(a>b){
        d = a;
        a = b;
        b = d;
    }
    if(b>c){
        d = b;
        b = c;
        c = d;
    }
    if(a>b){
        d = a;
        a = b;
        b = d;
    }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X,i,g=100000;
  cin>>N>>X;
  int m[N];
  for(i=0;i<N;i++){
    cin>>m[i];
    X-=m[i];
    g=min(g,m[i]);
  }
  cout<<N+(X/g)<<endl;
  return 0;
}


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

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

Measured memory_bytes: 3068
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-2):
    pi, pj, pk = p[i], p[i+1], p[i+2]
    pmax = max(pi, pj, pk)
    pmin = min(pi, pj, pk)
    if pj != pmax and pj != pmin:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#define N 100 

int main(void) {

  int i,tmp,j,A[N],n,cnt=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  
  for(i=0;i<=n-1;i++) {
    for(j=n-1;j>=i+1;j--) {
      if(A[j] < A[j - 1]) {
	tmp = A[j];	
	A[j] = A[j-1];
	A[j-1] = tmp;
	cnt++;
      } 
    }
  }
  for(i=0;i<n;i++) {

    printf("%d",A[i]);
    if(i < n-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  return 0;

}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 200005
ll arr[SIZE];
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll K,N;
	cin>>K>>N;
	for(ll i=0;i<N;++i){
		cin>>arr[i];
	}
	sort(arr,arr+N);
	ll maxd=0;
	for(ll i=0;i<N-1;++i){
		maxd=max(maxd,arr[i+1]-arr[i]);
	}
	maxd=max(maxd,arr[0]+K-arr[N-1]);
	cout<<K-maxd<<endl;
}

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

using namespace std;

namespace FastFourierTransform
{
  using C = complex< double >;

  void DiscreteFourierTransform(vector< C > &F, bool rev)
  {
    const int N = (int) F.size();
    const double PI = (rev ? -1 : 1) * acos(-1);
    for(int i = 0, j = 1; j + 1 < N; j++) {
      for(int k = N >> 1; k > (i ^= k); k >>= 1);
      if(i > j) swap(F[i], F[j]);
    }
    C w, s, t;
    for(int i = 1; i < N; i <<= 1) {
      for(int k = 0; k < i; k++) {
        w = polar(1.0, PI / i * k);
        for(int j = 0; j < N; j += i * 2) {
          s = F[j + k];
          t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
                F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
          F[j + k] = s + t, F[j + k + i] = s - t;
        }
      }
    }
    if(rev) for(int i = 0; i < N; i++) F[i] /= N;
  }

  vector< long long > Multiply(const vector< int > &A, const vector< int > &B)
  {
    int sz = 1;
    while(sz <= A.size() + B.size()) sz <<= 1;
    vector< C > F(sz), G(sz);
    for(int i = 0; i < A.size(); i++) F[i] = A[i];
    for(int i = 0; i < B.size(); i++) G[i] = B[i];
    DiscreteFourierTransform(F, false);
    DiscreteFourierTransform(G, false);
    for(int i = 0; i < sz; i++) F[i] *= G[i];
    DiscreteFourierTransform(F, true);
    vector< long long > X(A.size() + B.size() - 1);
    for(int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
    return (X);
  }
};

int main()
{
  int N, M, Q, A[40001], B[40001], C[100000];

  scanf("%d %d %d", &N, &M, &Q);
  for(int i = 0; i < N; i++) scanf("%d", &A[i + 1]), A[i + 1] += A[i];
  for(int i = 0; i < M; i++) scanf("%d", &B[i + 1]), B[i + 1] += B[i];
  for(int i = 0; i < Q; i++) scanf("%d", &C[i]);

  const int SZ = 200000;
  vector< int > F(SZ + 1), G(SZ + 1);

  {
    vector< int > S(SZ + 1), T(SZ + 1);
    for(int i = 0; i <= N; i++) S[A[i]]++, T[A[i]]++;
    reverse(begin(T), end(T));
    auto R = FastFourierTransform::Multiply(S, T);
    for(int i = 1; i <= SZ; i++) F[i] = R[SZ - i];
  }


  {
    vector< int > S(SZ + 1), T(SZ + 1);
    for(int i = 0; i <= M; i++) S[B[i]]++, T[B[i]]++;
    reverse(begin(T), end(T));
    auto R = FastFourierTransform::Multiply(S, T);
    for(int i = 1; i <= SZ; i++) G[i] = R[SZ - i];
  }

  reverse(begin(G), end(G));
  auto X = FastFourierTransform::Multiply(F, G);
  for(int i = 0; i < Q; i++) {
    if(C[i] == 0) printf("%lld\n", X[200000]);
    else printf("%lld\n", X[200000 - C[i]] + X[200000 + C[i]]);
  }
}

Measured memory_bytes: 26528
import itertools
N=int(input())
A=[]
Z=[]
for _ in range(N):
    a_i=int(input())
    z_i=[]
    A.append(a_i)
    for i in range(a_i):
        a,b=map(int,input().split())
        z_i.append([a-1,b])
    Z.append(z_i)
ans=0
for bit in itertools.product([0,1],repeat=N):
    f=True
    for j in range(N):
        if bit[j]==1:
            for k in range(A[j]):
                if bit[Z[j][k][0]]!=Z[j][k][1]:
                    f=False
                    break
    if f:
        ans=max(ans,bit.count(1))
print(ans)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using v  = vector<ll>;
using vv = vector<v>;
const int MOD = 1000000007;

const ll INF = 1001001001001001001LL;

int main(){
    int n;
    cin >> n;
    v a(n+1);
    rep(i,n+1){
        cin >> a[i];
    }
    
    if(n!=0 && a[0]){
        cout << -1 << endl;
        return 0;
    }
    if(n==0 && a[0]!=1){
        cout << -1 << endl;
        return 0;
    }
    
    
    vector<ll> up_eda(n+1,0);
    vector<ll> dn_eda(n+1,0);
    
    dn_eda[0]=1;
    
    for(int i=1; i<=n; i++){
        dn_eda[i] = min(INF, dn_eda[i-1]*2 - a[i]);
        if(dn_eda[i]<0){
            cout << -1 << endl;
            return 0;
        }
    }
    
    for(int i=n-1; i>=0; i--){
        up_eda[i]=up_eda[i+1]+a[i+1];
    }
    
    ll ans = 0;
    
    for(int i=0; i<=n; i++){
        ans += a[i] + min(up_eda[i], dn_eda[i]);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5636
#include<iostream>
#include<string>
using namespace std;
int main() {
	string n; cin >> n;
	for (int i = 0;i < 3;i++) {
		if (n[i] == '1') n[i] = '9';
		else n[i] = '1';
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
typedef long long LL;
typedef unsigned long long ULL;
const long long LLMIN=(1LL<<63);
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void Sort(ULL *from,ULL *to,ULL bit)
{
  if(!bit||to<from+1)return;
  ULL *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix(LL *array,const int len)
{
  ULL *x=(ULL*)array;
  rep(i,len)x[i]^=LLMIN;
  Sort(x,x+len,LLMIN);
  rep(i,len)x[i]^=LLMIN;
}
int main(void)
{
  LL N=IN(),K=IN(),P[1000]={0},i=0,sum=0;
  while(i<N){P[i++]=IN();}
  Radix(P,N);i=0;
  while(i<K){sum+=P[i++];}
  return printf("%d\n",sum),0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const ll INF = 1e15;
int main(){

  int n,k;
  cin >> n >> k;
  ll dp[n+1000];
  dp[0] = 0;

  FOR(i,1,n+1000) dp[i] = INF;
  ll h[n+1000];
  rep(i,n) cin >> h[i];

  rep(i,n){
    rep(j,k){
      int nextIdx = i+j+1;
      dp[nextIdx] = min<ll>(dp[i] + abs(h[nextIdx]-h[i]),dp[nextIdx]);
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1920
n = int(input())

p = list(map(int,input().split()))

ans = 0
for i in range(1,n-1):
    if p[i-1] < p[i] and p[i] < p[i+1] :
        ans += 1
    elif p[i+1] < p[i] and p[i] < p[i-1] :
        ans += 1
print(ans)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    long long n, x;
    cin >> n;
    vector<long long> as(n);
    vector<long long> acc;
    vector<long long> arr;
    REP(i, n) { cin >> as[i]; }
    long long ans = 0;
    acc.push_back(0);
    for (int i = 0; i < n; i++) {
        ans = __gcd(ans, as[i]);
        acc.push_back(ans);
    }
    ans = 0;
    arr.push_back(ans);
    for (int i = n - 1; i >= 0; i--) {
        ans = __gcd(ans, as[i]);
        arr.push_back(ans);
    }
    long long maxx = 1;
    REP(i, n) {
        if (__gcd(acc[i], arr[n - 1 - i]) > maxx) {
            maxx = __gcd(acc[i], arr[n - 1 - i]);
        }
    }
    cout << maxx << endl;
}

Measured memory_bytes: 3316
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

char st[200010];

int has[30];

ll ans;

int main(){
	scanf("%s",st+1);
	n=strlen(st+1);
	ans=1LL*n*(n+1)/2;
	REP(i,1,n)has[st[i]-'a']++;
	REP(i,0,26)ans-=1LL*has[i]*(has[i]+1)/2;
	cout<<ans+1<<endl;
	return 0;
}


Measured memory_bytes: 384
#!python3.8
# -*- coding: utf-8 -*-
# abc168/abc168_c
import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    a, b, H, M = i2nn()
    A_rad = (H + M / 60) / 12
    B_rad = M / 60
    C = (A_rad - B_rad) * math.pi * 2
    c = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(C))
    print(c)
    return

main()


Measured memory_bytes: 9612
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }

const int MAX = 2100000;
ll mod = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

ll rui(ll a,ll b){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
     return ans;
}

int main() {   
    COMinit();
    ll n, m, k; cin >> n >> m >> k;
    ll ans = 0;
    for(int i=0; i<=k; i++){
        ll res = 1;
        res = res * m % mod;
        ll ruijo = rui(m-1, n-1-i); 
        res = res * ruijo % mod;
        ll tmp = COM(n-1, i); 
        res = res * tmp % mod;
        ans = (ans + res) % mod;
    }
    cout << ans << ln;
}

Measured memory_bytes: 52852
N = list(map(int, list(input())))
for i in range(1,len(N)):
    if N[i] != 9:
        ans = (N[0] - 1) + 9 * (len(N) - 1)
        print(ans)
        exit()
ans = N[0] + 9 * (len(N) - 1)
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N; int K; cin >> K;
    vi data(N); F0R(i, N) cin >> data[i];

    int best = 0;
    int cur = 0;
    F0R(i, N) {
        cur += data[i];
        if (i >= K) {
            cur -= data[i-K];
        }
        best = max(best, cur);
    }
    best += K;
    bool odd = best % 2;
    best /= 2;
    cout << best;
    if (odd) cout << ".5";
    cout << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define DEBUG 0
#define REP(i, n) for (int i = 0; i < (n); i++) 
typedef long long ll;
typedef pair<int,int> pint;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main() { 
    ll N;
    cin >> N;
    ll sum_a = 0;
    vector <ll> a(N);
    REP(i,N)
    {
        cin >> a[i];
        sum_a += a[i];
    }

    ll tmp = 0;

    ll res = INF;

    REP(i,N)
    {
        if(tmp + a[i] > sum_a / 2)
        {
            res = min(res, abs((sum_a - tmp) - tmp));
            res = min(res, abs((sum_a - tmp -a[i]) - tmp - a[i]));
        }
        tmp += a[i];
    }


    cout << res << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
long long INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
    int h,w,d,q;
    scanf("%d %d %d",&h,&w,&d);
    map<int,pair<int,int>> mp;
    REP(i,h){
        REP(j,w){
            int a;
            scanf("%d",&a); --a;
            mp[a] = make_pair(i+1,j+1);
        }
    }

    scanf("%d",&q);
    vector<ll> vl[d];
    REP(i,d){
        ll abc=0;
        int a,b;
        a = mp[i].first;
        b = mp[i].second;
        vl[i].push_back(abc);
        for(int j=i+d;j<h*w;){
            //printf("i:%d j:%d x:%d y:%d ",i,j,mp[j].first,mp[j].second);
            abc += abs(mp[j].first-a) + abs(mp[j].second-b);
            //printf("%lld\n",abc);
            vl[i].push_back(abc);
            a = mp[j].first;
            b = mp[j].second;
            j += d;
        }
    }
    //printf("!\n");
    vector<ll> answer(q);
    REP(i,q){
        int l,r,a,b;
        ll ans = 0;
        scanf("%d %d",&l,&r);
        --l;--r;
        ans = vl[l%d][r/d] - vl[l%d][l/d];
        answer[i] = ans;
        //printf("%d %d %d\n",l%d,l,r);
        //printf("%lld %lld\n",vl[l%d][r/d],vl[l%d][l/d]);
    }
    REP(i,q){
        printf("%lld\n",answer[i]);
    }
    return 0;
}


Measured memory_bytes: 11776
n, k = map(int,input().split())
lis = []
for i in range(n):
	h = int(input())
	lis.append(h)
lis.sort()
diff = []
for j in range(n-k+1):
	diff.append(lis[j+k-1] - lis[j])
print(min(diff))

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

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

    sort(a, a + 3);

    int r = 1;
    for (int i = 1; i < 3; i++) {
        if (a[i - 1] != a[i]) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, H = map(int, input().split())

q = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(q,(-a, True))
    heapq.heappush(q,(-b, False))

ans = 0
while H > 0:
    x = heapq.heappop(q)
    if not x[1]:
        H -= abs(x[0])
        ans += 1
    else:
        ans += (H + abs(x[0]) - 1) // abs(x[0])
        break
print(ans)
    

Measured memory_bytes: 29804