akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

int main(){
    ll n; cin >> n;
    vector<vector<ll>> a(2,vector<ll>(n));
    rep(i,2)rep(j,n)cin >> a[i][j];
    ll ans = 0;
    vector<vector<ll>> sum(2,vector<ll>(n+1,0));
    rep(i,2)rep(j,n)sum[i][j+1] = sum[i][j] + a[i][j];
    rep(i,n){
        ll temp = sum[0][i+1] - sum[0][0];
        temp += sum[1][n] - sum[1][i];
        chmax(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
#define vi vector<int>
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve(){
    int a;cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

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

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

  vector<int> H(N);
  rep( i, 0, N ) cin >> H.at(i);

  int Ans = 1;
  int temp = H.front();
  rep( i, 1, N ) {
    if ( temp <= H.at(i) ) {
      Ans++;
      temp = H.at(i);
    }
  }

  cout << Ans << endl;
}


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

int main() {
  int s;
  cin >> s;
  int s1, s2, s3;
  s1 = s / 100;
  s2 = s % 100 / 10;
  s3 = s % 100 % 10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 3584
n, l = map(int,input().split())
list = []
ans = []

for i in range(n):
  list.append(l+i)
tmp = 9999
for i in range(n):
  ans.append(sum(list)-list[i])
for i in range(n):
  if abs(sum(list) - ans[i]) < tmp:
    tmp = abs(sum(list) - ans[i])
    answer = ans[i]
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
using ll = long long;

int main(){
  ll n, x; cin >> n >> x;
  ll a[n+1], b[n+1];
  for(int i=1; i<=n; i++){
    cin >> a[i];
    b[i] = a[i];
  };

  ll ans = LLONG_MAX;
  for(int k=0; k<n; k++){
    ll tmp = 0;
    for(int i=1; i<=n; i++){
      int be = (i-k <= 0)? i-k+n: i-k;
      b[i] = min(b[i], a[be]);
      tmp += b[i];
    }
    ans = min(ans, tmp + k*x);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;
    if(S==U) cout << A-1 << " " << B << endl;
    else cout << A << " " << B-1 << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<queue>
#include<vector>

const long long MAX = 1ll << 57;

int main(){
  int N;
  std::cin >> N;
  
  std::vector<std::vector<long long>> A(N, std::vector<long long>(N));
  std::vector<std::vector<long long>> graph(N, std::vector<long long>(N, 0));
  std::vector<std::vector<long long>> distance(N, std::vector<long long>(N, MAX));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      std::cin >> A[i][j];
      graph[i][j] = A[i][j];
      distance[i][j] = A[i][j];
    }
  }
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(distance[i][k] + distance[k][j] <= distance[i][j]){
          distance[i][j] = distance[i][k] + distance[k][j];
          if(i != k && j != k) graph[i][j] = 0;
        }
      }
    }
  }
  
  long long sum_length = 0;
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      if(distance[i][j] != A[i][j]) sum_length = -1;
      if(sum_length == -1) break;
      else sum_length += graph[i][j];
    }
  }
  
  std::cout << sum_length << std::endl;
  
  return 0;
}

/*class UnionFindTree{
private:
  std::vector<int> parent;
  
public:
  UnionFindTree(int n) : parent(n){
    for(int i = 0; i < n; i++) parent[i] = i;
  }
  
  int find(int x){
    if(parent[x] == x) return x;
    else return parent[x] = find(parent[x]);
  }

  void unite(int x, int y){
    parent[find(x)] = find(y);
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }
};

struct Edge{
  int v1;
  int v2;
  int length;
};

bool operator>(const Edge& e1, const Edge& e2){
  return e1.length > e2.length;
}

int main(){
  int N;
  std::cin >> N;
  
  std::vector<std::vector<int>> A(N, std::vector<int>(N));
  std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge>> pq;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      std::cin >> A[i][j];
      if(i >= j) continue;
      
      pq.push({i, j, A[i][j]});
    }
  }
  
  UnionFindTree tree(N);
  std::vector<std::vector<long long>> distance(N, std::vector<long long>(N, MAX));
  for(int i = 0; i < N; i++) distance[i][i] = 0;
  long long sum_length = 0;
  
  while(!pq.empty()){
    Edge e = pq.top();
    pq.pop();
    
    if(!tree.same(e.v1, e.v2)){
      tree.unite(e.v1, e.v2);
      distance[e.v1][e.v2] = distance[e.v2][e.v1] = e.length;
      sum_length += e.length;
    }
  }
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        distance[i][j] = distance[j][i] = std::min(distance[i][k] + distance[k][j], distance[i][j]);
      }
    }
  }
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(A[i][j] != distance[i][j]) sum_length = -1;
    }
  }
  
  std::cout << sum_length << std::endl;
  
  return 0;
}*/

Measured memory_bytes: 2432
using System;

namespace ABC123_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var dishes = new int[5];
            dishes[0] = int.Parse(Console.ReadLine());
            dishes[1] = int.Parse(Console.ReadLine());
            dishes[2] = int.Parse(Console.ReadLine());
            dishes[3] = int.Parse(Console.ReadLine());
            dishes[4] = int.Parse(Console.ReadLine());

            var min = 10;
            var sum = 0;
            foreach (var d in dishes)
            {
                sum += d % 10 == 0 ? d : (d - d % 10 + 10);
                if (d % 10 != 0) min = Math.Min(d % 10, min);
            }

            Console.WriteLine(sum - 10 + min);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int v[10];
int w[30][10];
int x[30][10];
int main()
{
  int n,m,a,d,i,j;
  while(cin >> n, n){
    memset(v,0,sizeof(v));
    memset(w,0,sizeof(w));
    memset(x,0,sizeof(x));
    cin >> m >> a >> d;
    for(i=1;i<=n;i++){
      v[i] = i;
    }
    string s;
    for(i=0;i<d;i++){
      cin >> s;
      for(j=0; j<s.length(); j++){
	x[i][j+1] = s[j] - '0';
	if(s[j] == '1') swap(v[j+1],v[j+2]);
      }
      for(j=1;j<=n;j++){
	w[i][j] = v[j];
      }
    }
    if(w[d-1][a] == m) {
      cout << "0" << endl;
      continue;
    }
    for(i=0;i<d;i++){
      for(j=1;j<n;j++){
	if(x[i][j-1] + x[i][j] + x[i][j+1] == 0 &&
	   (w[i][j] == w[d-1][a] && w[i][j+1] == m ||
	    w[i][j] == m && w[i][j+1] == w[d-1][a])) break;
      }
      if(j != n) break;
    }
    if(i != d) cout << (i+1) << " " << j << endl;
    else cout << "1" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

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

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}


int main(){
  // ????????§???????§£???????????????????????\???????§£????????????. 
  //   http://mofupp.info/pukiwiki/?plugin=attach&pcmd=open&file=2011-4A_pes.cpp&refer=ICPC%2FSummerCamp%2F2011_4A
  int H, W;
  while (cin >> H >> W){
    vector<string> B(H);
    REP(i, H) cin >> B[H - 1 - i];

    vector<pair<double, int> > events;

    REP(i, H + 1) REP(j, W + 1) if (i){
      int count = 0;
      REP(k, 4){
        int ni = i - k % 2;
        int nj = j - k / 2;
        if (0 <= ni && ni < H && 0 <= nj && nj < W && B[ni][nj] == '#'){
          count++;
        }
      }

      if (count % 2 == 0) continue;


      if (0 <= i - 1 && j < W && B[i - 1][j] == (count == 1 ? '#' : '.')){
        events.emplace_back((double)j / i, 1);
      }

      if (i < H && 0 <= j - 1 && B[i][j - 1] == (count == 1 ? '#' : '.')){
        events.emplace_back((double)j / i, -1);
      }
    }
    
    sort(ALL(events));
    

    int res = 1;
    int cur = 1;
    for (size_t i = 0; i < events.size();){
      double p = events[i].first;
      while (i < events.size() && abs(events[i].first - p) < 1e-6){
        cur += events[i++].second;
      }
      res = max(res, cur);
    }
    cout << res << endl;
  }

  
  return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,k,ba;
    cin>>a>>b>>c>>k;
    ba=min(a,k);
    k=k-a;
    if(k>0)
    {
    	k=k-b;
    	//cout<<k<<" "<<ba;
	}
	if(k>0)
	{
		ba=ba+max(k*-1,c*-1);
		//cout<<ba<<" ";
	}
	cout<<ba;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
int co=0,co1=0,Rectangle=0,Rhombus=0;
double side[3];
char str[300];
while(cin>>str){
for(int i=0;i<3;i++)side[i]=0;
for(int i=0;i<=strlen(str);i++){
if(str[i]==','||str[i]=='\0'){
for(int j=co;j<i;j++)side[co1]+=(str[j]-'0')*pow(10,i-j-1);
co=i+1;
co1++;
}
}co=0;co1=0;
if(side[0]==side[1])Rhombus++;
else if(side[0]*side[0]+side[1]*side[1]==side[2]*side[2])Rectangle++;
}
cout<<Rectangle<<endl<<Rhombus<<endl;
}

Measured memory_bytes: 1160
#include<algorithm>
#include<vector>

#include<iostream>
using namespace std;

vector<int> prime;
void prime_set(int n){
  n+=100;
  prime.resize(n);
  for(int i=0;i<n;i++){
    prime[i]=1;
  }
  prime[0]=prime[1]=0;
  for(int i=0;i*i<n;i++){
    if(prime[i]){
      for(int j=i*2;j<n;j+=i){
        prime[j]=0;
      }
    }
  }
}

int solve(int a,int b,int n){
  int c = 0;
  while(c!=n){
    c+=prime[a];
    a+=b;
  }
  return a-b;
}
int main(){
  prime_set(10000000);
  int a,b,n;
  while(cin>>a>>b>>n,a!=0&&b!=0&&n!=0){
    cout<<solve(a,b,n)<<endl;
  }
}

Measured memory_bytes: 40164
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
const int  MOD=1e9+7;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

int printintN(int array[],const int num){
    for(int i=0;i<num;i++){printf("%d ",array[i]);}
    br;
    return 0;
}
//#define int long long int

/*
 1.困った時こそ冷静に問題文を見直す！制約条件を見ろ！乱択アルゴリズムとかO(N^3)とか！
 2.一度に大量のことをやろうとしない。デバッグしやすいように細かく！
 3.プログラミングは半分数学だし、もう半分は数学ではない！
 4.できない問題はできない！！！！！
 */

int gcd(int a,int b){//最大公約数
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}


int experiment(){
    int ans;ans=0;
    int N;
    cin>>N;
    int A[N];
    inarray(A, 0, N);
    
    int frontGCD[N],backGCD[N];
    frontGCD[0]=A[0];
    FOR(i, 1, N){
        frontGCD[i]=gcd(frontGCD[i-1],A[i]);
    }
    
    backGCD[N-1]=A[N-1];
    FORREV(i, N-1, 0){
        backGCD[i]=gcd(backGCD[i+1],A[i]);
    }
    
    int exceptGCD[N];
    FOR(i, 0, N){
             if(i==0)  exceptGCD[i]=backGCD [i+1];
        else if(i==N-1)exceptGCD[i]=frontGCD[i-1];
        else           exceptGCD[i]=gcd(frontGCD[i-1],backGCD[i+1]);
    }
    
    sort(exceptGCD, exceptGCD+N);
    
    
    
    OutputAndReturn0(exceptGCD[N-1]);
    return 0;
}
signed main(){
    assert(1);
    experiment();
    return 0;
}


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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef map<ll, vector<ll>> mll;
typedef unordered_map<ll, vector<ll>> ull;

#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()
#define rep(i, a, b) for(ll i = a; i < b ; i++)
#define repr(i, a, b) for(ll i = a; i >= b ; --i)
#define distinct(v) v.erase(unique(v.begin(), v.end()), v.end());
#define delt(v, x) (v).erase(std::remove((v).begin(), (v).end(), x), (v).end())
#define MAX 200010
#define INF 1000000007
const ll MAXN = 1e5 + 5;

void dfs(int u, int par, vector<bool> &v, unordered_map<int, vector<int>> g) {
    if (!v[u]) {
        v[u] = true;
        for (auto i:g[u]) {
            if (!v[i] && i != par)dfs(i, u, v, g);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(all(a));
    int sum = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = i + 1; j < n && a[j] < 2 * a[i]; ++j) {
            auto it = upper_bound(a.begin(), a.begin() + i + 1, a[j] - a[i]);
            sum += i - (it - a.begin());
            //cout << a[i] << " " << a[j] << " " << sum << " " << *it << endl;
        }
    }
    cout << sum << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define inf  1000001
#define ind  -1000001
typedef int long long ll;


int main(){
    vector<ll> v;
    int n;
    cin>>n;
    ll mx=ind;
    ll mxp=0;
    ll mip=0;
    ll mi=inf;
    
    rep(i,n){
        ll x;
        cin>>x;
        if(x<mi){mi=x;mip=i;}
        if(x>mx){mx=x;mxp=i;}
        v.push_back(x);
    }
    if(mip==mxp){
        cout<<0<<endl;
        return 0;
    }
    cout<<2*n-1<<endl;
    int flag=0;
    
    if(abs(mi)<abs(mx)){
        for(int i=0;i<v.size();i++){
            cout<<mxp+1<<" "<<i+1<<endl;
            v[i]+=mx;
            flag=1;
        }
    }else{
        for(int i=0;i<v.size();i++){
            cout<<mip+1<<" "<<i+1<<endl;
            v[i]+=mi;
            flag=2;
        }
    }
    
    if(flag==1){
        for(int i=1;i<n;i++){
            v[i]+=v[i-1];
            cout<<i<<" "<<i+1<<endl;
        }
        
    }else{
        
        for(int i=n-1;i>0;i--){
            v[i-1]+=v[i];
            cout<<i+1<<" "<<i<<endl;
        }
    }
    
    
    
   
    
    
    
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long llong;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int w, h, x, y;
   cin >> w >> h >> x >> y;
   double s = (double)w * h / 2.0;
   if (x == w / 2.0 && y == h / 2.0) {
      printf("%0.10f 1\n", s);
   } else {
      printf("%0.10f 0\n", s);
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int a,b;
    cin >> a >> b;
    
    if ((a + b) % 2 == 0){
        cout << (a + b) / 2 << endl;
    }
    
    else cout << (a + b) / 2 + 1 << endl;
    
}


Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,n = inm()
a = inl()
if sum(a)>=h:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 53444
#include <iostream>
using namespace std;
typedef long long LL;

int main() {
	LL x; cin >> x;
	LL n = x % 11, m;
	if (n == 0)m = 0;
	else if (n <= 6)m = 1;
	else m = 2;
	cout << x / 11 * 2 + m << endl;
}

Measured memory_bytes: 256
R1 = [("R1","R2","R3"),("R2","R3","R4"),("R3","R4","R5"),("R4","R5","R6"),("R5","R6","R7"),("R6","R7","R8"),("R7","R8","R9")]
R2 = ["R1","R2","R3","R4","R5","R6","R7","R8","R9"]

G1 = [("G1","G2","G3"),("G2","G3","G4"),("G3","G4","G5"),("G4","G5","G6"),("G5","G6","G7"),("G6","G7","G8"),("G7","G8","G9")]
G2 = ["G1","G2","G3","G4","G5","G6","G7","G8","G9"]

B1 = [("B1","B2","B3"),("B2","B3","B4"),("B3","B4","B5"),("B4","B5","B6"),("B5","B6","B7"),("B6","B7","B8"),("B7","B8","B9")]
B2 = ["B1","B2","B3","B4","B5","B6","B7","B8","B9"]

def Rummy(C:list,N:list):

	#RGBの数が3の倍数で無い場合、負け
	if C.count("R") % 3 != 0 or C.count("G") % 3 != 0 or C.count("B") % 3 != 0:
		print("0")
		return

	ans = []
	for x,y in zip(C,N):
		tmp = x + str(y)
		ans.append(tmp)

	REN = R1+G1+B1
	DOU = R2+G2+B2

	#同番検索
	for z in DOU:
		if ans.count(z) >= 3:
			ans.remove(z)
			ans.remove(z)
			ans.remove(z)

	#連番検索
	for j in REN:
		while True:
			if all(x in ans for x in j):
				for k in j:
					ans.remove(k)
			else:
				break

	if len(ans) == 0:
		print("1")
	else:
		print("0")

if __name__ == '__main__':

	n = int(input())

	for _ in range(n):
		N = list(map(int,input().split()))
		C = input().split()

		Rummy(C,N)




Measured memory_bytes: 5772
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);
 
int main()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll sum = 0;
	if(k!=0){
		if(k>=a){
			sum += a;
			k -= a;
		}else{
			sum += k;
			k = 0;
		}
	}
	if(k!=0){
		if(k>=b){
			k -= b;
		}else{
			k = 0;
		}
	}
	if(k!=0){
		if(k>=c){
			sum -= c;
			k -= c;
		}else{
			sum -= k;
			k = 0;
		}
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

int main() {
	ll N;
	cin >> N;
	vll a(N + 1);
	repn(i, N)cin >> a[i];

	ll ans = 0;
	rep(j, 40) {
		vll c(N + 1);
		repn(i, N) {
			if (a[i] <= (1ull << j)) { c[i] = 0; }
			else if (a[i] < (1ull << (j+1))) { c[i] = 1; }
			else { c[i] = 2; }
		}

		ll now = 0;
		ll op = 0;
		repn(i, N) {
			if (op == 0) {
				if (c[i] > 0) { op = 1; now++; }
			}
			else {
				if (c[i] < 2) { op = 0; }
			}
		}

		ans += now;
	}
	cout << ans << endl;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  vector<int> v(3); cin >> v;
  if (v[0] == v[1] && v[1] == v[2]) {
    cout << (v[0] % 2 ? 0 : -1) << "\n";
    exit(0);
  }
  int counter = 0;
  while (1) {
    if (v[0] % 2 || v[1] % 2 || v[2] % 2) break;
    v = {(v[1] + v[2]) / 2, (v[2] + v[0]) / 2, (v[0] + v[1]) / 2};
    counter++;
  }
  cout << counter << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int n;
    cin >> n;
    VEC(int) A(n);
    READVEC(A);
    sort(ALL(A));
    cout << A.back() - A[0] << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
N=raw_input()

l=len(N)

s="375"

ans=0
def func(t):
	global ans
	#print "func( ", t, " )", len(t)
	if len(t)>len(N):
		return
	else:
		for si in s:
			if si not in t:
				break
		else:
			if int(t)<=int(N):
				ans+=1
	func(t+"3")
	func(t+"5")
	func(t+"7")

	return ans

print func("") 


Measured memory_bytes: 33768
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
int ok[100] = {};
int main() {
	int n;
	cin >> n;
	vector<int> a, b;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	REP(i, n) {
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
	}
	for (int i = 51; i >= 1; --i) {
		int doe = 0;
		for (int q = 0; q < a.size(); ++q) {
			int can_visit[52] = {};
			can_visit[a[q]] = 1;
			for (int j = 51; j >= 1; --j) {
				if (j < i || ok[j] == 1) {
					REP(t, 52) {
						if (can_visit[t] == 1) {
							can_visit[t % j] = 1;
						}
					}
				}
			}
			if (can_visit[b[q]] == 0) doe = 1;
		}
		if (doe == 1 && i == 51) {
			cout << -1 << endl;
			return 0;
		}
		ok[i] = doe;
	}
	long long ans = 0;
	long long geko = 2;
	for (int i = 1; i <= 50; ++i) {
		ans += (long long)ok[i] * geko;
		geko *= 2LL;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	unsigned long int a, b;
	
	cin >> a >> b;
	
	int count = 1;
	
	while (1){
		if (a*2 <= b){
			count++;
			a *= 2;
		}
		else {
			cout << count << "\n";
			break;
		}
	}
	
	return (0);
}


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

ll N;
int K;
ll divnum = 1000000007;

int main() {
  cin >> N >> K;
  ll count=0;
  ll *num;

  ll now=1, next;
  vector<int> lens;
  while (now<=N) {
    next = N/(N/now);
    lens.push_back(next-now+1);
    now = next+1;
  }
  ll len_size = lens.size();
  num = new ll[2*len_size];

  ll offset, preoffset=0;
  ll tmp;
  for(int s=0; s<len_size; s++) {
    num[s] = 1;
  }
  for(int k=1; k<K; k++) {
    offset = (k % 2) * len_size;
    tmp = 0;
    for(int s=0; s<len_size; s++) {
      tmp = (tmp + num[preoffset+s]*lens[s]) % divnum;
      num[offset+len_size-1-s] = tmp;
    }
    preoffset = offset;
  }
  
  ll res=0;
  offset = ((K-1) % 2) * len_size;
  for (int s=0; s<len_size; s++) {
    res = (res + num[offset+s]*lens[s]) % divnum;
  }
  cout << res << endl;
}


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

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

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

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

class BinaryIndexTree
{
public:
    BinaryIndexTree(int n)
        : mN(n)
    {
        node.resize(n + 1);
        REP(i, n + 1)
        {
            node[i] = 0;
        }
    }
    ~BinaryIndexTree()
    {
        node.resize(0);
    }

    //! 1-index get
    ll sum(int index)
    {
        ll sum = 0;
        for (int i = index; i > 0; i -= i & (-i))
            sum += node[i];
        return sum;
    }

    //! 1-index add
    void add(int index, ll value)
    {
        for (int i = index; i <= mN; i += i & (-i))
            node[i] += value;
    }

private:
    vector<ll> node;
    ll mN;
};

bool U[200005];
queue<ll> P[30];
ll Q[30];

int main()
{
    string S;
    cin >> S;
    ll N = S.length();
    memset(Q, 0, sizeof(Q));
    REP(i, N)
    {
        Q[S[i] - 'a']++;
    }
    ll odd = 0;
    int oddChar = -1;
    REP(i, 30)
    {
        if (Q[i] % 2 == 1)
        {
            odd++;
            oddChar = i;
        }
        Q[i] /= 2;
    }
    if (odd > N % 2)
    {
        cout << -1 << endl;
        return 0;
    }
    memset(U, 0, sizeof(U));
    string A = "", B = "";
    ll ans = 0;
    REP(i, N)
    {
        if (Q[S[i] - 'a'] > 0)
        {
            A.push_back(S[i]);
            Q[S[i] - 'a']--;
            ans += B.length();
        }
        else
        {
            B.push_back(S[i]);
        }
    }
    if (oddChar >= 0)
        A.push_back('a' + oddChar);
    REP(i, A.length())
    {
        P[A[i] - 'a'].push(i + 1);
    }
    BinaryIndexTree bit(N);
    REP(i, B.length())
    {
        ll t = P[B[B.length() - 1 - i] - 'a'].front();
        P[B[B.length() - 1 - i] - 'a'].pop();
        ans += i - bit.sum(t);
        bit.add(t, 1);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(vr) vr.begin(),vr.end()

typedef long long ll;
namespace myrand
{
    mt19937 mt(chrono::system_clock::now().time_since_epoch() / chrono::microseconds(1));
    ll Int(ll l,ll r) { return uniform_int_distribution<ll> (l,r)(mt); }
}
using namespace myrand;
auto ss=chrono::system_clock::now();
double remain_time()
{
    auto en=chrono::system_clock::now();
    return (chrono::duration_cast<chrono::nanoseconds>(en-ss).count()*1e-9);
}
int x;
bool check[300005];
vector<int> pr;
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   for(int i=2;i<=300005;i++) check[i]=true;
   cin >> x;
   for(int i=2;i<=300005;i++)
    if (check[i]==true){
            for(int j=i*2;j<=300005;j+=i) check[j]=false;
            pr.push_back(i);
    }
   cout << pr[(lower_bound(pr.begin(),pr.end(),x)-pr.begin())];


   return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;

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

string S;
ll N, cur, ans;

/*
int main()
{
    ios::sync_with_stdio(false);
    cin >> S;
    N = S.length();
    if (N==1) {
        cout << stoi(S) << endl;
        return 0;
    }
    else{
        REP(i, 0, pow(2, N-1)){
            cur = (int)(S[0] - '0');
            bitset<9> bs(i);
            string simb = bs.to_string().substr(9-N+1, 9);
            REP(j, 0, N-1){
                int n = (int)(S[j+1] - '0');
                if (simb[j] == '0') cur = cur*10 + n;
                else{
                    ans += cur;
                    cur = n;
                }
            }
            ans += cur;
        }
        CO(ans);
        return 0;
    }
}
*/

// dfs https://atcoder.jp/contests/arc061/submissions/9775372
void dfs(ll i, ll x, ll y){
    if (i == S.size()) ans += x + y;
    else{
        dfs(i+1, x, y*10+S[i]-'0');
        dfs(i+1, x+y, S[i]-'0');
    }
}

int main(){
    cin >> S;
    dfs(1, 0, S[0]-'0');
    CO(ans);
}

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

int main()
{
	int A, B, K;
	cin >> A >> B >> K;
	int count = K;
	int now = 1;
	for (int i = 100; i >= 1 && count; i--) {
		if (!(A % i) && !(B % i)) {
			count--;
			now = i;
		}
	}

	cout << now;

	return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

struct node{
	int u, v, w;
	node(int tu, int tv, int tw){
		u = tu, v = tv, w = tw;
	}
};

vector<node> ans;

int32_t main()
{
	int l; scanf("%d", &l);
	for(int i = 19; i >= 2; i--){
		ans.pb(node(i, i + 1, 0));
		ans.pb(node(i, i + 1, (1 << (20 - i - 1))));
	}
	while(l){
		int p = log2(lowbit(l));
		if(p == 19){
			ans.pb(node(1, 2, 0));
			ans.pb(node(1, 2, 1 << 18));
		}
		else ans.pb(node(1, 20 - p, l ^ lowbit(l)));
		l ^= lowbit(l);
	}
	printf("%d %d\n", 20, ans.size());
	for(auto i : ans){
		printf("%d %d %d\n", i.u, i.v, i.w);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;


int main(void){
  double a,b,x,ans;
  
  cin >> a >> b >> x;
  
  x/=a;
  
  if (x<=a*b/2){
    ans=atan(b*b/(x*2))/M_PI*180;
  }else{
    ans=atan(2*(a*b-x)/(a*a))/M_PI*180;
  }
  
  printf("%.12lf\n",ans);
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int x = n % 1000;
  if (x == 0) {
    cout << "0" << endl;    
  } else {
    cout << 1000 - x << endl;    
  }

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int ans = inf;
    rep(_a, 1, N) {
        int a = _a;
        int b = N - a;

        int sm = 0;
        while (a) sm += a % 10, a /= 10;
        while (b) sm += b % 10, b /= 10;
        chmin(ans, sm);
    }
    cout << ans << endl;
}


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

int main(void)
{
    set<int>s;
    int a,b,c;
    cin>>a>>b>>c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <functional>
#include <cmath>

using namespace std;
#define PI       3.14159265358979323846
#define MOD 1000000007

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int calc(LL n) {
	int ret = 0;
	while (n) {
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

int main() {
	LL n;
	cin >> n;
	int tmp = 0;
	int ret = 0;
	while (n>=0) {
		ret = max(ret, calc(n) + tmp * 9);
		if (n % 10 == 9) {
			n /= 10;
			tmp++;
		}
		else {
			n = n / 10 - 1;
			tmp++;
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    int i;

    enum {B, C} classify;

    int ball[10];

    bool isYES = true;

    int datasets;
    scanf("%d", &datasets);

    while (datasets--) {
        int b_list[10] = {0},c_list[10] = {0};
        int b_cnt = -1, c_cnt = -1;
        for (i = 0; i < 10; i++) {
            b_list[i] = c_list[i] = 0;
        }

        for (i = 0; i < 10; i++) {
            scanf("%d", ball + i);
        }

        b_list[++b_cnt] = ball[0];
        classify = B;

        for (i = 1; i < 10; i++) {
            if (classify == B) {
                if (ball[i] > b_list[b_cnt]) {
                    if (ball[i] > c_list[c_cnt]) {
                        if (b_list[b_cnt] > c_list[c_cnt]) {
                            b_list[++b_cnt] = ball[i];
                        } else {
                            c_list[++c_cnt] = ball[i];
                            classify = C;
                        }
                    } else {
                        b_list[++b_cnt] = ball[i];
                    }
                } else if (ball[i] > c_list[c_cnt]) {
                    c_list[++c_cnt] = ball[i];
                    classify = C;
                } else {
                    isYES = false;
                    break;
                }
            } else {
                if (ball[i] > b_list[b_cnt]) {
                    if (ball[i] > c_list[c_cnt]) {
                        if (b_list[b_cnt] > c_list[c_cnt]) {
                            b_list[++b_cnt] = ball[i];
                        } else {
                            c_list[++c_cnt] = ball[i];
                            classify = C;
                        }
                    } else {
                        b_list[++b_cnt] = ball[i];
                    }
                } else if (ball[i] > c_list[c_cnt]) {
                    c_list[++c_cnt] = ball[i];
                    classify = C;
                } else {
                    isYES = false;
                    break;
                }
            }
        }

        if (isYES == true) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[][] map = new int[10][10];

		long count = 0;

		// 先頭と末尾の数値のmap
		for (int i = 1; i <= n; i++) {
			int len = String.valueOf(i).length();
			int d = (int) Math.pow(10, len - 1);
			int head = i / d;
			int tail = i % 10;
			map[head][tail]++;
		}

		for (int i = 1; i <= n; i++) {
			int len = String.valueOf(i).length();
			int d = (int) Math.pow(10, len - 1);
			int head = i / d;
			int tail = i % 10;
			count = count + map[tail][head];
		}

		print(count);
		sc.close();
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 39516
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <math.h>
#include <map>

using namespace std;

vector<string> split(string source, string pattern) {
    unsigned i, base = 0;
    vector<string> ret;
    string buff;

    for(i = 0; i < source.size(); i++) {
        if(source.substr(i, pattern.size()) == pattern) {
            ret.push_back(buff);
            i += pattern.size() - 1;
            buff.clear();
        } else {
            buff += source[i];
        }
    }
    ret.push_back(buff);
    return ret;
}

int main(void) {
    string w, big_occ, big_size;
    int ml = 0, occ = 0;
    map<string, int> m;

    getline(cin, w);

    vector<string> sp = split(w, " ");

    for(int i = 0; i < (int) sp.size(); i++) {
        m[sp[i]] += 1;
    }

    for(map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
        if(it->second > occ) {
            big_occ = it->first;
            occ = it->second;
        }
        if(it->first.size() >= ml) {
            big_size = it->first;
            ml = it->first.size();
        }
    }

    cout << big_occ << " " << big_size << endl;

    return 0;
}

Measured memory_bytes: 0
import sys

# import bisect
from collections import Counter, deque, defaultdict

# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
from operator import attrgetter, itemgetter

# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, a, b, c = list(map(int, readline().split()))
    l = [int(input()) for _ in range(n)]

    ans = INF

    base_idx = list(itertools.permutations(range(n), r=3))

    for bi in base_idx:
        bamboo_length = [0] * 3
        add_bamboo = list(itertools.product(range(4), repeat=(n-3)))
        rem_idx = [i for i in range(n) if i not in bi]
        for ai in add_bamboo:
            mp = 0
            bamboo_length[0] = l[bi[0]]
            bamboo_length[1] = l[bi[1]]
            bamboo_length[2] = l[bi[2]]
            for idx, num in enumerate(ai):
                if num != 3:
                    bamboo_length[num] += l[rem_idx[idx]]
                    mp += 10
            mp += abs(a - bamboo_length[0])
            mp += abs(b - bamboo_length[1])
            mp += abs(c - bamboo_length[2])
            ans = min(mp, ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47964
// C - Sum of gcd of Tuples (Easy)
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int ans = 0, K; cin>>K;
	rp(a, 1, K+1) rp(b, 1, K+1) rp(c, 1, K+1)
		ans += gcd(gcd(a, b), c);
	cout<< ans <<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, m;
    cin>>n>>m;
    n = min(n, m);
    vector<ll> x(m);
    for(ll i=0;i<m;++i){
        cin>>x[i];
    }

    sort(x.begin(), x.end());
    vector<ll> d(m-1);
    for(ll i=0;i<m-1;++i){
        d[i] = x[i+1] - x[i];
    }
    sort(d.begin(), d.end());
    ll ans = 0;
    for(ll i=0;i<d.size()-(n-1);++i){
        ans += d[i];
    }
    cout<<ans<<endl;

    return 0;
}

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const int INF = 100001;

set<string> se;
int n;

int main()
{
    cin >> n;
    char c = '@';
    string s;
    cin >> s;
    c = s.back();
    se.emplace(s);
    REP(i, n - 1)
    {
        string s;
        cin >> s;
        if (s[0] != c || se.find(s) != se.end())
        {
            cout << "No" << endl;
            return 0;
        }
        c = s.back();
        se.emplace(s);
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256