akhauriyash/Code-Regression huggingface dataset:
n=input()
n1=int (n)
if n1/100>=1:
    if  n[2]=='2' or n[2]=='4' or n[2]=='5' or n[2]=='7' or n[2]=='9':
        print("hon")
    elif n[2]=='0' or n[2]=='1' or n[2]=='6' or n[2]=='8':
        print("pon")
    else:
        print("bon")

elif n1/10>=1:
    if  n[1]=='2' or n[1]=='4' or n[1]=='5' or n[1]=='7' or n[1]=='9':
        print("hon")
    elif n[1]=='0' or n[1]=='1' or n[1]=='6' or n[1]=='8':
        print("pon")
    else:
        print("bon")

else:
    if  n[0]=='2' or n[0]=='4' or n[0]=='5' or n[0]=='7' or n[0]=='9':
        print("hon")
    elif n[0]=='0' or n[0]=='1' or n[0]=='6' or n[0]=='8':
        print("pon")
    else:
        print("bon")

        

Measured memory_bytes: 9268
h, w, a, b = map(int, input().split())
###############
# 二項係数テンプレート
# 出力制限
mod = 10 ** 9 + 7
MAX_N = 2 * 10 ** 5
factorial = [1] * MAX_N
#事前に階乗テーブルを用意
def calc_factorial():
    for i in range(1, MAX_N):
        factorial[i] = i * factorial[i - 1] % mod

def comb(n, k):
    a = factorial[n] % mod
    b = (factorial[k] * factorial[n - k]) % mod
    b_ = pow(b, mod - 2, mod)
    return (a * b_) % mod


# 階乗を用意
calc_factorial()
#########

# 全体の組み合わせを計算する
# h-1(高さ)+w-1(横幅)から、h-1(高さ)個取り出す組み合わせ
all = comb(h + w - 2, h - 1)
sub = 0
for j in range(1, b + 1):
    sub += comb(h - a - 1 + j - 1, j - 1) * comb(a - 1 + w - j, w - j)
    sub = sub % mod
if all - sub <= 0:
    print(all - sub + mod)
else:
    print(all - sub)

Measured memory_bytes: 10868
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A, B, C = rl()

if len(set([A,B,C])) == 2:
	print('Yes')
else:
	print('No')


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

int main()
{
    int number[100];
    int i;
    
    cin >> i;
    for (int j = 0; j < i; j++) {
        cin >> number[j];
    }
    
    for(int j = 0; j < i; j++) {
        if (number[j] % 2) {
          //何も実行せず
        } else if( (number[j] % 3) && (number[j] % 5)) {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
s = input()
n = len(s)

ans = 0

for bit in range(2 ** (n - 1)):
    f = s[0]

    for i in range(n - 1):
        if bit & (1 << i):
            f += "+"
        f += s[i + 1]

    ans += sum(map(int, f.split("+")))

print(ans)

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

int main(){
	char str[11];
	int leng = 0, length = 0;
	cin >> str;
	for(int i = 0; i < 10; i++){
		if(str[i] == 'A' || str[i] == 'T' || str[i] == 'G' || str[i] == 'C'){
			if(i > 0){
				if(str[i-1] == 'A' || str[i-1] == 'T' || str[i-1] == 'G' || str[i-1] == 'C') leng++;
				else leng = 1;
			}
			else leng = 1;
		}
		if(leng > length) length = leng;
	}
	cout << length << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
ary = []
n.times do
    suit, number = gets.chomp.split(' ')
    ary.push([suit, number.to_i])
end

def partition(ary, p, r)
    x = ary[r][1]
    i = p - 1
    p.upto(r - 1) do |j|
        if ary[j][1] <= x then
            i += 1
            tmp = ary[i]
            ary[i] = ary[j]
            ary[j] = tmp
        end
    end
    tmp = ary[i + 1]
    ary[i + 1] = ary[r]
    ary[r] = tmp
    return i + 1
end

def quickSort(ary, p, r)
    if p < r then
        q = partition(ary, p, r)
        quickSort(ary, p, q - 1)
        quickSort(ary, q + 1, r)
    end
end

INF = 10 ** 9 + 5
def merge(aAry, left, mid, right)
    n1 = mid - left
    n2 = right - mid
    lAry = aAry[left, n1]
    rAry = aAry[mid, n2]
    lAry[n1] = ["Z", INF]
    rAry[n2] = ["Z", INF]
    i = 0
    j = 0
    # puts "lAry = #{lAry}, rAry = #{rAry}, left = #{left}, right = #{right}"
    (left..(right - 1)).each do |k|
        if lAry[i][1] <= rAry[j][1] then
            aAry[k] = lAry[i]
            i += 1
        else
            aAry[k] = rAry[j]
            j += 1
        end
    end
end

def mergeSort(aAry, left, right)
    if left + 1 < right then
        mid = (left + right) / 2
        mergeSort(aAry, left, mid)
        mergeSort(aAry, mid, right)
        merge(aAry, left, mid, right)
    end
end

stablySortedAry = Marshal.load(Marshal.dump(ary))
mergeSort(stablySortedAry, 0, stablySortedAry.size)
# p stablySortedAry

quickSort(ary, 0, ary.size - 1)
# p ary

puts ary == stablySortedAry ? "Stable" : "Not stable"
ary.each { |e| puts e.join(' ')}



Measured memory_bytes: 47928
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

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

    vector<long long> sum_a(N,0);
    long long ans=0;
    vector<long long> a(N,0);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }

    for(int i=0; i<N; i++){
        if(i==0){
            sum_a[i]=a[i];
        }else{
            sum_a[i]=sum_a[i-1]+a[i];
        }

        if(i%2==0 && sum_a[i]<=0){
            ans+=-sum_a[i]+1;
            sum_a[i]=1;
        }else if(i%2==1 && sum_a[i]>=0){
            ans+=sum_a[i]+1;
            sum_a[i]=-1;
        }
    }
    long long tmp=0;;
    for(int i=0; i<N; i++){
        if(i==0){
            sum_a[i]=a[i];
        }else{
            sum_a[i]=sum_a[i-1]+a[i];
        }

        if(i%2==0 && sum_a[i]>=0){
            tmp+=sum_a[i]+1;
            sum_a[i]=-1;
        }else if(i%2==1 && sum_a[i]<=0){
            tmp+=-sum_a[i]+1;
            sum_a[i]=1;
        }
    }

    cout << min(tmp,ans) << endl;
}

Measured memory_bytes: 1792
N=int(input())
L=list(map(int,input().split()))
L.sort()

ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            a,b,c=L[i],L[j],L[k]
            if a!=b and b!=c and a+b>c:
                ans+=1

print(ans)


Measured memory_bytes: 9100
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n=int(input())
    for i in range(10):
        for j in range(10):
            if i*j==n:
                print("Yes")
                exit()
    print("No")
if __name__ == '__main__':
    main()

Measured memory_bytes: 5736
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="SUN"){
    cout << "7" << endl;
  }
  else if(s=="MON"){
    cout << "6" << endl;
  }
  else if(s=="TUE"){
    cout << "5" << endl;
  }
  else if(s=="WED"){
    cout << "4" << endl;
  }
  else if(s=="THU"){
    cout << "3" << endl;
  }
  else if(s=="FRI"){
    cout << "2" << endl;
  }
  else{
    cout << "1" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main () 
{
    ll a,b,c,d,count=1;cin>>a>>b>>c>>d;
    while (a>0&&c>0) {
        if (count%2!=0)c=c-b;
        else a=a-d;
        count++;
    }
    if (a<=0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
 
}

Measured memory_bytes: 3620
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class TaskD {
 public:
  void solveOne(istream &in, ostream &out) {
    int n;
    int modulo;
    in >> n >> modulo;
    vector<vector<int>> ways(3 * n + 1, vector<int>(n + 1, 0));
    ways[0][0] = 1;
    for (int len = 1; len <= 3 * n; ++len) {
      for (int block = 1; block <= len && block <= 3; ++block) {
        int64 cw = 1;
        for (int i = 0; i < block - 1; ++i) {
          cw = cw * (len - i - 1) % modulo;
        }
        int delta = block >= 2 ? 1 : 0;
        for (int balance = delta; balance <= n; ++balance) {
          ways[len][balance] = (ways[len][balance] + ways[len - block][balance - delta] * cw) % modulo;
        }
      }
    }
    int64 res = 0;
    for (int x : ways[3 * n]) res += x;
    res %= modulo;
    out << res << "\n";
  }

  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int it = 0; it < nt; ++it) {
      solveOne(in, out);
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  TaskD solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 47488
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;
vector<P> v;

int main() {

    int N, M; cin >> N >> M;
    int a, b;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        v.push_back(make_pair(b, a));
    }

    sort(v.begin(), v.end());

    int ans = 0;
    int l = -1;
    for (int i = 0; i < v.size(); i++) {
        if (l <= v[i].second) {
            ans++;
            l = v[i].first;
        }
    }

    cout << ans << '\n';
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &i : a) cin >> i;
	for (auto &i : a) { int x; cin >> x; i -= x; }

	int ans = 0;
	for (auto i : a)
		ans += (i>0)*i;

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
/* Author: Dhruv Rastogi */
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<ctime>
#include<string>
#include<random>
#include<ctime>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

const int N=1e2+4;
int ps[N];
void solve(){
	int n;
	cin>>n;
	rep(i,1,n+1){
		int x;
		cin>>x;
		ps[i]=ps[i-1]+x;
	}  
	int ans=hell;
	rep(i,1,n+1){
		int s1=ps[i];
		int s2=ps[n]-ps[i];
		ans=min(ans,abs(s1-s2));
	}
	cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<u32>();
    let n = v[0];
    let m = v[1];

    let a = read_vec2::<u32>(n);
    let b = (0..m).map(|_| read::<u32>()).collect::<Vec<u32>>();

    for i in 0..(n as usize) {
        let s = a[i].iter().enumerate().map(|(j, &num)| num * b[j]).sum::<u32>();
        println!("{}", s);
    }
}



Measured memory_bytes: 5048
R = ((1,2,4,3),(2,0,3,5),(0,1,5,4))
f = input().split()

for i in range(int(input())):
    t, s = map(f.index, input().split())
    for j in R:
        if not (t in j)*(s in j):
            continue
        d = R.index(j)
        if (j.index(t) - j.index(s)) %4 == 1:
            d -= 5
    print(f[abs(d)])

Measured memory_bytes: 7676
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
#define INF 1e9;
#define LINF 1e18;
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;}
const string YES = "Yes";
const string NO = "No";
// clang-format on

void solve(long long N, std::vector<long long> a) {
  ll b1 = 0, b2 = 0, b4 = 0;
  rep(i, N) {
    if (a[i] % 2 != 0)
      b1++;
    else if (a[i] % 4 != 0)
      b2++;
    else
      b4++;
  }
  if (b2 == 0) {
    ANS((b1 <= b4 + 1 ? YES : NO));
  } else {
    ANS((b1 <= b4 ? YES : NO));
  }
}

// clang-format off
int main() {
  long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

const int N=200005;

struct node{
	int x,y;
	node(){}
	node(int x,int y):x(x),y(y){}
}a[N];
int n,x,y,S,T,cnt,rt,ans,z;
int dep[N],vis[N],dis[N],fa[N],in[N],ot[N],tag[N];
vector<int> lv1[N],lv2[N];
queue<int> q;

void dfs2(int k,int pre){
	int j,u;
	in[k]=++cnt;
	for (j=0;j<lv2[k].size();j++){
		u=lv2[k][j];
		if (u==pre) continue;
		dep[u]=dep[k]+1; fa[u]=k;
		dfs2(u,k);
	}
	ot[k]=++cnt;
}

bool check(int x,int y){
	if (in[x]>in[y]) swap(x,y);
	if (in[x]<in[y]&&ot[x]>in[y]) return (dep[y]-dep[x]>2);
	if (fa[x]==fa[y]) return 0;
	return 1;
}

void bfs(){
	int j,k,u;
	q.push(S); vis[S]=1;
	while (!q.empty()){
		k=q.front(); q.pop();
		for (j=0;j<lv1[k].size();j++){
			u=lv1[k][j];
			if (!vis[u]&&dis[k]+1<dep[u]){
				dis[u]=dis[k]+1;
				vis[u]=1;
				q.push(u);
			}
		}
	}
}

int main(){
	int i;
	scanf("%d%d%d",&n,&S,&T);
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		a[i]=node(x,y);
	}
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		lv2[x].push_back(y);
		lv2[y].push_back(x);
	}
	dfs2(T,0);
	for (i=1;i<n;i++){
		if (check(a[i].x,a[i].y)) tag[a[i].x]=tag[a[i].y]=1;
		else{
			lv1[a[i].x].push_back(a[i].y);
			lv1[a[i].y].push_back(a[i].x);
		}
	}
	bfs();
	for (i=1;i<=n;i++)
		if (tag[i]&&vis[i]){
			printf("-1\n");
			return 0;
		}
	for (i=1;i<=n;i++)
		if (vis[i]) ans=max(ans,dep[i]*2);
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    int n;
    ll H[110000];
    int ans=0;
    int sum=0;
    cin >> n;
    rep(i,n) cin >> H[i];

    for(int i=1; i<n; i++){
        if(H[i-1]>=H[i]){
            sum++;
            if(ans<sum){
                ans = sum;
            }
        }else{
            sum=0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int n;
vector<int>a;
int am = 0, am1 = 0;

int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ai;
		cin >> ai;
		a.push_back(ai);
		if (ai >= am) {
			am1 = am;
			am = ai;
		}
		else if (ai > am1)
			am1 = ai;
	}

	for (int i = 0; i < n; i++) {
		int ret;
		if (a[i] < am)
			ret = am;
		else
			ret = am1;
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 2548
using System;
using System.Linq;

namespace AOJ.Volume2
{
    public class Thanksgiving
    {
        public static int Main()
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                int n = int.Parse(input[0]);
                int m = int.Parse(input[1]);
                if (n == 0) { break; }

                input = Console.ReadLine().Split(' ');
                int[] price = new int[n];
                for(int i = 0; i < n; i++) { price[i] = int.Parse(input[i]); }

                // ?????????????????????????????????????????????m???????????????
                int answer = 0;
                int counter = 1;
                foreach(int i in price.OrderByDescending(x => x))
                {
                    if (counter == m) { counter = 1; }
                    else
                    {
                        answer += i;
                        counter++;
                    }
                }

                Console.WriteLine(answer);
            }
            return 0;
        }
    }
}

Measured memory_bytes: 10300
readlines.map(&:to_f).each{|q|
  break if q == -1
  x = q / 2.0
  x2 = x*x
  x3 = x*x2
  loop do
    break if (x3 - q).abs < 0.00001 * q
    x -=  (x3 - q)/(3.0*x2)
    x2 = x*x
    x3 = x*x2
  end
  puts "%.8f" % x
}

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

using namespace std;

int main() {

        string s;
        int len;
        int count;

        cin >>s;
        len = s.size();
        count = 0;
        for (int i =0; i < len /2; ++i) {
            if (s[i] == s[len - i - 1]) {
                ;
            } else {
                count = count + 1;
            }
        }
        cout << count << endl;
      return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n;
int niz[200005];
unordered_map<int,int>poj;
ll res = 0;



int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    ff(i,1,n){
        cin >> niz[i];
        if(poj.find(i-niz[i]) != poj.end())res += poj[i-niz[i]];
        poj[niz[i]+i]++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 12144
#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>;

int A, B;

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

  std::cin >> A >> B;

  int lb = 10 * B, ub = lb + 10;
  int res = -1;

  for(int i=lb;i<ub;++i){
      if(i * 8 / 100 == A && res == -1){
          res = i;
      }
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;


void solve() {
	char S[30] = {};
	scanf("%s", S);
	int n = (int)strlen(S);
	if(n < 26) {
		int chk[30] = {};
		for(int i=0;i<n;i++) chk[S[i]-'a'] = 1;
		int f = 0;
		while(chk[f] == 1) ++f;
		S[n++] = f + 'a';
		printf("%s\n", S);
	}
	else {
		if(is_sorted(S, S+n, greater<int>())) puts("-1");
		else {
			char T[30];
			rep(i, 26) T[i] = S[i];
			next_permutation(S, S+n);
			rep(i, 26) {
				printf("%c", S[i]);
				if(T[i] != S[i]) break;
			}
			puts("");
		}
	}
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 764
n = int(input())
a = [list(map(int,input().split())) for i in range(2)]
s = []
for i in range(n):
    if i == 0:
        s.append(a[0][0]+sum(a[1]))
    else:
        s.append(sum(a[0][:i])+sum(a[1][i-1:]))
print(max(s))


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = a+b;
    int r = c+d;

    if(l > r) {
        cout << "Left";
    }
    else if(l < r) {
        cout << "Right";
    }
    else {
        cout << "Balanced";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define N 10
using namespace std;

int n;
int x[11],y[11];

int check(int,int,int);
int solve(int a,int px,int py){
	// cout<<"solve..."<<a<<" "<<px<<" "<<py<<endl;
	int l=0;
	if(!(0<=px&&px<N&&0<=py&&py<N))return 0;
	if(a==n-1) return 1;
	if(check(a+1,px+2,py+1))l|=solve(a+1,px+2,py+1);
	if(l==1)return 1;
	if(check(a+1,px+2,py))l|=solve(a+1,px+2,py);
	if(l==1)return 1;
	if(check(a+1,px+2,py-1))l|=solve(a+1,px+2,py-1);
	if(l==1)return 1;
	if(check(a+1,px-2,py+1))l|=solve(a+1,px-2,py+1);
	if(l==1)return 1;
	if(check(a+1,px-2,py))l|=solve(a+1,px-2,py);
	if(l==1)return 1;
	if(check(a+1,px-2,py-1))l|=solve(a+1,px-2,py-1);
	if(l==1)return 1;
	if(check(a+1,px+1,py+2))l|=solve(a+1,px+1,py+2);
	if(l==1)return 1;
	if(check(a+1,px,py+2))l|=solve(a+1,px,py+2);
	if(l==1)return 1;
	if(check(a+1,px-1,py+2))l|=solve(a+1,px-1,py+2);
	if(l==1)return 1;
	if(check(a+1,px+1,py-2))l|=solve(a+1,px+1,py-2);
	if(l==1)return 1;
	if(check(a+1,px,py-2))l|=solve(a+1,px,py-2);
	if(l==1)return 1;
	if(check(a+1,px-1,py-2))l|=solve(a+1,px-1,py-2);
	if(l==1)return 1;
	return 0;
}

int check(int sn,int i,int j){
	if(!(0<=i&&i<N&&0<=j&&j<N))return 0;
	if(i==x[sn]&&j==y[sn])return 1;
	if(i==x[sn]+1&&j==y[sn])return 1;
	if(i==x[sn]+1&&j==y[sn]+1)return 1;
	if(i==x[sn]+1&&j==y[sn]-1)return 1;
	if(i==x[sn]-1&&j==y[sn])return 1;
	if(i==x[sn]-1&&j==y[sn]+1)return 1;
	if(i==x[sn]-1&&j==y[sn]-1)return 1;
	if(i==x[sn]&&j==y[sn]+1)return 1;
	if(i==x[sn]&&j==y[sn]-1)return 1;
	return 0;
}

int main(void){
	int px,py;
	while(cin>>px>>py,px||py){
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>x[i]>>y[i];
		}
		if(solve(-1,px,py)==1)cout<<"OK"<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int n,s;cin>>n>>s;s/=1000;
	int x=-1,y=0;
	while(true){
		int t=s-n-4*y;
		if(t<0) break;
		if(t%9==0) {x=t/9;break;}
		y++;
	}
	if(x==-1||n-x-y<0) cout<<-1<<' '<<-1<<' '<<-1<<endl;
	else cout<<x<<' '<<y<<' '<<n-x-y<<endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
MOD = 10**9 + 7
def comb(n, k, mod):
    if n<0 or k<0 or n<k:
        return 0
    if n==0 or k==0:
        return 1
    k=k if k<=n-k else n-k
    x = 1
    y = 1
    for i in range(k):
        x=x*(n-i)%mod
        y=y*(i+1)%mod
    return (x*pow(y,mod-2,mod))%mod
n,a,b = map(int,input().split())
A = comb(n,a,MOD)
B = comb(n,b,MOD)
C = pow(2,n,MOD)
ans = C -A-B-1
print(ans%MOD)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int a[200005];
	int current=1;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	int count=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==current)
		{
			current++;
		}
		else
		{
			count++;
		}
	}
	if(count==n)printf("-1\n");
	else
	printf("%d\n",count);
	return 0;
}



Measured memory_bytes: 896
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
    long n = long.Parse(Console.ReadLine());
    for(long i = 0; i < n; i++)
    {
		  long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      long vecXa = nums[2] - nums[0];
      long vecYa = nums[3] - nums[1];
      long vecXb = nums[6] - nums[4];
      long vecYb = nums[7] - nums[5];
      long dotNum = vecXa*vecXb + vecYa*vecYb;
      if(dotNum == 0) Console.WriteLine(1);
      else if(vecXa*vecYb == vecYa*vecXb) Console.WriteLine(2);
      else Console.WriteLine(0);
    }
	}
}


Measured memory_bytes: 17988
#include <iostream>
#include <string>

int main(){
	std::string str;
	std::cin >> str;
	for(int i = 0;i < 3;i++){
		if(str[i] == '1'){
			std::cout << '9';
		}else{
			std::cout <<'1';
		}
	}
	std::cout << '\n';
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) {
		if (b != c)
			cout << "2" << "\n";
		if (b == c)
			cout << "1" << "\n";
	}
	else if (b == c)
		cout << "2" << "\n";
	else if (a == c)
		cout << "2" << "\n";
	else
		cout << "3" << "\n";
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll m = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(a[i] > m) m = a[i];
        ans += m - a[i];
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
#define debug(x) cout << #x << ": " << (x) << endl
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define INF ((1 << 16)-1)
#define MOD (1000000007)
#define print(arr, n) REP(i, n) cout << arr[i] << " ";
struct PreMain {PreMain(){std::cin.tie(0);ios::sync_with_stdio(false);}} premain;

int train_map[501][501];
int cumsum[501][501];


int main() {
#ifdef LOCAL
    std::ifstream in("../arg.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N, M, Q;
    cin >> N >> M >> Q;

    int l, r;
    REP(i, M) {
        cin >> l >> r;
        train_map[l][r] += 1;
    }

    REPN(i, 1, N + 1) {
        REPN(j, 1, N + 1) {
            cumsum[i][j] = train_map[i][j] + cumsum[i][j - 1] + cumsum[i - 1][j] - cumsum[i - 1][j - 1];
        }
    }

    int p, q;
    REP(i, Q) {
        cin >> p >> q;
        cout << (cumsum[q][q] - cumsum[p - 1][q]) << endl;

    }

    return 0;
}




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

#define MOD (1.0e9 + 7)

using namespace std;

vector<int> g[300000];

bool findR(vector<int> &v,int dst)
{
    for(int i = 0;i < v.size();i++)
	if(v[i] == dst)
	    return true;

    return false;
}

int main(void)
{
    int dst,m;
    
    cin>>dst;
    cin>>m;

    for(int i = 0;i < m;i++)
    {
	int src,dst;
	cin>>src>>dst;

	g[src].push_back(dst);
	g[dst].push_back(src);
    }

    bool flag = false;
    
    for(int i = 0;i < g[1].size();i++)
    {
	if(findR(g[g[1][i]],dst))
	    flag = true;
    }

    if(flag)
	cout<<"POSSIBLE"<<endl;
    else
	cout<<"IMPOSSIBLE"<<endl;

    return 0;
}



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

int main(void) {
	int n;
	cin >> n;
	if (n == 1){
		cout << "Hello World\n";
	} else if (n == 2) {
		int a, b;
		cin >> a >> b;
		cout << a + b << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {

  // u: from
  // v: to
  case class Edge(u: Int, v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // ここ、0オリジン化した方がいい
    val edges = IndexedSeq.fill(n-1)(Edge(sc.nextInt(), sc.nextInt(), sc.nextInt()))
    (n, edges)
  }

  def solve(n:Int, edges:IndexedSeq[Edge]): IndexedSeq[Int] = {
    val nextList = IndexedSeq.fill(n+1)(ArrayBuffer.empty[Edge])
    for(edge <- edges){
      val from = edge.u
      val to = edge.v
      nextList(from).append(edge)
      nextList(to).append(Edge(to, from, edge.w))
    }
    val visited = Array.fill(n+1)(false)
    // 1から
    visited(1) = true
    val open: java.util.Queue[Int] = new java.util.ArrayDeque[Int]()
    //add, remove
    open.add(1)
    //白:false ,黒:true
    val colors = Array.fill(n+1)(true)
    colors(1) = false


    while(!open.isEmpty){
      val current = open.remove()
      for(edge <- nextList(current)){
        val next = edge.v
        if(!visited(next)) {
          val w = edge.w
          if (w % 2 == 0) {
            colors(next) = colors(current)
          } else {
            colors(next) = !colors(current)
          }
          visited(next) = true
          open.add(next)
        }
      }
    }
    colors.takeRight(n).map(p => if(p) 1 else 0)
  }

  def output1(result: IndexedSeq[Int]) = {
    result.foreach(println)
  }

  def output2(result: IndexedSeq[Int]) = {
    result.foreach(System.out.println)
  }

  def output3(result: IndexedSeq[Int]) = {
    val out = new java.io.PrintWriter(System.out)
    result.foreach(out.println)
    out.flush()
  }

  def main(args: Array[String]): Unit = {
    val (n, edges) = read()
    output1(solve(n,edges))
  }
}

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

const int MAX_V=100;
const int INF=1001001001;
int S,T;
struct edge{
    int to,cap,cost,rev;
    edge(int to,int cap,int cost,int rev)
        :to(to),cap(cap),cost(cost),rev(rev){}
};

int V;
vector<edge>G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
    int res=0;
    while(f>0){
        fill_n(dist,V,INF);
        dist[s]=0;
        bool update=true;
        while(update){
            update=false;
            for(int v=0;v<V;v++){
                if(dist[v]==INF)continue;
                for(int i=0;i<G[v].size();i++){
                    edge &e=G[v][i];
                    if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
                        dist[e.to]=dist[v]+e.cost;
                        prevv[e.to]=v;
                        preve[e.to]=i;
                        update=true;
                    }
                }
            }
        }

        if(dist[t]==INF)return INF;

        int d=f;
        for(int v=t;v!=s;v=prevv[v]){
            d=min(d,G[prevv[v]][preve[v]].cap);
        }
        f-=d;
        res+=d*dist[t];
        for(int v=t;v!=s;v=prevv[v]){
            edge &e=G[prevv[v]][preve[v]];
            e.cap-=d;
            G[v][e.rev].cap+=d;
        }
    }
    return res;
}

void init(){
    fill_n(G,MAX_V,vector<edge>());
}

int main(){
    V=100;
    int M,W;
    while(scanf("%d%d",&M,&W),M||W){
        init();
        vector<int>bm(M),bw(W);
        for(int i=0;i<M;i++)scanf("%d",&bm[i]);
        for(int i=0;i<W;i++)scanf("%d",&bw[i]);


        S=98,T=99;
        for(int i=0;i<M;i++){
            for(int j=0;j<W;j++){
                int ab=abs(bm[i]-bw[j]);
                int val=ab*(ab-30)*(ab-30);
                add_edge(i,M+j,1,-val);
            }
        }

        for(int i=0;i<M;i++){
            add_edge(S,i,1,0);
        }
        for(int i=0;i<W;i++){
            add_edge(i+M,T,1,0);
        }

        cout<<-min_cost_flow(S,T,min(M,W))<<endl;

    }
    return 0;
}

Measured memory_bytes: 1224
n = int(input())
g = [[-1] * n for _ in range(n)]  # Graph for testimonies.
for i in range(n):
    m = int(input())
    for _ in range(m):
        x, y = [int(z) for z in input().split()]
        x -= 1  # Zero-indexed.
        g[i][x] = y  # Person i says that person x is honest or not.

ans = set()
for bb in range(2 ** n):
    tmp = [0] * n
    possible = True
    for shift in range(n):
        if bb >> shift & 1:
            tmp[shift] = 1  # Assumes person i is honest or not.
    for i, j in enumerate(tmp):
        if j:  # Assumed honest.
            for k in range(n):
                if g[i][k] == -1:
                    # No testimony.
                    continue
                if g[i][k] != tmp[k]:
                    # Contradiction!
                    possible = False
    if possible:
        ans.add(bin(bb).count('1'))

print(max(ans))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <set>
#include <bitset>
#include <queue>


#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, 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(a > b) { a=b; return 1; }return 0;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;


int main() {
    // int N; cin >> N;
    string s; cin >> s;
    // int N, M; cin >> N >> M;
    string res = "Yes";
    int cnt = 0;
    rep (i,4) {
        rep (j,4) {
            if(s[i]==s[j]) cnt++;
        }
    }
    if(cnt != 8) res = "No";
    cout << res << endl;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = intScanner()
	}
	xs := []int{as[0]}
	for j := 1; j < n; j++ {
		idx := sort.Search(len(xs), func(i int) bool { return xs[i] < as[j] })
		if idx == len(xs) {
			xs = append(xs, as[j])
		} else {
			xs[idx] = as[j]
		}
	}
	fmt.Println(len(xs))
}


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

using namespace std;
typedef long long ll;

int main(int, char**)
{
	string s;
	stack<char> n;
	int ans = 0;
	cin >> s;

	for (int i = 0; i < s.length(); i++) {
		if (n.empty()) {
			n.push(s[i]);
			continue;
		}
		if (n.top() != s[i]) {
			ans += 2;
			n.pop();
		} else {
			n.push(s[i]);
		}
	}

	cout <<  ans << endl;
	return 0;
}


Measured memory_bytes: 512
package main

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

var counter int = 0

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	txt := scanner.Text()

	txtSlixe := strings.Split(txt, "")

	for idx, val := range txtSlixe {
		if idx%2 == 0 {
			if val == "R" || val == "U" || val == "D" {
				continue
			} else {
				counter += 1
			}
		} else {
			if val == "L" || val == "U" || val == "D" {
				continue
			} else {
				counter += 1
			}
		}
	}

	if counter == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int x = 0;
  for (int i = 0; i < N; i++) {
    if (p.at(i) != i + 1) {
      x++;
    }
  }
  if (x > 2) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define inf 1000000000000000
using ll = long long;
using namespace std;

ll n, m, x, ans = -1;
// tree height
ll h[100005] = {0};
// from i to first (dictnace:second)
vector<pair<ll, ll>> edge[100005];
// now time point
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>,
               greater<pair<ll, ll>>>
    pq;
// now time height
pair<ll, ll> memo[100005], now, nextn;

bool cmp(pair<ll, ll> l, pair<ll, ll> r) {
  if(l.fi < r.fi)
    return 1;
  else if(l.fi == r.fi && l.se > r.se)
    return 1;
  return 0;
}

int main() {
  ll i, j, a, b, t, nowp, nexth, nowh, nextp, nowt, nextt,
      nowtop, nexttop;
  pair<ll, ll> dummy = make_pair(inf, 0);
  cin >> n >> m >> x;
  for(i = 0; i < n; ++i) {
    cin >> h[i];
    memo[i] = dummy;
  }
  for(j = 0; j < m; ++j) {
    cin >> a >> b >> t;
    --a;
    --b;
    edge[a].push_back(make_pair(b, t));
    edge[b].push_back(make_pair(a, t));
  }
  memo[0] = make_pair(0, x);
  pq.push(make_pair(0, 0));
  while(pq.size() > 0) {
    // now time point
    now = pq.top();
    pq.pop();
    // now data
    nowp = now.se;
    nowh = memo[nowp].se;
    nowt = now.fi;
    nowtop = h[nowp];
    for(i = 0; i < edge[nowp].size(); ++i) {
      // next time point
      nextn = now;
      nextn.se = edge[nowp][i].fi;
      nextp = nextn.se;
      nexttop = h[nextp];
      nextt = edge[nowp][i].se;
      // over height
      if(nowh - nextt > nexttop) {
        nextn.fi += nowh - nexttop;
        nexth = h[nextn.se];
      }
      // enough height
      else if(nextt <= nowh) {
        nextn.fi += nextt;
        nexth = nowh - nextt;
      }
      // not enough
      else if(nextt <= nowtop) {
        nextn.fi += 2 * nextt - nowh;
        nexth = 0;
      }
      // can't go
      else
        continue;
      // best time?
      if(cmp(make_pair(nextn.fi, nexth), memo[nextp])) {
        memo[nextp] = make_pair(nextn.fi, nexth);
        pq.push(nextn);
      }
    }
  }
  if(memo[n - 1].fi == inf)
    cout << -1 << endl;
  else
    cout << memo[n - 1].fi + h[n - 1] - memo[n - 1].se
         << endl;
  return 0;
}


Measured memory_bytes: 23780
s = [int(x) for x in input()]

import functools
@functools.lru_cache(maxsize=None)
def f(c, n):
    if n == 4:
        if c == 7:
            return []
        else:
            return None
    v = s[n]
    for o in ['+', '-']:
        ret = f(eval('%d%s%d'% (c,o,v)), n + 1)
        if ret is not None:
            return [o, v] + ret
print(''.join([str(x) for x in ([s[0]] + f(s[0], 1))]) + '=7')

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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr << "~ " << #x << " = " << x << endl

std::vector<int> v;
int n;

void rec(int pos, int val) {

	if(pos == n+1) {

		for(int i = 0; i < n; i++) {
			char ch = 'a'+v[i]-1;
			cout << ch;
		}

		cout << endl;
		return;
	}

	for(int i = 1; i <= val+1; i++) {
		
		v.push_back(i);
		rec(pos+1, max(val,i));

		v.pop_back();
	}
}

int main() {

	fast_cin;

	
	cin >> n;

	rec(1,0);
	
	
	
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

//-------------------------------------------------------//


int n, m, q, ans = 0;
int a[50], b[50], c[50], d[50];
vector<int> v;

int check() {
	int score = 0;
	for(int i = 0; i < q; i++)
		if(v[b[i]] - v[a[i]] == c[i]) score += d[i];
	
	return score;
}

void dfs(int i, int cur) { //i goes up to N, cur goes up to 10
	if(i >= n) {
		ans = max(ans, check()); 
		return;
	}
	
	for(int j = cur; j <= m; j++) {
			v.pb(j);
			dfs(i+1, j);
			v.pop_back();
	}
}

int main() {
	cin >> n >> m >> q;
	
	for(int i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; //this way indices start at 0
		b[i]--;
	}
	
	dfs(0, 1);
	
	cout << ans << endl;
	
	return 0;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  int n,m;
  cin >> n >> m;
  cout << ((n == m)?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  vi x = {a, b, c};
  sort(x.begin(), x.end());
  int ans = 0;
  ans += x[2] - x[1];
  x[0] += x[2] - x[1];
  x[1] += x[2] - x[1];
  ans += (x[1]-x[0])%2;
  ans += (x[1]-x[0] + (x[1]-x[0])%2)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int x[1000],y[1000],dp[1010][20000];
signed main(){
	int a,b,ans=INF;
	cin>>a>>b;
	f(i,b){
		f(j,20000){
			if(j)dp[i][j]=INF;
		}
	}
	f(i,b){
		cin>>x[i]>>y[i];
		f(j,20000){
			if(j<x[i])dp[i+1][j]=dp[i][j];
			else dp[i+1][j]=min(dp[i+1][j-x[i]]+y[i],dp[i][j]);
		}
	}
	for(int i=a;i<20000;i++){
		ans=min(dp[b][i],ans);
	}
	cout<<ans<<endl;
}


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

int main() {

    string S; cin >> S;
    bool flag = true;

    for (int i=0; i<S.size(); i++) {

        // 奇数文字
        if (i % 2 == 0) {
            if (S.at(i) == 'L') {
                flag = false;
                break;
            }
        }

        // 偶数文字
        else {
            if (S.at(i) == 'R') {
                flag = false;
                break;
            }
        }

    }

    if (flag) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;
using pii = pair<int, int>;
int dp[105][2][5],k,n,val[105];
char s[105];
int solve(int lak, int isless, int n1){
    if(dp[lak][isless][n1] != -1) return dp[lak][isless][n1];
    if(lak == n){
        if(n1 > 1) return 0;
        if(n1 == 0) dp[lak][isless][n1] = 1;
        else if(isless == 1) dp[lak][isless][n1] = 9;
        else dp[lak][isless][n1] = val[lak];
        return dp[lak][isless][n1];
    }
    int &rec = dp[lak][isless][n1];
    rec = 0;
    int ub = (isless == 1) ? 9 : val[lak];
    rec += solve(lak+1, isless || (val[lak] > 0), n1);
    if(n1 == 0) return rec;
    for(int i = 1;i <= ub; i++){
        int x = (isless == 1) ? 1  : (val[lak] > i ? 1 : 0);
        rec += solve(lak+1,x,n1-1);
    }
    return rec;
}
int main(){
    scanf("%s%d",s+1,&k);
    n = strlen(s+1);
    for(int i = 0;i <=n;i++){
        for(int j=0;j<2;j++){
            for(int l =0;l<=k;l++) dp[i][j][l]  =  -1;
        }
    }
    for(int i = 1;i <= n;i++) val[i] = s[i] -'0';
    printf("%d",solve(0,0,k));


}


Measured memory_bytes: 256