akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Globalization;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Read();
            var a = N[N.Length - 1];
            switch (int.Parse(a.ToString()))
            {
                case 3:
                    WriteLine("bon");
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    WriteLine("pon");
                    break;
                default:
                    WriteLine("hon");
                    break;
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27484
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
j = M

for i in range(N+1):
    if ruiA[i] > K:
        break
    while ruiA[i] + ruiB[j] > K:
        j -= 1
    MAX = max(MAX, i+j)

print(MAX)


Measured memory_bytes: 47408
#include<iostream>
#include<vector>
#define Max 100000
using namespace std;
int main(void){
int n,w,h;
cin>>n>>w>>h;
vector<int> x(n),y(n),r(n);
vector<int> xl(w+1,0),yl(h+1,0);
for(int i=0;i<n;i++){
	cin>>x[i]>>y[i]>>r[i];
xl[max(0,x[i]-r[i])]++;
xl[min(w,x[i]+r[i])]--;
yl[max(0,y[i]-r[i])]++;
yl[min(h,y[i]+r[i])]--;
}
bool ansx=true,ansy=true;
for(int i=0;i<w;i++){
	xl[i+1]+=xl[i];	
}
for(int i=0;i<h;i++){
	yl[i+1]+=yl[i];	
}
for(int i=0;i<w;i++){
	if(xl[i]==0)ansx=false;
}
for(int i=0;i<h;i++){
if(yl[i]==0)ansy=false;
}
if(ansx||ansy){
	cout<<"Yes"<<endl;
}else{
	cout<<"No"<<endl;
}

return 0;
}

Measured memory_bytes: 4692
a, b, c = map(int, input().split())

import math

S = (a * b * math.sin(math.radians(c))) / 2
x = math.sqrt(a**2 + b**2 -2*a*b*math.cos(math.radians(c)))
L = a + b + x
h = (2 * S) / a

print(S)
print(L)
print(h)


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

int main() {
  int N;
  cin>>N;
  vector<int> vec(100000);
  int Q;
  long Ans;
  Ans=0;
  rep(i,N){cin >> Q; Ans+=Q; vec.at(Q-1)++;}
  int B,C;
    cin>>Q;
    rep(i,Q){cin>>B>>C;
            Ans+=(C-B)*vec.at(B-1);
             vec.at(C-1)+=vec.at(B-1);
            vec.at(B-1)=0;
            cout<<Ans<<endl;}
}


Measured memory_bytes: 3732
#include <stdio.h>

int main(void){
  int i, j, n, m;
  int W[300], H[300];
  for(n=0 ; ; n++){
  scanf("%d %d",&H[n],&W[n]);
  if(H[n]==0 && W[n]==0){
     m=n;
 break;
  }
  }

  
  for(n=0 ; n<m ; n++){ 
 for(i=0 ; i<H[n] ; i++){
    for(j=0 ; j<W[n] ; j++){
      printf("#");
    }
    printf("\n");
  }
 printf("\n");
  }

 

return 0;
}

Measured memory_bytes: 576
n=int(input())
a=list(map(int,input().split()))
dp=[[0,-1e10] for i in range(n+1)]
for i in range(n):
    dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i])
    dp[i+1][1]=max(dp[i][1]+a[i],dp[i][0]-a[i])
print(dp[n][0])

Measured memory_bytes: 25588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c;
  cin >> c;
  if (c >= 'A' && c <= 'Z')
    cout << 'A' << endl;
  else
    cout << 'a' << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    bool flag = false;
    for (int i=0;i<3;i++){
        if (N%10==7){
            flag = true;
            break;
        }
        N/=10;
    }
    if(flag){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 3632
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = sorted(readInts(), reverse=True)
ans = 0
dic = defaultdict(int)
dq = deque()
for i in range(n):
    if i == 0:
        dq.append(A[i])
    else:
        ans += dq.popleft()
        for j in range(2):
            dq.append(A[i])
print(ans)


Measured memory_bytes: 32936
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)

	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &A[i])
	}

	A0, count := bubbleSort(A, n)

	fmt.Fprintln(w, strings.Join(itoS(A0)," "))
	fmt.Fprintln(w, count)
}

func bubbleSort(A []int, n int) ([]int, int) {
	flag := true
	count := 0
	for flag {
		flag = false
		for j := n - 1; j > 0; j-- {
			if A[j] < A[j-1] {
				buf := A[j]
				A[j] = A[j-1]
				A[j-1] = buf
				flag = true
				count += 1
			}
		}
	}
	return A, count
}

func itoS(A []int) []string {
	var s []string
	for _, k := range A {
		s = append(s, strconv.Itoa(k))
	}
	return s
}


Measured memory_bytes: 1196
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
 
show_flg=False
show_flg=True
 
ans=0
m=[]

n,d,a=LI()
for i in range(n):
    x,h=LI()
    m.append((x,h))

m.sort(key=lambda x:x[0])
dm=0
q=deque()

for i in range(n):
    x,h=m[i]
    while q:
        if x>q[0][0]:
            y,c=q.popleft()
            dm-=c*a
        else:
            break

    if h>dm:
        c=(h-dm+a-1)//a
        dm+=c*a
        ans+=c
        q.append((x+2*d,c))

print(ans)




Measured memory_bytes: 75352
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
auto Get(int i,tuple<int,int,int>tp){
    if(i == 0)return get<0>(tp);
    if(i == 1)return get<1>(tp);
    if(i == 2)return get<2>(tp);
    return 0LL;
}
signed main(){
    using tp = tuple<int,int,int>;
    vector<tp>u;
    int n; cin >> n;
    auto dp = vectors(n,3,0LL);
    rep(i,n){
        int a,b,c; cin >> a >> b >> c;
        u.push_back(tie(a,b,c));
    }
    rep(i,n){
        rep(j,3){
            if(i == 0){
                dp[0][j] = Get(j,u.front());
                continue;
            } else{
                rep(k,3){
                    if(j == k)continue;
                    int cost  = Get(k,u[i]);
                    cmax(dp[i][k],dp[i-1][j] + cost);
                }
            }
        }
    }
    cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
}



Measured memory_bytes: 10356
import java.util.*;
 
 
class Main {
    static int path[][];
    static int N;
    static ArrayList<Integer[]> permitations;
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        N = sc.nextInt();
        double x[] = new double[N];
        double y[] = new double[N];

        for(int i=0; i<N; i++){
            x[i] = sc.nextDouble();
            y[i] = sc.nextDouble();
        }
        
        permitations = new ArrayList<Integer[]>();
        ArrayList<Integer> candidate = new ArrayList<Integer>();
        for(int i=0;i<N;i++){
            candidate.add(new Integer(i));
        }
        pem(candidate);
        
        Integer arra[] = permitations.get(1);
        for(int i= 0;i<N;i++){
  
            
        }

        double sum = 0;
        int pc = 1;
        for(int i=1; i<=N; i++){
            pc *= i;
        }
        for(int i=0; i<pc; i++){
            double summ = 0;
            Integer array[] = permitations.get(i);
            for(int j=0; j<N-1; j++){
                double xi = x[array[j].intValue()];
                double xip = x[array[j+1].intValue()];
                double yi = y[array[j].intValue()];
                double yip = y[array[j+1].intValue()];
                double dis = Math.sqrt(Math.pow(xi-xip,2) + Math.pow(yi-yip,2));
                summ += dis;
            }
            sum += summ/pc;
        }
        System.out.println(sum);


    }

    public static void pem(ArrayList<Integer> data){
        ArrayList<Integer> candidate = new ArrayList<Integer>(data);
        ArrayList<Integer> perm = new ArrayList<Integer>();
        _pem(candidate,perm);
    }
    private static void _pem(ArrayList<Integer> candidate, ArrayList<Integer> pem){
        if(candidate.size() == 0) {
            Integer ary[] = new Integer[N];
            for(int i=0; i<N;i++){
                ary[i] = pem.get(i);
            }
            permitations.add(ary);
        }

        for(int i=0; i < candidate.size(); i++){
            ArrayList<Integer> p = new ArrayList<Integer>(pem);
            ArrayList<Integer> c = new ArrayList<Integer>(candidate);
            p.add(c.get(i));
            c.remove(i);
            _pem(c,p);
        }
    }

}

Measured memory_bytes: 46188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10, 0));
	rep(i, 10){
		rep(j, 10){
			int in;
			cin >> in;
			c.at(i).at(j) = in;
		}
	}
	map<int, int> m;
	rep(i, h*w){
		int in;
		cin >> in;
		if(in == -1) continue;
		m[in]++;
	}

	vector<int> d(10, INF);
	vector<bool> ch(10, false);
	d.at(1) = 0;
	ch.at(1) = true;
	int now = 1;
	rep(i, 10){
		rep(j, 10){
			int add = c.at(j).at(now);
			if(ch.at(j) == true) continue;
			d.at(j) = min(d.at(j), add + d.at(now));
		}
		int mn = INF, nnow = -1;
		rep(i, 10){
			if(ch.at(i) == true) continue;
			if(mn > d.at(i)){
				mn = d.at(i);
				nnow = i;
			}
		}
		if(nnow == -1) break;
		ch.at(nnow) = true;
		now = nnow;
	}
	ll ans = 0;

	// rep(i, 10){
	// 	cerr << d.at(i) << " ";
	// }
	// cerr << endl;
	for(auto p : m){
		ans += d.at(p.first) * p.second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N, M = [int(e) for e in input().split()]
    min_l = 1
    min_r = 100000
    for l in sys.stdin:
        l, r = [int(e) for e in l.strip().split()]
        if l > min_l:
            min_l = l
        if r < min_r:
            min_r = r

    res = min_r + 1 - min_l

    print(res if res > 0 else 0)

main()


Measured memory_bytes: 3060
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

const int N = 400000;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    ll ans = 1ll * s.size() * (s.size() + 1) / 2 + 1;
    vector<ll> cnt(26);
    for (int i = 0; i < s.size(); i++) cnt[s[i] - 'a']++;
    forn(i, 26) ans = ans - cnt[i] * (cnt[i] + 1) / 2;
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        long i,a=0,n=0,min=0,max=0,sum=0;
        n=scan.nextInt();
        for(i=0;i<n;i++){
        	a=scan.nextInt();
        	sum+=a;
        	if(i==0){
        		min=max=a;
        	}
        	if(min>a){
        		min=a;
        	}
        	if(max<a){
        		max=a;
        	}
        }
        System.out.println(min+" "+max+" "+sum);
    }
}

Measured memory_bytes: 41000
import sys

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

hw.sort()

hcnt = [0] * (H+1)
wcnt = [0] * (W+1)

target = []
for i, j in hw:
    hcnt[i] += 1
    wcnt[j] += 1
    target.append([str(i) + " " + str(j),1])

d = dict(target)

hlist = []
hmax = -1
for i in range(1,H+1):
    if hmax < hcnt[i]:
        hlist = [i]
        hmax = hcnt[i]
    elif hmax == hcnt[i]:
        hlist.append(i)

wlist = []
wmax = -1
for i in range(1,W+1):
    if wmax < wcnt[i]:
        wlist = [i]
        wmax = wcnt[i]
    elif wmax == wcnt[i]:
        wlist.append(i)

if len(hlist) * len(wlist) > M:
    print(hmax + wmax)
    sys.exit()

idx = 0
for h in hlist:
    for w in wlist:
        while h > hw[idx][0] or w > hw[idx][1]:
            idx += 1
            if idx == M:
                print(hmax + wmax)
                sys.exit()                
            if h == hw[idx][0] and w == hw[idx][1]:
                break
        if h < hw[idx][0] or w < hw[idx][1]:
            print(hmax + wmax)
            sys.exit()
        
print(hmax + wmax - 1)


Measured memory_bytes: 230860
// УЛЬЯНА НОВОЯТЛОВА САМАЯ ЛУЧШАЯ В МИРЕ!!!

#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <stack>
#include <algorithm>
#include <random>

using namespace std;

typedef long long ll;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    string s, s1;
    cin >> s;
    
    s1 = s;
    
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    
    if (s.length() < 26) {
        for (int i = 0; i < 26; ++i) {
            if (s.find((char)('a' + i)) == -1) {
                cout << s + (char)('a' + i) << endl;
                return 0;
            }
        }
    }
    
    next_permutation(s.begin(), s.end());
    for (int i = 0; i < 26; ++i) {
        cout << s[i];
        
        if (s[i] != s1[i]) {
            cout << endl;
            return 0;
        }
    }
    
    return 0;
}



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

int main(){
  int N;
  cin >>N;
  vector<int> d(N);
  for(int i=0; i<N; i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int ans=1;
  for(int i=0; i<N-1; i++){
    if(d.at(i)!=d.at(i+1)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    ll sum=0;
    ll pc=0;
    ll mc=0;
    for(ll i=0;i<N;i++){
        cin>>A[i];
        if(A[i]>=0)pc++;
        else mc++;
        sum+=llabs(A[i]);
        pq.push(llabs(A[i]));
    ;}
    if(llabs(mc)%2){
        sum-=2*pq.top();
    }
    cout<<sum<<endl;
    

    return 0;
}


Measured memory_bytes: 2168
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	ld A, B, X; cin >> A >> B >> X;
	bool rev = false;
	if (X * 2 > A*A*B) {
		X = A*A*B-X;
		cout << setprecision(20) << (ld) 90 / (ld) asin(1) * atan(X / A / A / A * 2);
	} else {
		ld val = X / A / B / B; val *= 2;
		val = atan(val);
		ld PI = asin(1) * 2;
		val *= 90;
		val /= PI / 2;
		val = 90 - val;
		cout << setprecision(20) << val;
	}
	
	cout << endl;
	
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

struct edge{int to,cap,rev;};
vector<edge> v[101010];
int n,m,dist[101010],iter[101010];

void addedge(int from,int to,int cap){
    int x=v[to].size(),y=v[from].size();
    v[from].push_back({to,cap,x});
    v[to].push_back({from,0,y});
}

void bfs(int s){
    rep(i,n)dist[i]=-1;
    queue<int> q;
    dist[s]=0;
    q.push(s);
    while(q.size()){
        int x=q.front();q.pop();
        for(auto& e:v[x]){
            if(e.cap>0&&dist[e.to]<0){
                dist[e.to]=dist[x]+1;
                q.push(e.to);
            }
        }
    }
}

int dfs(int x,int t,int f){
    if(x==t)return f;
    for(int& i=iter[x];i<(int)v[x].size();i++){
        edge& e=v[x][i];
        if(e.cap>0&&dist[x]<dist[e.to]){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                v[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(1){
        bfs(s);
        if(dist[t]<0)return flow;
        rep(i,n)iter[i]=0;
        int f;
        while((f=dfs(s,t,inf))>0)flow+=f;
    }
}
int main(){
    cin>>n>>m;
    rep(i,m){
        int s,t,c;
        cin>>s>>t>>c;
        addedge(s,t,c);
    }
    cout<<max_flow(0,n-1)<<endl;
   return 0;
}


Measured memory_bytes: 5580
#!/usr/bin/env python3
import sys
import fractions as f

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    #lcm=np.lcm.reduce(A)
    lcm=A[0]
    for i in range(1,N):
        lcm=lcm*A[i]//f.gcd(lcm,A[i])

    ans=0
    for i in range(N):
        ans+=lcm//A[i]
    print(ans%MOD)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8188
#include<bits/stdc++.h>
#define ll long long int
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define test(t) int t; cin >> t; while(t--)
#define endl "\n"
#define debug(x) cout << x << "\n"
#define pb push_back
#define mp make_pair
#define MEMS(x,t) memset(x, t, sizeof(x))
#define mod 1000000007
#define forn(i,n) for (ll i = 0; i < n; i++)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rrep(i,a,b) for( int i = a; i >= b; i--)
#define map map<ll,ll>
#define fi first
#define se second
#define set set<ll>
#define pp pair<ll,ll>
using namespace std;
bool sortbysec(const pp &a,
              const pp &b)
{
    return (a.second < b.second);
}
int main()
{
    ll n;
    cin >> n;
    ll a[n];
    forn(i,n) cin >> a[i];
    ll m = 0, h = 0;
    forn(i,n)
    {
        m = max(m,a[i]);
        if ( a[i] < m) h += m - a[i];
    }
    cout << h;
}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,C,h[200005],dp[200005],Q[400005],head=1,tail=1;
inline double slope(int j,int k){
	return 1.0*(dp[j]-dp[k]+h[j]*h[j]-h[k]*h[k])/(h[j]-h[k]);
}
signed main(){
	cin>>n>>C;
	for(int i=1;i<=n;i++)	cin>>h[i];
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0]=dp[1]=0;Q[1]=1;
	for(int i=2;i<=n;i++){
		while(head<tail&&slope(Q[head],Q[head+1])<=2*h[i])	head++;
		int j=Q[head];
		dp[i]=dp[j]+(h[i]-h[j])*(h[i]-h[j])+C;
		while(head<=tail&&slope(Q[tail],Q[tail-1])>=slope(Q[tail],i))	tail--;
		Q[++tail]=i;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 6016
def main():
    n = int(input())
    A = list(map(int, input().split(' ')))
    q = int(input())
    ms = list(map(int, input().split(' ')))
    results = _enumerate(A)

    for m in ms:
        if m in results:
            print('yes')
        else:
            print('no')



def _enumerate(lst):
    result = [0]
    for e in lst:
        n = len(result)
        for i in range(n):
            result.append(result[i]+e)
    return list(set(result))


if __name__ == '__main__':
    main()



Measured memory_bytes: 42980
#include<iostream>
#include<algorithm>
using namespace std;
long long N,A,B,ans;
int main(void){
    cin>>N;
    long long cuisine[N];
    for(int i=0;i<N;i++){cin>>A>>B;cuisine[i]=A+B;ans+=A;}
    sort(cuisine,cuisine+N,std::greater<long long>());
    for(int i=1;i<N;i+=2){ans-=cuisine[i];}
    cout<<ans<<endl;
    return 0;
}

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

const int maxc=1e6+5;
int n,m,cn;

vector<int>v[2*maxc];//注意大小 
vector<int>col[maxc];
int vis[2*maxc],id[2*maxc],dis[2*maxc];
queue<int>q;

int father[(int)1e5+5];
void rs(int x)
{
	father[x]=x;
	vis[x]=0;
	id[x]=0;
}
void reset()
{
	for(int i=1; i<=n; i++)
	{
		rs(i);
	}
}
int findf(int x)
{
	return father[x]==x?x:father[x]=findf(father[x]);
}
void join(int a,int b)
{
	int x=findf(a),y=findf(b);
	father[x]=y;
}

void pset()
{
	cin>>n>>m;
	for(int i=1; i<=m; i++)
	{
		int p,q,c;
		cin>>p>>q>>c;
		col[c].push_back(p);
		col[c].push_back(q);
	}
	cn=n;
	reset();
	for(int i=1; i<=1e6; i++)
	{
		if(col[i].size()==0)continue;
		for(int k=0; k<col[i].size(); k+=2)
		{
			int p=col[i][k],q=col[i][k+1];
			rs(p);
			rs(q);
		}
		for(int k=0; k<col[i].size(); k+=2)
		{
			int p=col[i][k],q=col[i][k+1];
			join(p,q);
		}
		for(int k=0; k<col[i].size(); k+=2)
		{
			int p=col[i][k],q=col[i][k+1];
			if(!vis[p])
			{
				vis[p]=1;
				int root=findf(p);
				if(!id[root])
				{
					cn++;
					id[root]=cn;
				}
				v[p].push_back(id[root]);
				v[id[root]].push_back(p);
			}
			if(!vis[q])
			{
				vis[q]=1;
				int root=findf(q);
				if(!id[root])
				{
					cn++;
					id[root]=cn;
				}
				v[q].push_back(id[root]);
				v[id[root]].push_back(q);
			}
		}
	}
}

void deal()
{
	q.push(1);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0; i<v[x].size(); i++)
		{
			if(!dis[v[x][i]])
			{
				dis[v[x][i]]=dis[x]+1;
				q.push(v[x][i]);
			}
		}
	} 
	cout<<(dis[n]==0?-1:(dis[n]/2))<<'\n';
}

int main()
{
	ios::sync_with_stdio(0);
	//cin.tie(0);
	pset();
	deal();

	return 0;
}

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def divisors(n):
    dd = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            dd.append(i)
            if i != n // i:
                dd.append(n//i)
    #dd.sort()
    return dd

def main():
    A, B, K = i2nn()
    g = gcd(A, B)
    dd = divisors(g)
    dd.sort()
    dd.reverse()
    n = dd[K-1]
    print(n)

main()


Measured memory_bytes: 38256
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=105;
int a[MAXN];
int main() {
	int n,x;
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=1;i<=n;++i) {
		if(i==n) {
			if(x==a[i]) ++ans;
			break;
		} else {
			if(x-a[i]<0) {
				break;
			} else if(x-a[i]>=0) {
				x-=a[i];
				++ans;
			}
		}
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 128
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    n %= 12;
    for(int i = 0; i < n; i++){
        if(i%2 == 0)    a = a-b;
        else            b = a+b;
    }
    cout << a << " " << b << endl;
    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int answer = a * b;
    if (answer % 2) {
        cout << "Odd" << endl;
    } else {
        cout << "Even" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if 0 > self.parents[x]:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if 0 > x]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
	
N, M = MAP()
L = [[x-1 for x in LIST()[1:]] for _ in range(N)]
uf = UnionFind(N)
graph = [[] for _ in range(M)]

for i, l in enumerate(L):
	for x in l:
		graph[x].append(i)

for i in range(M):
	if len(graph[i]) <= 1:
		continue
	p = graph[i][0]
	for x in graph[i][1:]:
		uf.union(p, x)

print("YES" if uf.group_count() == 1 else "NO")

Measured memory_bytes: 35996
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int kN = 100005;
void primeNumber(bool prime[kN]){
	rep(i,kN) prime[i] = 1;
	prime[0] = prime[1] = 0;
	rep(i,kN){
		if(prime[i]){
			for(int j = i + i; j < kN; j+=i){
				prime[j] = 0;
			}
		}
	}
}

int main(){
	bool p[kN];
	primeNumber(p);

	bool like[kN] = {0};
	for(int i = 3; i < kN; i+=2){
		if(p[i] and p[(i + 1) / 2]) like[i] = true;
	}



	vector<int> s(100005, 0);
	range(i,1,100001){
		s[i] = like[i] + s[i - 1];
	}

	int q;
	cin >> q;

	rep(i,q){
		int l, r;
		cin >> l >> r;
		cout << s[r] - s[l - 1] << endl;
	}
}


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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' '; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
double b,sm=0,as;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n >> k;
	double a[n];
    for (int i=0;i<n;++i){
      cin >> b;
      a[i] = b / 2.0 + 0.5;
      //dbg(a[i]);
    } 
    //sort(a,a+n);
    REP(i,k) 
		sm += a[i];

  as  = sm;
    FOR(j,0,n-k) {
      sm += a[j+k];
      sm -= a[j];   
      if (as < sm)
        as = sm;
    }
  cout << (double)as << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const LL mod=1000000007;
int main(){
    int N;cin>>N;
    string S[2];
    cin>>S[0]>>S[1];
    LL res=1;
    if(S[0][0]==S[1][0])res*=3;
    else res*=6;
    FOR(i,1,N){
        if(S[0][i-1]==S[1][i-1]){//ひとつまえが縦の時
            res=res*2LL%mod;
        }else{//ひとつまえが横の時
            if(S[0][i]==S[1][i])res*=1LL;
            else if(S[0][i]!=S[0][i-1])res=res*3LL%mod;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
signed main(){
	ll n,x; cin>>n>>x;
	vl a(n);
	rep(i,0,n)cin>>a[i];
	ll ans=0;
	rep(i,1,n){
		if(a[i]+a[i-1]>x){
			ans+=a[i]+a[i-1]-x;
			ll k=a[i]+a[i-1]-x;
			if(a[i]+a[i-1]-x<=a[i]){
				a[i]-=a[i]+a[i-1]-x;
			}
			else{
				k-=a[i]+a[i-1]-k;
				a[i]=0;
				a[i-1]-=k;
			}
		}
	}
	//rep(i,0,n) cout<<a[i]<<" ";
	 cout<<endl;
	cout<<ans<<endl;
	return 0;
}

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

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, 0, N)cin >> A[i];

	int buy = 1;
	pii mon = mp(1000, 0);

	rep(i, 0, N)
	{
		if (buy == 1)
		{
			if (i < N - 1 && A[i] < A[i + 1])
			{
				mon.second = mon.first / A[i];
				mon.first -= mon.second*A[i];
				buy = 0;
			}
		}
		else
		{
			if (i == N - 1 || A[i] > A[i + 1])
			{
				mon.first += mon.second*A[i];
				mon.second = 0;
				buy = 1;
			}
		}
	}

	cout << mon.first << endl;
	

	return 0;
}

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

int main() {
  long long a,b;
  cin >> a >> b;
  if(a == 1 || b == 1){
    cout << 1 << endl;
    return 0; 
  }
  if(a%2 == 1 && b%2 == 1) cout << a*b/2+1 << endl;
  else cout << a*b/2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int i,air[10000];
    for(i=0;i<3;i++)
    {
        scanf("%lld",&air[i]);
    }
    sort(air,air+3);
    printf("%lld\n",air[0]+air[1]);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 998244353
#define mad(a,b) a=(a+b)%mod
#define N 10000010
ll fac[N],ivf[N],inv[N];
ll C(ll n,ll k){
    if(n<k)return 0;
    if(k<0)return 0;
    return fac[n]*ivf[k]%mod*ivf[n-k]%mod;
}

ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
ll rui[N];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    fac[0]=ivf[0]=inv[1]=1;
    for(ll i=1;i<N;i++){
	if(i>1)inv[i]=(mod-(mod/i*inv[mod%i]%mod))%mod;
	fac[i]=fac[i-1]*i%mod;
	ivf[i]=ivf[i-1]*inv[i]%mod;
    }
    ll n; cin>>n;
    ll ans=po(3,n);
    for(ll x=n/2+1;x<=n;x++){
	mad(ans,-2*C(n,x)*po(2,n-x)%mod);
    }
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}



Measured memory_bytes: 235008
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;


int main(){
    string s;
    cin >> s;
    int a[3]={0};
    for(int i=0;i<3;i++){
        a[s[i]%3]++;
    }
    if(a[0]==a[1]&&a[1]==a[2]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define INF 999999999
int main(){
    int n;
    cin >> n;
    string ans = "No";
    for(int i=0;i<=100;i=i+4){
        for(int j=0;j<=100;j=j+7){
            if(i+j==n){
                ans="Yes";
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [0]*(H+2)
S[0] = '*'*(W+2)
S[H+1] = '*'*(W+2)
for h in range(1,H+1):
  S[h] = '*' + input() + '*'

import sys
sys.setrecursionlimit(10**8)

bw = ['#','.']

visited = [[False]*(W+2) for h in range(H+2)]
ans = 0
dh = [0,1,0,-1]
dw = [1,0,-1,0]

def dfs(h,w,c):
  #print(h,w,c, bw_count)
  for i in range(4):
    h0 = h+dh[i]
    w0 = w+dw[i]
    if S[h0][w0]==bw[c^1] and visited[h0][w0]==False:
      visited[h0][w0]=True
      bw_count[c^1]+=1
      dfs(h0,w0,c^1)
  
for h in range(H+2):
  for w in range(W+2):
    if S[h][w]=='#' and visited[h][w]==False:
      bw_count = [1,0]
      visited[h][w]=True
      dfs(h,w,0)
      ans += bw_count[0]*bw_count[1]

print(ans)   

#print(*ans, sep='\n')


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int> > F(N, vector<int>(10));
    for(int n=0; n<N; n++) {
        for(int i=0; i<10; i++) {
            cin >> F[n][i];
        }
    }
    vector<vector<long long int> > P(N, vector<long long int>(11));
    for(int n=0; n<N; n++) {
        for(int i=0; i<11; i++) {
            cin >> P[n][i];
        }
    }
    
    long long int ans=-1e9;
    for(int i=1; i<(1<<10); i++) {
        long long int ta=0;
        for(int n=0; n<N; n++) {
            int cnt=0;
            for(int j=0; j<10; j++) {
                if(i & (1<<j) && F[n][j]) {
                    cnt++;
                }
            }
            ta += P[n][cnt];
        }
        ans = max(ans, ta);
    }
    
    cout << ans << endl;


    return 0;
    
}

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

#define ll long long
#define ull unsigned ll

#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define INFLL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define DEBUG 0


int main ()

{
    //#define int ll
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    string s, t;
    cin >> s >> t;
    int m = s.size();
    int n = t.size();
    int dp[m+1][n+1];

    for (int i=0; i<=m; i++){
        dp[i][0] = 0;
    }
    for (int i=0; i<=n; i++){
        dp[0][i] = 0;
    }
    string lcs = "";
    for (int i=1; i<=m; i++){
        for (int j = 1; j<=n; j++){
            if (s[i-1] == t[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
                
            }
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    int i = m;
    int j = n;
    while (i > 0 and j > 0){
        if (s[i-1] == t[j-1]) {
            lcs += s[i-1];
            i--;
            j--;
        }
        else if (dp[i-1][j] > dp[i][j-1]) i--;
        else j--;
    }
    reverse(lcs.begin(), lcs.end());

    //cout << dp[m][n] << endl;
    cout << lcs << endl;
       
    return 0;
}

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

int main(){
  int r;
  cin >> r;
  string rtn;
  if (r<1200) rtn="ABC";
  else if (r<2800) rtn="ARC";
  else rtn="AGC";
  cout << rtn << endl;
}

Measured memory_bytes: 256