akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
using namespace std;

int h, w, map[102][102], dx[2][6] = {{-1, 0, -1, 1, -1, 0}, {0, 1, -1, 1, 0, 1}}, dy[6] = {-1, -1, 0, 0, 1, 1}, sum = 0;
bool checked[102][102];

void search(int x, int y){
    checked[x][y] = 1;

    for(int i = 0; i < 6; i++){
        int x2 = x + dx[y % 2][i], y2 = y + dy[i];
        if(x2 < 0 || x2 > w + 1 || y2 < 0 || y2 > h + 1 || checked[x2][y2]){
            continue;
        }

        if(map[x2][y2]){
            sum++;
        } else{
            search(x2, y2);
        }
    }

    return;
}

int main(){
    scanf("%d%d", &w, &h);
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            scanf("%d",&map[j][i]);
        }
    }

    search(0, 0);

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

    return 0;
}

Measured memory_bytes: 1552
#include<bits/stdc++.h>
using namespace std;
int dp[100001][3];
int main() {
	int n,x;
	cin>>n;
	int a[n+1],b[n+1],c[n+1];
	for(int i=1;i<=n;i++)
	{cin>>a[i]>>b[i]>>c[i];

	}
  dp[1][0]=a[1];
  dp[1][1]=b[1];
  dp[1][2]=c[1];
  

  for (int i =2; i <=n; ++i)
  {dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
   dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
   dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);

  }
  x=max(dp[n][0],dp[n][1]);
  x=max(dp[n][2],x);


  cout<<x<<endl;
  return 0;

}

Measured memory_bytes: 5960
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();

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

		int sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j <= d; j += a[i]) {
				sum++;
			}
		}

		pr.println(x + sum);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21716
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;
import static java.lang.Math.*;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		HashMap<Integer, Integer> a = new HashMap<>();
//		int[] a = new int[n];
		int tmp = 0;
		for (i = 0; i < n; i++) {
			tmp = parseInt(sc.next());
			if(a.get(tmp) == null) {
				a.put(tmp, 1);
			} else {
				a.put(tmp, a.get(tmp)+1);
			}
		}
		sc.close();
		ArrayList<Integer> list = new ArrayList<>(a.keySet());
//		Arrays.parallelSort(a);
		int cnt = 0;
		for (Integer ii : list) {
			cnt += a.get(ii) - 1;
		}
		int ans = list.size();
		if(cnt%2==1) {
			ans--;
		}
		out.println(ans);
	}
}


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll n,k; cin>>n>>k;
    vint p(n); rep(i,n) {cin>>p[i]; p[i]--;}
    vint c(n); rep(i,n) cin>>c[i];

    ll ans = LLONG_MIN;

    auto eval = [&](ll st){
        // cout<<st<<endl;
        vint score(n, 0);
        vint num(n,0);
        vector<bool> visited(n, false);
        // visited[st] = true;
        ll now = st;
        ll nxt = p[now];
        ll cnt = 0;
        ll ret = c[nxt];

        while(!visited[nxt]){
            cnt++;
            // cout<<"cnt: "<<cnt<<endl;
            // cout<<"(now, nxt) = "<<now<<" "<<nxt<<endl;
            score[nxt] = score[now] + c[nxt];
            visited[nxt] = true;
            num[nxt] = cnt;
            chmax(ret, score[nxt]);
            now = nxt;
            nxt = p[nxt];
            if(cnt == k) return ret;
        }

        // for(auto e:score)cout<<e<<" "; cout<<endl;

        ll diff = score[now] - score[nxt] + c[nxt];
        // cout<<"diff: "<<diff<<endl;

        ll res = k - cnt;

        if(diff <= 0){
            ll tmp = score[now];
            chmin(res, n);
            while(res>0){
                res--;
                tmp += c[nxt];
                nxt = p[nxt];
                chmax(ret, tmp);
            }
            return ret;
        }

        ll T = num[now] - num[nxt] + 1; // 周期
        ll loop = max(res/T - 2, 0ll); // loop回数
        // ret += diff*loop;
        res -= T*loop;

        // cout<<res<<" "<<loop<<endl;

        ll tmp = score[now] + diff*loop;

        while(res>0){
            res--;
            tmp += c[nxt];
            now = nxt;
            nxt = p[nxt];
            chmax(ret, tmp);
        }

        return ret;

    };

    rep(st, n){
        chmax(ans, eval(st));
    }



    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 3768
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


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

	if ((n % 500) <= a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

void print1d(const vector<int>& vec) {
    for (auto val : vec) {
        cout << val << " ";
    }
    cout << endl;
}

void print2d(const vector<vector<int>>& vec) {
    for (auto row : vec) {
        for (auto val : row) {
            cout << val << " ";
        }
        cout << endl;
    }
}

void solve() {
    int n, m;
    cin >> n >> m;

    vi height(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> height[i];
    }

    vvi adj(n + 1);

    while (m--) {
        int x, y;
        cin >> x >> y;

        adj[x].push_back(height[y]);
        adj[y].push_back(height[x]);
    }

    // print2d(adj);

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (adj[i].size() == 0 or (*max_element(adj[i].begin(), adj[i].end()) < height[i]))
            cnt++;
    }

    cout << cnt << endl;
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
#endif
    crap;

    solve();

    return 0;
}

Measured memory_bytes: 9804
import collections
w = str(input())
w = collections.Counter(w)

flg = 0

for i in range(len(w)):
    tmp = w.most_common()[i][1]
    
    if tmp % 2 == 1:
        flg = 1
        
if flg == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3444
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def readChars(S, c, i):
  count = 0
  for k in range(i, len(S)):
    if S[k] == c:
      count += 1
    else:
      return (k, count)
  return (len(S), count)

def solve():
  S = input()
  ans = [0 for _ in range(len(S))]
  i = 0
  while i < len(S):
    j, countR = readChars(S, 'R', i)
    i, countL = readChars(S, 'L', j)
    ans[j-1] += (countR // 2) + (countR % 2) + (countL // 2)
    ans[j] += (countR // 2) + (countL // 2) + (countL % 2)
  print(" ".join(map(str, ans)))

def main():
  solve()

if __name__ == "__main__":
  main()


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

using namespace std;

typedef long long ll;
typedef long double K;
typedef pair<int, int> pii;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const ll inf = 1e18;

const int N = 51;
const int MONEY = 5001;

struct way
{
    int to, a, b;
};

vector<way> g[N];

ll dp[N][MONEY];
bool was[N][MONEY];

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

    int n, m, s;
    cin >> n >> m >> s;
    if (s > MONEY)
    {
        s = MONEY - 1;
    }
    for (int i = 0; i < m; i++)
    {
        int q, w, a, b;
        cin >> q >> w >> a >> b;
        g[q].pb({w, a, b});
        g[w].pb({q, a, b});
    }

    int c[n + 1], d[n + 1];
    for (int i = 1; i <= n; i++)
    {
        cin >> c[i] >> d[i];
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < MONEY; j++)
        {
            dp[i][j] = inf;
        }
    }
    dp[1][s] = 0;
    was[1][s] = true;

    queue<pii> q;
    q.push({1, s});

    while (!q.empty())
    {
        pii tmp = q.front();

        int v = tmp.x;
        int mon = tmp.y;

        // cout << v << " " << mon << " " << dp[v][mon] << "\n";

        for (int i = 0; i <= MONEY / c[v]; i++)
        {
            ll newmon = mon + 1ll * i * c[v];
            newmon = min(newmon, 1ll * MONEY - 1);

            ll cost = dp[v][mon] + 1ll * i * d[v];
            if (cost < dp[v][newmon])
            {
                dp[v][newmon] = cost;
                if (!was[v][newmon])
                {
                    q.push({v, newmon});
                    was[v][newmon] = true;
                }
            }

            if (newmon == MONEY - 1)
            {
                break;
            }
        }

        for (way &y : g[v])
        {
            ll cost = 0ll + dp[v][mon] + y.b;
            if(mon >= y.a && cost < dp[y.to][mon - y.a]){
                if(!was[y.to][mon - y.a]){
                    was[y.to][mon - y.a] = true;
                    q.push({y.to, mon - y.a});
                }
                dp[y.to][mon - y.a] = cost;
            }
        }

        q.pop();
        was[tmp.x][tmp.y] = false;
    }

    for (int i = 2; i <= n; i++)
    {
        ll ans = inf;
        for (int j = 0; j < MONEY; j++)
        {
            ans = min(ans, dp[i][j]);
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 7280
//https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_11_B
//深さ優先探索
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}

template< typename T >
struct edge {
	int src, to;
	T cost;
	edge(int _to, T _cost) : src(-1), to(_to), cost(_cost) {}
	edge(int _src, int _to, T _cost) : src(_src), to(_to), cost(_cost) {}
	edge &operator=(const int &x) {
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template< typename T>
struct node {
	vector<edge<T>> edges;
    ll d=0,f=0;
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< node< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
    ll n; cin>>n;
    WeightedGraph<ll> graph(n+1);
    FOR(i,1,n+1){
        ll u, k; cin>>u>>k;
        FOR(j,0,k){
            ll v; cin>>v;
            graph[i].edges.emplace_back(u,v,1);
        }
    }

    ll counter=1;
    function<void(ll)> dfs = [&](ll id){
        auto& node=graph.at(id);
        if (node.d!=0)return; //訪問済
        node.d=counter++;
        for(const auto& e :graph.at(id).edges){
            dfs(e);
        }
        node.f=counter++;
    };

    FOR(i,1,n+1){
        dfs(i);
    }

    FOR(i,1,n+1){
        const auto& node=graph.at(i);
        cout<<i<<" "<<node.d<<" "<<node.f<<endl;
    }

    return 0;
}


Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	string p;
	cin >> p;
	if (p == "Sunny")cout << "Cloudy" << endl;
	if (p == "Cloudy")cout << "Rainy" << endl;
	if (p == "Rainy")cout << "Sunny" << endl;

	return 0;


}

Measured memory_bytes: 256
l, r = (int(x) for x in input().split())
tmpmin = 2019
if r-l >= 2019:
    print(0)
else:
    for i in range(l, r):
        for j in range(l+1, r+1):
            tmp = (i*j)%2019
            if tmp < tmpmin:
                tmpmin = tmp
                if tmpmin == 0:
                    break
    print(tmpmin)

Measured memory_bytes: 3060
main(){float a,b,c,d,e,f,g,h;for(;~scanf("%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g,&h);puts(((a-=g)*(d-=h)-(b-=h)*(c-=g))*(g=(c*(f-=h)-d*(e-=g)))>0&g*(e*b-f*a)>0?"YES":"NO"));}

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

using namespace std;


struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef long long LL;

typedef vector<LL> V;
typedef vector<V> VV;

const LL MOD=1e9+7;
LL p[500][500];
struct CWW{CWW(){
    for(int i=1;i<500;i++){
        p[i][0]=1;
        for(int j=1;j<500;j++)
            p[i][j]=p[i][j-1]*i%MOD;
    }
}}cww;

int main(){
    int N,C;
    cin>>N>>C;
    V A(N),B(N);
    for(auto &it:A)cin>>it;
    for(auto &it:B)cin>>it;
    //for(int i=0;i<N;i++)if(A[i]!=B[i])return -1;
    V dp(C+1,0);
    dp[0]=1;
    for(int i=0;i<N;i++){
        V c(C+1,0);
        V nxt(C+1,0);
        for(int j=A[i];j<=B[i];j++)
            for(int k=0;k<=C;k++)
                (c[k]+=p[j][k])%=MOD;
        for(int j=0;j<=C;j++)
            for(int k=0;k<=C-j;k++)
                (nxt[j+k]+=(dp[j]*c[k])%MOD)%=MOD;
        swap(dp,nxt);
    }
    cout<<dp[C]<<endl;

    return 0;
}


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

// types
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;

// macros
#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 Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
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,k;
  cin >> n >> k;
  string s;
  cin >> s;


  vll v;
  ll cnt = 1;
  char p = s[0];

  if(s[0]=='0')
    v.push_back(0);
  REP1(i, n){
    if(p != s[i]){
      v.push_back(cnt);
      cnt = 1;
      p = s[i];
    }
    else
      cnt++;
  }
  v.push_back(cnt);
  if(s[n-1]=='0')
    v.push_back(0);


  ll now = 0;
  ll w_size = min(ll(v.size()), k*2+1);
  REP(i, w_size)
    now += v[i];

  ll ans = now;
  for(int i = w_size; i+1 < v.size(); i+=2){
    now += v[i] + v[i+1] - (v[i-w_size]+v[i-w_size+1]);
    ans = max(ans, now);
  }

  cout << ans << endl;

}



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

struct Rational {
    long long num;
    long long den;
    Rational(const long long n = 0, const long long d = 1) : num(n), den(d) {}
    bool operator==(const Rational& r) const {
        return num == r.num && den == r.den;
    }
    bool operator!=(const Rational& r) const { return !(*this==r); }
    bool operator<(const Rational& r) const { return compare(r) < 0; }
    bool operator>(const Rational& r) const { return compare(r) > 0; }
    bool operator<=(const Rational& r) const { return compare(r) <= 0; }
    bool operator>=(const Rational& r) const { return compare(r) >= 0; }
    inline long long compare(const Rational& r) const {
        long long ln = num, ld = den, rn = r.num, rd = r.den;
        if ( ld < 0 ) ln = -ln, ld = -ld;
        if ( rd < 0 ) rn = -rn, rd = -rd;
        return ln * rd - ld * rn;
    }
};

ll solve() {
    ll A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    Rational rmax(0,100*A);
    ll wmax = 100*A, smax = 0;
    for ( ll b = 0; b * 100 * B <= F; b++ ) {
        for ( ll a = 0; b * 100 * B + a * 100 * A <= F; a++ ) {
            ll w = a * 100 * A + b * 100 * B;
            if ( w == 0 || w > F ) continue;
            ll emax = w / 100 * E;
            for ( ll d = 0; d * D <= emax; d++ ) {
                for ( ll c = 0; d * D + c * C <= emax; c++ ) {
                    ll s = c * C + d * D;
                    if ( w + s > F ) continue;
                    Rational r(s, w + s);
                    if ( rmax < r ) {
                        rmax = r;
                        wmax = w;
                        smax = s;
                    }
                }
            }
        }
    }
    
    cout << wmax + smax << " " << smax << "\n";
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

A.sort(reverse = True)

alc = 0
bob = 0

N -= 1
end = int(N/2) + 1

if N % 2 == 0:
    f = 1
else:
    f = 0

for i in range(0, end):
    alc += A[2*i]
    if f == 1 and 2*i == N:
        break
    bob += A[2*i+1]

print(alc-bob)

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

int main() {
  string s;
  cin >> s;
  
  int ans = 1e9;
  
  for (int i=0; i<s.length()-2; i++){
    ans = min(ans, abs(753 - stoi(s.substr(i, 3))));
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
def solve():
  h,w = (int(i) for i in input().split())
  maze = []
  for i in range(h):
    tmp = input()
    maze.append(tmp)
  l = [[0]*w for _ in range(h)]
  r = [[0]*w for _ in range(h)]
  u = [[0]*w for _ in range(h)]
  d = [[0]*w for _ in range(h)]
  cur = 0
  for i in range(h):
    cur = 0
    for j in range(w):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      l[i][j] = cur
  for i in range(h):
    cur = 0
    for j in range(w-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      r[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      d[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      u[i][j] = cur      
  ans = 0
  for i in range(h):
    for j in range(w):
      now = l[i][j]+r[i][j]+u[i][j]+d[i][j] -3
      ans = max(now,ans)
  print(ans)
solve()

Measured memory_bytes: 181636
mod = 10**9+7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]


def init(n):
    for i in range(2, n + 1):
        fac.append(fac[-1] * i % mod)
        inv.append(-inv[mod % i] * (mod // i) % mod)
        finv.append(finv[-1] * inv[-1] % mod)


def com(n, k, mod):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


X, Y = map(int, input().split())
b = max([X, Y])
s = min([X, Y])
if s - (b-s) < 0 or not (s-(b-s)) % 3 == 0:
    print(0)
    exit()

s_t = (s-(b-s))//3
b_t = (s-(b-s))//3 + (b-s)
a = s_t + b_t
b = b_t
p = 10**9 + 7
init(a)
print(com(a, b, p))


Measured memory_bytes: 88108
S =input()
S_bin = int("0b"+S, 0)
if len(S)%2 == 0:
    a = int("0b"+"01"*int(len(S)/2),0)
    b = int("0b"+"10"*int(len(S)/2),0)
else:
    a = int("0b"+"1" + "01"*int(len(S)/2) ,0)
    b = int("0b"+"0" + "10"*int(len(S)/2) ,0)
print(min(bin(a^S_bin).count("1"),bin(b^S_bin).count("1")))

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>

#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define vec vector

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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;
  }
};

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i, a) {
    x *= n-i;  // n~(n-a)まで
    y *= i+1;  // 1~aまで（0始まりだから）
  }
  return x / y;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  mint ans = mint(2).pow(n);
  ans -= 1;
  ans -= choose(n, a);
  ans -= choose(n, b);
  say(ans.x);
  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
int main() {
    short int H, W, K;
    char Grid[6][6];
    scanf("%hi%hi%hi", &H, &W, &K);
    K *= -1;
    for (short int i = 0; i < H; i++) {
        scanf("%*c");
        for (short int j = 0; j < W; j++) {
            scanf("%c", &Grid[i][j]);
            if (Grid[i][j] == '#') K++;
        }
    }

    short int ans = 0;
    for (short int rowMask = 0; rowMask < (1 << H); rowMask++) {
        for (short int colMask = 0; colMask < (1 << W); colMask++) {
            short int cnt = 0;
            for (short int i = 0, pow1 = 1; i < H; i++, pow1 <<= 1) {
                for (short int j = 0, pow2 = 1; j < W; j++, pow2 <<= 1) {
                    if (Grid[i][j] == '#'
                        && (rowMask % (pow1 << 1) / pow1
                            || colMask % (pow2 << 1) / pow2)) {
                        cnt++;
                    }
                }
            }
            if (cnt == K) ans++;
        }
    }
    printf("%hi", ans);
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
#include <algorithm>
#include<set>
#include <limits>
#include<iomanip>
#include<string>
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
#define d9_7 1000000007
int main(void){
  ll n,a,b,c,d;
  cin >> n>>a>>b>>c>>d;
  ll tmp1;
  ll tmp2;
  n--;
  for(ll i=0;i<n+1;i++){
    tmp1=(i-n)*d+i*c;
    tmp2=(i-n)*c+i*d;
    if(tmp1>tmp2)swap(tmp1,tmp2);
    if((ll)abs(b-a)>=tmp1 && (ll)abs(b-a)<=tmp2){
      //cout<<tmp1<<" "<<tmp2<<" "<<i<<endl;
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}

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

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

  vector<long long> a(n + 1), r(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] > 0) r[i] = a[i];
  }

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

  long long ans = -1001001001001001;
  for (int i = 0; i + k <= n; ++i) {
    ans = max(ans, r[i] + max(0ll, a[i + k] - a[i]) + r[n] - r[i + k]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define For(i, a, b) for(long long i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
using namespace std;

signed main(void)
{
	long long n, cnt;
	vector<long long> a, b;

	cin >> n;
	rep(i, n + 1) {long long x; cin >> x; a.push_back(x);}
	rep(i, n) {long long x; cin >> x; b.push_back(x);}
	cnt = 0;
	rep(i, n)
	{
		if (a[i] - b[i] < 0)
		{
			cnt += a[i];
			b[i] -= a[i];
			a[i] = 0;
			if (a[i + 1] - b[i] < 0)
			{
				cnt += a[i + 1];
				a[i + 1] = 0;
			}
			else
			{
				cnt += b[i];
				a[i + 1] -= b[i];
			}
		}
		else
		{
			cnt += b[i];
			a[i] -= b[i];
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 2548
import java.io.*;
import java.util.*;

public class Main {
	private static final boolean local = false;
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter output;
	//char c = line.nextToken().charAt(0);

	private static void openFile() throws IOException {
		if (local) {
			String inp = "C:/Users/ztrong/Desktop/AndroidStudioProjects/Java/src/main/java/input.txt";
			String out = "C:/Users/ztrong/Desktop/AndroidStudioProjects/Java/src/main/java/output.txt";
			br = new BufferedReader(new InputStreamReader(new FileInputStream(inp)));
			output = new PrintWriter(new FileOutputStream(out));
		} else {
			br = new BufferedReader(new InputStreamReader(System.in));
			output = new PrintWriter(System.out);
		}
	}

	private static String _next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	private static int nextInt() {
		return Integer.parseInt(_next());
	}

	private static long nextLong() {
		return Long.parseLong(_next());
	}

	private static double nextDouble() {
		return Double.parseDouble(_next());
	}

	private static String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}

	private static final int maxN = (int) 1e5 + 5;
	private static final int maxM = (int) 1e6 + 5;
	private static final int inf = (int) 1e9 + 7;

	private static int N;
	private static int[] a = new int[maxN];
	private static int cnt1, cnt2, cnt4;

	private static void init() {

	}

	private static void enter() throws IOException {
		N = nextInt();
		for (int i = 1; i <= N; ++i) {
			int x = nextInt();
			if (x % 4 == 0) {
				++cnt4;
			}
			else if (x % 2 == 0) {
				++cnt2;
			}
			else {
				++cnt1;
			}
		}
	}

	private static void print(boolean ok) {
		if (ok) {
			output.println("Yes");
		}
		else {
			output.println("No");
		}
	}

	private static void solve() throws IOException {
		if (cnt2 == 0) {
			print(cnt4 + 1 >= cnt1);
		}
		else {
			print(cnt4 >= cnt1);
		}
	}

	public static void main(String[] args) throws IOException {
		openFile();
		init();
		enter();
		solve();
		output.close();
	}
}

Measured memory_bytes: 36232
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int kokunai = 0, kaigai = 0;

    for (auto &&i : s) {
        bool passed = false;

        switch (i) {
            case 'a':
                if (kokunai + kaigai < a + b) {
                    kokunai++;
                    passed = true;
                }
                break;

            case 'b':
                if (kokunai + kaigai < a + b && kaigai < b) {
                    kaigai++;
                    passed = true;
                }
                break;

            case 'c':
                break;
        }

        cout << (passed ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 976
#include<stdio.h>
int main(void)
{
    int i,k,n,x,y,min;
    scanf("%d",&n);
 
 
 
    scanf("%d",&k);
    for(i=1;i<=k;i++) {
        scanf("%d %d",&x,&y);
        min=n;
        if((n+1)-x <= min) {
            min=(n+1)-x;
        }
        if((n+1)-y <= min) {
            min=(n+1)-y;
        }
        if(x <= min) {
            min=x;
        }
        if(y <= min) {
            min=y;
        }
 
 
 
        if(min % 3 == 1) {
            printf("1\n");
        }
        if(min % 3 == 2) {
            printf("2\n");
        }
        if(min % 3 == 0) {
            printf("3\n");
        }
    }
    return 0;
}

Measured memory_bytes: 580
N, M = gets.split.map(&:to_i)
abs = M.times.map { gets.split.map(&:to_i) }
min_rs = Hash.new { 1 << 60 }
abs.each do |(a, b)|
  min_rs[a] = b if b < min_rs[a]
end

ans = 0
right = nil
sorted_ls = min_rs.keys.sort
sorted_ls.each do |l|
  r = min_rs[l]
  if right.nil?
    right = r
    next
  end
  if l >= right
    ans += 1
    right = r
  else
    right = r if r < right
  end
end
ans += 1
puts ans


Measured memory_bytes: 18424
#include<cstdio>

int main(){
	int a, b, c, x;
	int n = 0;
	scanf("%d %d %d", &a, &b, &c);
	for(int x = a; x <= b; x++){
		if(c%x != 0) continue;
		n++;
	}

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

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int const NMAX = 100;
long long v[1 + NMAX];

int main() {

  string s;
  long long n, ans = 0, k, d;
  cin >> n >> k >> d;n = abs(n);
  if(n / d > k){
    cout << n - (d * k);
  }else{
    if((n / d) % 2 == k % 2){
      cout << n % d;
    }else{
      cout << d - n % d;
    }
  }
  return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
int main(){
    int n;
    char s[100],t[100],ans[200],a;
    scanf("%d",&n);
    scanf("%c",&a);
    for(int i=0;i<n;i++){
        scanf("%c",&s[i]);
    }
    scanf("%c",&a);
    for(int i=0;i<n;i++){
        scanf("%c",&t[i]);
    }
    for(int i=0;i<n;i++){
        printf("%c",s[i]);
        printf("%c",t[i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

int main(){
   int N, M, X, Y, x, y;
   std::cin >> N >> M >> X >> Y;
   int max = X;
   for(int i=0; i<N; ++i){
      std::cin >> x;
      if(max<x) max = x;
   }
   int min = Y;
   for(int i=0; i<M; ++i){
      std::cin >> y;
      if(min>y) min = y;
   }
   if(min>max) std::cout << "No War" << std::endl;
   else std::cout << "War" << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
typedef long long ll;

using namespace std;

int n,h[100010];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    cin>>n;
    for(re int i=1;i<=n;i++){
    	scanf("%d",&h[i]);
        if(n==1){
        	cout<<"Yes";
        	return 0;
        }
        if(h[i]-h[i-1]<0){
		cout<<"No";
		return 0; 
    }
    if(h[i]-h[i-1]>0){
    	h[i]-=1; 
    }
}
cout<<"Yes";
	return 0;
}


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

ll solve(vector<int> &weight, vector<int> &value, int w) {
  int n = value.size();
  vector<ll> dp(w + 1, 0);
  for (int j = 1; j <= n; ++j) {
    for (int wt = w; wt - weight[j - 1] >= 0; --wt) {
      dp[wt] = max(dp[wt], value[j - 1] + dp[wt - weight[j - 1]]);
    }
  }
  ll ans = 0;
  for (int i = 1; i <= w; ++i) {
    ans = max(ans, dp[w]);
  }
  return ans;
}

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> value(n, 0);
  vector<int> weight(n, 0);
  for(int i = 0; i < n; ++i) {
    cin >> weight[i];
    cin >> value[i];
  }
  cout << solve(weight, value, w) << '\n';
  return 0;
}


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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
 
int main() {
int n;
cin >> n;
int m;
cin >> m;
int a;
cin >> a;
if(n>a || n+m<a)cout << "NO" << endl;
  else {cout << "YES" << endl;}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////

void solve() {
	vector<int>A(5);
	int time = 0;
	vector<int>B;
	for (int i = 0; i < 5; ++i) {
		cin >> A[i];
		if (A[i] % 10 == 0) {
			time += A[i];
		}
		else {
			B.push_back(A[i]);
		}
	}
	int N = B.size();
	vector<int>C;
	for (int i = 0; i < N; ++i) {
		int ter = B[i];
		time += (ter / 10) * 10;
		B[i] %= 10;
	}
	sort(B.begin(), B.end());
	
	if (B.size()) {
		time += 10 * (B.size() - 1);
		time += B[0];
	}
	cout << time << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
def main():
    n = input()
    data = input().split()
    data = list(map(lambda x: int(x), data))

    mid_val = calculate_mean(data)

    if int(n) < 1 or 101 < int(n):
        return -1

    current_pos = -1
    current_distance = 101

    if int(n) == len(data):
        for key, value in enumerate(data):
            if int(value) < 1 or 101 < int(value):
                return -1
            new_distance = abs(mid_val - value)
            if current_distance > new_distance:
                current_pos = key
                current_distance = new_distance
        return current_pos


def calculate_mean(data):
    s = sum(data)
    N = len(data)
    mean =s/N

    return mean

r = main()
print(r)



Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = a - b - b;
		if (ans < 0) ans = 0;
		out.println(ans);
		
	}
}

Measured memory_bytes: 25300
#include <cstdio>

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

int main()
{
	long long a,b;
	scanf("%lld%lld",&a,&b);
	printf("%lld",a*b/gcd(a,b));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(b-a==c-b?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	char op;
	while(cin >> a >> op >> b){
		if(op=='?')
			break;
		switch(op){
			case '+' : cout << a+b << endl; break;
			case '-' : cout << a-b << endl; break;
			case '*' : cout << a*b << endl; break;
			case '/' : cout << a/b << endl; break;
		}
	}
	return 0;
} 


Measured memory_bytes: 3100
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  cout << 3 * n *n;
  return 0;
} //good night.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int H, W;
    cin >> H >> W;
    string S[50];
 
    for (int i=0; i<H; i++) {
        cin >> S[i];
    }
    // 基準となる座標からの周りの座標位置 
    int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if ( S[i][j] == '.') {    
                int num = 0;
                for (int d=0; d<8; d++) {
                    int ni = i + dx[d]; // 基準座標の周りのx座標
                    int nj = j + dy[d]; // 基準座標の周りのy座標
 
                    if (ni < 0 or H <= ni) continue; //座標の外なら無視
                    if (nj < 0 or W <= nj) continue;//座標の外なら無視
                    if (S[ni][nj] == '#') num++;
                }
                S[i][j] = num+'0'; //数値に文字列を足すと文字の数値に変換される。
            }
        }
    }
    for (int i=0; i<H; i++) {
        cout << S[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//Be Name Khoda
/*
tane ezafami sharifast be jane ezafamiat
na hamin lebase zibast neshane ezafamiat
agar ezafami be cheshmasto dahano goosho bini
che miane naghshe divaro miane ezafamiat
khoro khabo khashmo shahvat shaghab asto jahlo zolmat
hayavan khabar nezafarezaf ze jahane ezafamiat
be haghighat ezafami bash vagarna morgh bashezaf
ke hami sokhan begooyezaf be zabane ezafamiat
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=1e5+10,LG=26,SM=105,inf=1e9+5;
ll mod=1e9+7;

ll f(ll x)
{
    if (x<10) return x;
    return f(x/10)*10;
}

ll su(ll x)
{
    if (x==0) return 0;
    return x%10+su(x/10);
}

int main()
{
    ios::sync_with_stdio(0);
    ll n;
    cin >> n;
    if (f(n+1)==n+1) RET(su(n));
    RET(su(f(n)-1));
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009



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

    // input
    ll N;
    cin >> N;
    vector<ll> height(N);
    REP(i, N) cin >> height[i];
    
    // calculation
    if (N == 1) {
        cout << height[0] << "\n";
    } else {
        ll idx = 0, left, right, min_interval;
        ll sum_height = SUM(height), res = 0;
        while (sum_height > 0) {
            // 区間を定める
            left = -1, right = -1;
            min_interval = 101;
    
            // 左端を定める
            for (ll i = 0; i < N; ++i) {
                if (height[i] != 0) {
                    left = i;
                    break;
                }
            }
            
            if (left == -1) {
                // 全てが 0 の場合
                break;
            } else {
                // 右端を定める
                for (ll i = left; i < N; ++i) {
                    if (height[i] != 0) {
                        min_interval = min(min_interval, height[i]);
                        right = i;
                    } else {
                        break;
                    }
                }
                
                if (left == right) {
                    // 順序気をつける
                    res += height[left];
                    sum_height -= height[left];
                    height[left] -= min_interval;
                } else {
                    for (ll i = left; i <= right; ++i) {
                        height[i] -= min_interval;
                        sum_height -= min_interval;
                    }
                    res += min_interval;
                }
            }
        }
        
        cout << res << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0; char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
int cnt[333];
string s;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		cnt[s[i]-'A']++;
	}
	int ok=1;
	for(int i=0;i<=222;i++){
		if(cnt[i]&&cnt[i]!=2)ok=0;
	}
	if(ok)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    long long n, m, d;
    cin >> n >> m >> d;

    if (d == 0) {
        cout << setprecision(7) << (m - 1) * 1.0 / n << endl;
    } else {
        cout << setprecision(7) << ((n - d) * 2 * (m - 1)) * 1.0 / (n * n) << endl;
    }

    return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int H = input(), W = input(), d = input();
    char chars[] = {'R', 'G', 'B', 'Y'};

    range(i, 0, H) range(j, 0, W) {
        int y = (i + j + 1000) / d;
        int x = (i - j + 1000) / d;
        int c = (y & 1 ? 0 : 2) + (x & 1 ? 0 : 1);

        cout << chars[c] << (j + 1 == W ? "\n" : "");
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 512
sx, sy, tx, ty = map(int, input().split(' '))
up_cnt = ty - sy
slide_cnt = tx - sx
print('U' * up_cnt + 'R' * slide_cnt +
      'D' * up_cnt + 'L' * slide_cnt +
      'L' + 'U' * (up_cnt + 1) + 'R' * (slide_cnt + 1) + 'D' +
      'R' + 'D' * (up_cnt + 1) + 'L' * (slide_cnt + 1) + 'U')

Measured memory_bytes: 3060