akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	cycle_detection
# CreatedDate:  2020-07-28 21:10:00 +0900
# LastModified: 2020-07-28 21:57:12 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


class Graph():
    def __init__(self, vertex):
        self.V = vertex
        self.path = [[] for _ in range(self.V)]
        self.visited = [False] * self.V
        self.recurbox = [False] * self.V

    def addedge(self, s, t):
        self.path[s].append(t)

    def dfs(self, u):
        self.visited[u] = True
        self.recurbox[u] = True
        for v in self.path[u]:
            if self.visited[v] is False:
                if self.dfs(v) is True:
                    return True
            elif self.recurbox[v] is True:
                return True
        self.recurbox[u] = False
        return False

    def dfsutil(self):
        for i in range(self.V):
            if self.visited[i] is False:
                if self.dfs(i) is True:
                    return True
        return False


def main():
    V, E = map(int, input().split())
    graph = Graph(V)
    for _ in range(E):
        s, t = map(int, input().split())
        graph.addedge(s, t)
    if graph.dfsutil() is True:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string s;
  cin >> s;
  vc vec;
  map<char, ll> m;
  rep(i, 4) {
    vec.push_back(s[i]);
    m[s[i]]++;
  }
  bool T=1;
  rep(i, vec.size()) if(m[vec[i]]!=2) T=0;
  cout << (T ? "Yes" : "No") << newl;
  return 0;
}


Measured memory_bytes: 256
op = list(input().split())
stack = []
for i in range(len(op)):
  if op[i] == '+':
    a = stack.pop(-1)
    b = stack.pop(-1)
    stack.append(a+b)
  elif op[i] == '-':
    a = stack.pop(-1)
    b = stack.pop(-1)
    stack.append(b-a)
  elif op[i] == '*':
    a = stack.pop(-1)
    b = stack.pop(-1)
    stack.append(a*b)
  else:
    stack.append(int(op[i]))
print(stack.pop(-1))
  
    


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
using namespace std;

int main() {
    cin.tie(nullptr);

    int m,n;
    cin >> n >> m;
    int cont = 0;
    vector<int> a(n);
    int S = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        S += a[i];
    }

    double treashold = (1 / (double) (4*m)) * (double) S;
    for(int i=0;i<n;i++){
        if(a[i] >= treashold) cont++;
    }

    if(cont >= m) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


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

long long n;
long long pr[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};

double res = 1.0;
void rec(long long now, int i, int k, double tmp) {
    if (now > n) return;
    chmax(res, tmp);
    
    rec(now * pr[i], i, k+1, tmp * (power(pr[i],k+2) - 1) / (power(pr[i],k+2) - pr[i]) );
    rec(now * pr[i+1], i+1, 1, tmp * (pr[i+1] + 1) / pr[i+1] );
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (cin >> n) {
        if (n == 0) break;
        res = 1.0;
        rec(2, 0, 1, 1.5);
        
        cout << fixed << setprecision(9) << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	string s;
 	cin>>s;
 	if((s[0]==s[1])||(s[1]==s[2])||(s[2]==s[3]))
 		cout<<"Bad"<<endl;
 	else
 		cout<<"Good"<<endl;
 	return 0;
}
 	
 					

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  int n,k,x,y;
  scanf("%d%d%d%d",&n,&k,&x,&y);
  if(n<=k) printf("%d\n",n*x);
  else printf("%d\n",k*x+(n-k)*y);
  return 0;
}


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

int main()
{
  int N, buf, rem = 0;
  cin >> N;
  buf = N;
  
  while(buf != 0)
  {
    rem += buf % 10;
    buf /= 10;
  }
  
  if(N % rem == 0)
  	cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int n, p;
  while(cin >> n >> p){
    if(n == 0 && p == 0) break;

    int stone[n];
    int left = p;
    
    for(int i = 0 ; i < n ; i++){
      stone[i] = 0;
    }

    int i = 0;

    while(1){
      if(left > 0){
	stone[i]++;
	left--;
      }
      else{
	left += stone[i];
	stone[i] = 0;
      }

      if(left == 0 && stone[i] == p){
	break;
      }
      i++;
      if(i == n) i = 0;
    }
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 864
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<iostream>
using namespace std;
int rec(string s){
  priority_queue<int,vector<int>,greater<int> > que;
  bool flg=true;
  stack<int> sta;
  for(int i=0;i<s.size();i++){
    if(s[i]=='['){ sta.push(i); flg=false;}
    if(s[i]==']'){ int tmp=sta.top(); sta.pop();
      if(sta.empty()){ que.push(rec(s.substr(tmp+1,i-tmp-1))); 
        //        cout << "s.substr : " << s.substr(tmp+1,i-tmp-1) << endl;
        //        cout << "kakko : " << rec(s.substr(tmp+1,i-tmp-1)) << endl;}
    }
  }
}
if(flg){ return ((atoi(s.c_str())+1)/2);} // cout << "atoi : " << (atoi(s.c_str())+1)/2 << endl;}
int gott = que.size();
int res=0;
for(int i=0;i<((gott+1)/2);i++){
  //cout << "que.pop " << i << " : " << que.top() << endl;
  res+=que.top(); que.pop();
}
return res;


}


int main(){
  string s;
  int N;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    cin >> s;
    printf("%d\n",rec(s));
  }

  return 0;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

vector<int> d(2*100000);
vector<int> p(2*100000,-1);
vector<vector<int>> r(2*100000, vector<int>(0));

void dfs(int i, int v) {
  d[i] += v;
  rep(j, r[i].size()){
    if (p[r[i][j]] == -1) {
      p[r[i][j]] = i;
      dfs(r[i][j], d[i]);
    }
  }
}

int main() {
  int n,q;
  cin >> n >> q;
  vector<int> a(n-1), b(n-1);
  rep(i,n-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    r[a[i]].push_back(b[i]);
    r[b[i]].push_back(a[i]);
  }

  rep(i,q) {
    int p, x;
    cin >> p >> x;
    d[p-1] += x;
  }

  p[0] = 0;
  dfs(0,0);
  rep(i,n) cout << d[i] << endl;

  return 0;
}


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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
const ll inf = (ll)1e18;
const ll N = (ll)2e5+77;
const ll mod = (ll)1e9+7;

int main() {
    fast;
    int n, f[111][10], p[111][10];
    cin >> n;
    forn(i, n) forn(j, 10) cin >> f[i][j];
    forn(i, n) forn(j, 11) cin >> p[i][j];

    int ans = INT_MIN;
    for1(mask, (1 << 10)-1) {
        int profit = 0, c = 0;
        forn(i, n) {
            c = 0;
            forn(j, 10) {
                if (f[i][j] and (mask & (1 << j))) c++;
            }
            profit += p[i][c];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N;
    cin >> N;
    VLL A(N);
    rep(i,N){
        cin >> A[i];
    }
    ll money=1000;
    ll have=0;
    for(int i=0; i<N-1; i++){
        money+=have*A[i];
        have=0;
        if(A[i+1]>=A[i]){
            have=money/A[i];
            money%=A[i];
        }
    }
    money+=have*A[N-1];
    cout << money << endl;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int k = scan.nextInt();

    String s = scan.next();

    ArrayList<Integer> a = new ArrayList<Integer>();
    ArrayList<Integer> b = new ArrayList<Integer>();

    boolean stop = false;
    char pre = s.charAt(0);
    if (pre == '0'){
      a.add(0);
    }
    int count = 1;
    for (int i=1;i<n;i++){
        char current = s.charAt(i);
        if (current == pre){
          count += 1;
          if (i == n-1){
            if (current == '1'){
              a.add(count);
            }
            else{
              b.add(count);
            }
          }
        }
        else{
          if (current == '1'){
            b.add(count);
          }
          else{
            a.add(count);
          }

          count = 1;

          if (i == n-1){
            if (current == '1'){
              a.add(count);
            }
            else{
              b.add(count);
            }
          }
        }
        pre = current;
    }

    a.add(0);

    if (k >= b.size()){
      System.out.println(n);
    }
    else{
      long sum = 0;
      long check = 0;
      int g = b.size();
      for (int i=0;i<=g-k;i++){
        check = 0;
        for (int j=0;j<k;j++){
          check += a.get(i+j);
          check += b.get(i+j);
        }
        check += a.get(i+k);
        sum = Math.max(sum,check);
      }
      System.out.println(sum);
    }
  }
}


Measured memory_bytes: 42768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

ll n;
vector<int> a;

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

// 中央値が x 以上か否か
bool C(int x){
    // (a[i] < x) → -1
    // (a[i] >= x) → 1
    // とした場合の累積和
    // second には 位置情報が入っている
    vector<P> sum(n+1, P(0, 0));

    for(int i = 0; i < n; ++i){
        if(a[i] < x)    sum[i+1].first = sum[i].first - 1;
        else    sum[i+1].first = sum[i].first + 1;
        sum[i+1].second = i+1;
    }
    sort(sum.begin(), sum.end());
    
    // 転倒数を求めるためのセグ木
    SegmentTree<int> seg(n+5, [](int a, int b){return a + b;}, 0);
    ll res = 0;
    for(int i = 0; i < n+1; ++i){
        int pos = sum[i].second;
        res += seg.query(0, pos);
        seg.update(pos, 1);    
    }

    // x が中央値になるための条件
    ll comparision = (n * (n + 1) / 2 + 1) / 2;
    return res >= comparision;
}

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

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

    int lb = 0, ub = *max_element(a.begin(), a.end()) + 1;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(C(mid))  lb = mid;
        else    ub = mid;
    }
    cout << lb << endl;
}

Measured memory_bytes: 2440
A, B, K = map(int, input().split())
C = K - A
if A >= K:
  A -= K
  print(A, B)
else:
  A *= 0
  B -= C
  if B <= 0:
    B = 0
    print(A,B)
  else:
    B = B
    print(A,B)



Measured memory_bytes: 2940
board = []
for i in range(3):
  temp = list(map(int, input().split()))
  board.append(temp)
n = int(input())
TF = [[False] * 3 for i in range(3)]
for _ in range(n):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if board[i][j] == b:
        TF[i][j] = True
res = False
for i in range(3):
  res = res or (TF[i][0] and TF[i][1] and TF[i][2])
  res = res or (TF[0][i] and TF[1][i] and TF[2][i])
res = res or (TF[0][0] and TF[1][1] and TF[2][2])
res = res or (TF[0][2] and TF[1][1] and TF[2][0])
print('Yes' if res else 'No')

Measured memory_bytes: 9240
#include <cstdio>
#include <algorithm>

const int N = 2e5; 

int a[N + 5]; 

int main() {

    int n, m; 
    double ans = 0, mid = 0;

    scanf("%d%d", &n, &m); 
    for (int i = 1; i <= n; i ++) 
        scanf("%d", &a[i]);
    
    //std::sort(a + 1, a + n + 1); 

    int l = 1, r = 1; 
    while (r <= m) {
        ans += 1.0 * (a[r] + 1) / 2.0; 
        r ++; 
    }
    r --; 
    mid = ans; 

    while (r <= n) {
        ans = std::max(mid, ans); 
        mid -= 1.0 * (a[l ++] + 1) / 2.0;
        mid += 1.0 * (a[++ r] + 1) / 2.0; 
    } 

    printf("%f", ans);

    return 0; 
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::queue<int> que;
int N;
int A[1100][1100], C[1100];

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

  std::cin >> N;

  for(int i=1;i<=N;++i){
      for(int j=0;j<N-1;++j){
          std::cin >> A[i][j];
      }
  }

  for(int i=1;i<=N;++i){
      int j = A[i][0];
      if(A[j][0] == i){
          que.emplace(i);
      }
  }

  int days = 0;
  
  until(que.empty()){
      days += 1;
      
      std::set<int> s;

      until(que.empty()){
          int i = que.front();
          que.pop();

          C[i] += 1;
          s.emplace(i);
      }

      for(int i : s){
          if(C[i] >= N - 1){
              continue;
          }

          int j = A[i][C[i]];

          if(A[j][C[j]] == i){
              que.emplace(i);
              if(s.count(j) == 0){
                  que.emplace(j);
              }
          }
      }
  }

  for(int i=1;i<=N;++i){
      if(C[i] != N - 1){
          days = -1;
          break;
      }
  }

  std::cout << days << std::endl;
}


Measured memory_bytes: 4608
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      boolean[] hit = new boolean[9];
      int[] a = new int[9];
      for (int i = 0; i < 9; i++) a[i] = sc.nextInt();
      
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int b = sc.nextInt();
        for (int j = 0; j < 9; j++) {
          if (b == a[j]) hit[j] = true;
        }
      }

      int[][] lines = {
        { 0, 1, 2 },
        { 3, 4, 5 },
        { 6, 7, 8 },
        { 0, 3, 6 },
        { 1, 4, 7 },
        { 2, 5, 8 },
        { 0, 4, 8 },
        { 2, 4, 6 },
      };

      boolean ans = false;
      for (int i = 0; i < 8; i++) {
        boolean chk = true;
        for (int j = 0; j < 3; j++) {
          if (!hit[lines[i][j]]) chk = false;
        }
        if (chk) ans = true;
      }

      if (ans) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    } finally {
      sc.close();
    }
  }
}

Measured memory_bytes: 35684
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;


bool isValidNum(string s) {
	return s.length == 1 || s[0] != '0';
}

bool isValidEq(string s) {
	string l = s.split("+")[0];
	string r = s.split("+")[1].split("=")[0];
	string sum = s.split("+")[1].split("=")[1];
	return isValidNum(l) && isValidNum(r) && isValidNum(sum) && BigInt(l)+ BigInt(r) == BigInt(sum);
}

void main() {
	auto s = readln().strip();
	while(!s.empty()) {
		int i;
		while(i <= 9) {
			if(isValidEq(s.replace("X", to!string(i)))){
				writeln(i);
				break;
			}
			++i;
		}
		if(i > 9)
			writeln("NA");
		s = readln().strip();
	}
}

Measured memory_bytes: 1276
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll,P> T; 
const ll INF=2e18;
const ll MOD=1e9+7;

ll M;
ll pConcat[15]={0,2,4,6,8,1,3,5,7,9};
string result;
ll cnt=0;
void Compress(ll a,ll n){
    while(n>1){
        if(n%2==1){
            result+='0'+a;
        }
        if(a<=4){
            cnt+=n/2;
        }else{
            cnt+=(n/2)*2;
        }
        n/=2;
        a=pConcat[a];
    }
    result+='0'+a;
} 
int main(){
    cin>>M;
    ll sum;
    for(ll i=0;i<M;i++){
        ll d,c;
        cin>>d>>c;
        Compress(d,c);
    }
    while(result.length()>1){
        ll a=stoll(result.substr(result.length()-2,2));
        result.pop_back();
        result.pop_back();
        a=a/10+a%10;
        cnt++;
        if(a>9){
            a=a/10+a%10;
            cnt++;
        }
        result+=a+'0';
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 6404
#include<vector>
#include<map>
#include<climits>
#include<set>
#include<queue>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<bitset>
#include<cstring>
#include<list>
using namespace std;
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int,int>PII;
typedef long long LL;
typedef pair<LL,LL>PLL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define EACH(i,c) for(typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define F first
#define S second

int main(){
    double x;
    while(cin>>x,x>=0){
        double d=1<<7;
        string ans="";
        REP(i,8){
            if(x>=d){
                x-=d;
                ans+="1";
            }
            else ans+="0";

            d/=2;
        }
        ans+=".";
        REP(i,4){
            if(x>=d){
                x-=d;
                ans+="1";
            }
            else ans+="0";
            d/=2;
        }
        if(x==0)cout<<ans<<endl;
        else cout<<"NA"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    bool c = C >=A && C<=B;
    if(c) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int N,i,sum=0;
  cin >> N;
  int Num = N;
  while (Num>0) {
    sum += Num%10;
      Num /=10;
  }
  if (N%sum == 0)
    cout << "Yes";
  else
    cout <<"No";
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    int X, N;
    set<int> P;
    cin >> X >> N;
    for_(i,0,N) {
        int p;
        cin >> p;
        P.insert(p);
    }

    int ans = -1, mn = 1L << 30;
    for_(x,-1000,1001) {
        if (P.count(x)) continue;
        int v = abs(x - X);
        if (mn > v) {
            ans = x;
            mn = v;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    map<string, int> mp;
    while(t--){
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << '\n';
    cout << "WA x " << mp["WA"] << '\n';
    cout << "TLE x " << mp["TLE"] << '\n';
    cout << "RE x " << mp["RE"];


    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

#define MAX 251

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
int main(){
  
  int h,i;
  int A[MAX];
  
  // 入力
  scanf("%d",&h);
  for(i=1;i<=h;i++)
    scanf("%d",&A[i]);
  
  
  
  // 出力
  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i != 1) printf("parent key = %d, ",A[parent(i)]);
    if(h >= 2*i) printf("left key = %d, ",A[left(i)]);
    if(h >= 2*i+1) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ff first
#define ss second
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    setprecision(20);
    
    int a,b;
    cin>>a>>b;
    cout<<a*b;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

ll sum(ll a,ll b){
	return (b+a)*(b-a+1)/2;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for(int i=k;i<=n+1;++i){
		ll lim1=sum(0,1ll*i-1);
		//~ cout<<"2 num : "<<n+2-i<<" , "<<n+1<<endl;
		ll lim2=sum(n+1-i,n);
		//~ cout<<"#case "<<i<<" : "<<lim1<<" ~ "<<lim2<<endl;
		ans+=lim2-lim1+1;
		ans%=mod;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	as := make([]int, n)
	mx := -1
	mxIndex := -1
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &as[i])

		if mx < as[i] {
			mx = as[i]
			mxIndex = i
		}
	}

	half := mx / 2
	half2 := mx/2 + 1

	t := 0
	for i := 0; i < n; i++ {
		if i == mxIndex {
			continue
		}
		if abs(half-t) > abs(half-as[i]) {
			t = as[i]
		}
		if abs(half2-t) > abs(half2-as[i]) {
			t = as[i]
		}
	}

	fmt.Printf("%d %d", mx, t)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 998244353;
using mint = Fp<MOD>;
const int MAX=400000;
mint fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
        inv[i] = (mint)MOD - inv[MOD%i] * (MOD / i);
        finv[i] = finv[i - 1] * inv[i];
    }
}

mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    COMinit();
    mint ans=0;
    rep(i,n+1){
        if(k-i*a>=0&&(k-i*a)%b==0&&(k-i*a)/b<=n) ans+=COM(n,i)*COM(n,(k-i*a)/b);
    }
    cout<<ans;
}


Measured memory_bytes: 13016
package main

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

func main() {
	// 標準入力読み取り
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line := scanner.Text()
	n, _ := strconv.Atoi(line)

	votes := make(map[string]int)
	for i := 0; i < n; i++ {
		scanner.Scan()
		line = scanner.Text()
		votes[line]++
	}
	maxValue := 0
	words := []string{}
	for key, value := range votes {
		if maxValue < value {
			maxValue = value
			words = []string{key}
		} else if maxValue == value {
			words = append(words, key)
		}
	}

	sort.Strings(words)
	for _, word := range words {
		fmt.Println(word)
	}

}


Measured memory_bytes: 30848
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner s = new Scanner(System.in);

        int a = Integer.parseInt(s.next());
        int b = Integer.parseInt(s.next());
        int t = Integer.parseInt(s.next());
        s.close();

        System.out.println((t/a)*b);
    }

}


Measured memory_bytes: 21076
#include <stdio.h>
#include <string.h>

int main() {
    int i, l, n;
    char s[101];
    long long oocnt = 0, total_oocnt = 0;
    scanf("%d %d %s", &l, &n, s);

    for ( i=0; i<l-1; ++i ) {
	if ( s[i] == 'o' && s[i+1] == 'o' ) ++oocnt;
    }
    for ( i=0; i<n; ++i ) {
	total_oocnt += oocnt;
	oocnt *= 2;
    }

    printf("%lld\n", 3*total_oocnt + l);
    return 0;
}



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


int main() {
	long n,m,i,j,k,t,ans,cur,res;
	cin >> n;
	vector<long> p(0);
	p.push_back(1);
	p.push_back(n);
	for(i=2; i*i<=n; i++){
		if(n%i==0){
			p.push_back(i);
			if(i*i<n){
				p.push_back(n/i);
			}
		}
	}

	long a,b;
	sort(p.begin(),p.end());
	
	/*
	for(i=0; i<p.size(); i++){
		cout << p[i] << ' ';
	}
	cout << endl;
	*/
	for(i=0; i<p.size(); i++){
		cur=p[i];
		a=cur/2; b=a-cur;
		while(a*a*a*a*a-b*b*b*b*b<=n){
			if(a*a*a*a*a-b*b*b*b*b==n){
				cout << a << ' ' << b; return 0;
			}else{
				a++; b++;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#define MOD 1000000007LL

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

ll extgcd(ll a, ll b, ll& x, ll& y){
	ll d=a;
	if(b!=0){
		d=extgcd(b, a%b, y, x);
		y-=(a/b)*x;
	}else{
		x=1, y=0;
	}
	return d;
}
 
ll inv(ll a, ll p){
	ll x, y;
	extgcd(a, p, x, y);
	if(x<0){
		return p-(-x%p);
	}else{
		return x%p;
	}
}

vector<int> v[200001];
int d[200001], dmax;
vector<int> dist[200001];
int pp[200001];

void dfs(int x){
	for(auto y:v[x]){
		if(d[y]<0){
			d[y]=d[x]+1;
			dist[d[y]].push_back(y);
			dmax=max(d[y], dmax);
			dfs(y);
		}
	}
}

int p1;

void dfs2(int x){
	int ct=0;
	for(auto y:v[x]){
		if(d[y]>d[x]) ct++;
	}
	if(ct>1){
		for(auto y:v[x]){
			if(d[y]<d[x]) continue;
			p1=y;
			dfs2(y);
		}
	}
	if(ct==1){
		for(auto y:v[x]){
			if(d[y]<d[x]) continue;
			pp[y]=p1;
			dfs2(y);
		}
	}
}

map<int, vector<int> > g;

void dfs3(int x){
	bool e=0;
	if(g[pp[x]].empty()) e=1;
	g[pp[x]].push_back(x);
	if(e && pp[x]!=0) dfs3(pp[x]);
}

ll dfs4(int x){
	if(g[x].empty()){
		return 500000004;
	}
	ll sum=0, prod=1;
	for(auto y:g[x]){
		ll c=dfs4(y);
		sum+=(c*inv((MOD+1-c)%MOD, MOD)%MOD);
		sum%=MOD;
        prod*=(MOD+1-c);
        prod%=MOD;
	}
	return sum*prod%MOD;
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d", &pp[i]);
		v[i].push_back(pp[i]);
		v[pp[i]].push_back(i);
	}
	fill(d, d+n+1, -1);
	d[0]=0;
	dist[0].push_back(0);
	dfs(0);
	dfs2(0);
	ll p2=1;
	for(int i=0; i<=n; i++){
		p2*=2;
		p2%=MOD;
	}
	ll ans=0;
	for(int t=0; t<=dmax; t++){
		if(t==0){
			ans+=500000004;
			continue;
		}
		g.clear();
		for(auto x:dist[t]){
			dfs3(x);
		}
		ans+=dfs4(0);
		ans%=MOD;
	}
	ans*=p2;
	ans%=MOD;
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int n;
  bool is_prime[1000000];
  int count;

  while (1) {
    cin >> n;
    if (cin.eof()) break;
    for (int i=2; i<=n; i++) is_prime[i] = true;

    for (int i=2; i*i<=n; i++) {
      if (is_prime[i]) {
        for (int j=i+i; j<=n; j+=i) {
          is_prime[j] = false;
        }
      }
    }

    count = 0;
    for (int i=2; i<=n; i++) {
      if (is_prime[i]) count++;
    }

    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 2132
#include<iostream>

using namespace std;

int main(){

	char c;
	
	cin >> c;
	
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
		cout << "vowel";
	}else{
		cout << "consonant";
	}


	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++) 
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = (s.size()-1)/2;

    rep(i, n) {
        if (s[i] != s[s.size()-i-1]) {
            cout << "No" << endl;
            //cout << "oh" << endl;
            return 0;
        }
    }
    rep(i, n/2) {
        if (s[i] != s[(s.size()-1)/2-1-i]) {
            cout << "No" << endl;
            //cout << "ohs" << endl;
            return 0;
        }
    }
    int j = 0;
    int last = (s.size()+3)/2-1;
    for (int i = last; i < (s.size()-last-1)/2; i++) {
        if (s[i] != s[s.size()-1-j]) {
            cout << "No" << endl;
            return 0;
        }
        j--;
    }
    cout << "Yes" << endl;
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
#define INT_MAX 10000000

int n,a[MAX][MAX],sum=0,cost[MAX],color[MAX],pi[MAX];

void prim(int );

int main(){
  int i,j;

  scanf("%d",&n);

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

  prim(0);

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

  return 0;
}

void prim(int r){
  int u,v,i;
  for(i=0;i<n;i++){
    cost[i]=INT_MAX;
    color[i]=0;
  }

  cost[r]=0;
  pi[r]=-1;

  while(1){
    int mincost=INT_MAX;
    int u,v;

    for(i=0;i<n;i++){
      if(color[i]!=1 && cost[i]<mincost){
	mincost=cost[i];
	u=i;
      }
    }

    if(mincost==INT_MAX) break;

    color[u]=1;

    for(v=0;v<n;v++){
      if(color[v]!=1 && a[u][v]<cost[v] && a[u][v]!=-1){
	pi[v]=u;
	cost[v]=a[u][v];
	
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i]!=-1) sum+=a[i][pi[i]];
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define db double
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353

const ll N=1e12;

int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}

ll solve(){
    ll a;
    cin>>a;
    vi v(2*a,0);
    rep(i,0,2*a) cin>>v[i];
    sort(all(v));
    cout<<v[a+1]-v[a]<<"\n";
    return 0;
}

signed main(){
    IOS
// 	#ifndef ONLINE_JUDGE
//     	freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	#endif
    ll n;
    cin>>n;
    vector<char> v(n,0);
    ll w=0,r=0;
    rep(i,0,n){
      cin>>v[i];
      if(v[i]=='W') w++;
      else r++;
    }
    if(r==0||w==0) cout<<"0";
    else{
        ll a=0;
        repn(i,n-1,0){
            if(v[i]=='R'){
          	    auto it=find(all(v),'W');
        	    ll j=it-v.begin();
        	    if(j<i){
                    char c=v[i];
                    v[i]=v[j];
                    v[j]=c;
                    a++;
                }
          	    else break;
            }
        }
        cout<<a;
  }
    return 0;
}
// size_t f= str.find(string s,0); find s in str from start
// if found then (f != string::npos)
// m.insert({x,y}); m[x]=y;

Measured memory_bytes: 3596
#include <iostream>

int main(){
    int n, r;
    std::cin >> n >> r;

    if (n >= 10)
    {
        std::cout << r << std::endl;
    }
    else
    {
        std::cout << r + 100 * (10 - n) <<std::endl;
    }

    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) {if (b<a) {a=b; return 1;} return 0;}

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans;
    rep(i, n) {
        if (p[i] == i+1) {
            if (i == n-1) swap(p[i-1], p[i]);
            else swap(p[i], p[i+1]);
            ans++;
        }
        // rep(i, n) printf("%d%c", p[i], i == n-1 ? '\n' : ' ');
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int total,alice,borys;
    scanf("%d %d %d",&total,&alice,&borys);
    if((borys-alice)%2==0)
        printf("Alice");
    else if((borys-alice)%2!=0)
        printf("Borys");
    return 0;
}


Measured memory_bytes: 1732
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: June 4 2019
 * 
 */

#include <bits/stdc++.h>

//#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    int a , b;

    cin>>a>>b;

    int sum = 0;

    if(a>b){
        sum+=a--;
        cout<<sum+(max(a,b))<<endl;
    }else{
        sum+=b--;
        cout<<sum+(max(a,b))<<endl;
    }

    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("ain","r",stdin);
    freopen("aout","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;



int main(){
    string s;
    stack <ll> st;
    while(cin >> s){
        if(s[0] == '+' || s[0] == '-' || s[0] == '*'){
            int a,b;
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            if(s[0] == '+'){
                st.push(a+b);
            }else if(s[0] == '-'){
                st.push(b-a);
            }else{
                st.push(a*b);
            }
        }else{
            int c = stoi(s);
            st.push(c);
        }
    }
    cout << st.top() << endl;


}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()
{
    fastio;
    long long n,i,j,sum=0,mul=0;
    long long M=1000000007;
    static long long ara[200003];
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    for(i=n-2;i>=0;i--)
    {
        sum=((sum%M)+(ara[i+1]%M))%M;
        mul=((mul%M)+((ara[i]%M)*(sum%M))%M)%M;
    }
    cout<<mul<<"\n";
    return 0;
}

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


int main(){
    ll N;cin>>N;
    if(N==1||N==2){
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    for(ll i=1;i*(i+1)<N;i++){
        if(N%i==0)ans+=N/i-1;
    }
    cout<<ans<<endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

const int INF = 1001001001;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    vector<int> dp(N, INF);
    dp[0] = 0;
    rep(i, N) {
        rrepSE(j, i, max(-1,i-K-1)) {
            chmin(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[N-1] << "\n";
    return 0;
}


Measured memory_bytes: 1024