akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

namespace SOLVE {
    void main(){
        
    }
}
int ans[100000];

void G(){
    cout<<"YES";exit(0);
}
void B(){
    cout<<"NO";exit(0);
}
int main() {
    
    
    
    
    
    string s;
    cin>>s;
    string a = "CODEFESTIVAL2016";
    int ans = 0;
    REP(i,0,sz(s))ans+=a[i]!=s[i];
    cout<<ans;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	bool is_odd(int x);
	int n,i,sum=0;
	cin>>n;
	for(i=1;i<=n;i++)
	if(is_odd(i))sum++;
	cout<<sum;
	return 0;
}
bool is_odd(int x){
	int s=0;
	while(x!=0){
		x/=10;
		s++;
	}
	if(s%2==0)return false;
	else
	return true;
}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  int N;
  cin >> N;

  vector<int> A(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
  }

  vector<int> B = A;  
  sort(A.begin(), A.end());
  int ans = 0;
  {
    int l = 0, r = N-1;
    vector<int> C;
    C.emplace_back(A[r--]);
    while ( r-l > 0 ) {    
      C.emplace_back(A[l++]);
      if ( r == l ) continue;    
      C.emplace_back(A[r--]);
    }
    /*for ( int i = 0; i < C.size(); i++ ) {
      cout << C[i] << " ";
      } cout << endl;*/
    for ( int i = 1; i < C.size(); i += 2 ) {
      ans += abs(C[i]-C[i-1]);
      if ( i < C.size()-1 ) ans += abs(C[i]-C[i+1]);    
    }
    // cout << ans << endl;
    ans += max(abs(C[0]-A[r]), abs(C[(int)C.size()-1LL]-A[r]));  
  }
  sort(A.begin(), A.end(), greater<int>());  
  {
    int tmp = 0;    
    int l = 0, r = N-1;
    vector<int> C;
    C.emplace_back(A[r--]);
    while ( r-l > 0 ) {    
      C.emplace_back(A[l++]);
      if ( r == l ) continue;    
      C.emplace_back(A[r--]);
    }
    /*for ( int i = 0; i < C.size(); i++ ) {
      cout << C[i] << " ";
      } cout << endl;*/
    for ( int i = 1; i < C.size(); i += 2 ) {
      tmp += abs(C[i]-C[i-1]);
      if ( i < C.size()-1 ) tmp += abs(C[i]-C[i+1]);    
    }
    // cout << ans << endl;
    tmp += max(abs(C[0]-A[r]), abs(C[(int)C.size()-1LL]-A[r]));
    ans = max(ans, tmp);    
  }
  cout << ans << endl;  
  
  return 0;
}


Measured memory_bytes: 3684
import fractions

N, X = map(int, input().split())
x = list(map(int, input().split()))
y = []
x.insert(0, X)
x.sort()
for i in range(1, N+1):
    x1 = x[i] - x[i-1]
    y.append(x1)

d = y[0]

for i in range(1, len(y)):
    d = fractions.gcd(y[i], d)

print(d)

Measured memory_bytes: 16296
public class
Main
{
  public void
  run (
    final java.util.Scanner sc,
    final java.io.PrintStream out
    )
  {
    String s;
    int[ ] d = new int[ 26 ];
    boolean[ ] f;
    int i;

    s = sc.next ( );
    f = new boolean[ s.length ( ) ];
    for ( i = 0; i < s.length ( ); ++i )
    {
      d[ s.charAt ( i ) - 'A' ] += 1;
      if ( i - 8 >= 0 )
        d[ s.charAt ( i - 8 ) - 'A' ] -= 1;
      if ( d[ 'A' - 'A' ] == 2
        && d[ 'I' - 'A' ] == 1
        && d[ 'D' - 'A' ] == 1
        && d[ 'U' - 'A' ] == 1
        && d[ 'N' - 'A' ] == 2
        && d[ 'Y' - 'A' ] == 1 ) f[ i - 7 ] = true;
    }

    for ( i = 0; i < s.length ( ); )
    {
      if ( f[ i ] )
      {
        out.print ( "AIZUNYAN" );
        i += 8;
      }
      else
      {
        out.print ( s.charAt ( i ) );
        i += 1;
      }
    }
    out.println ( );
  }

  public static void
  main (
    final String[ ] args
    )
  {
    ( new Main ( ) ).run ( new java.util.Scanner ( System.in ), System.out );
  }
}

Measured memory_bytes: 17404
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b
  
def solve():
    R, G, B, N = map(int, line_input())
    ans = 0
    for r in range(N // R + 1):
        left = N - r * R
        for g in range(left // G + 1):
            if (left - g * G) % B == 0: ans += 1
    print(ans)

    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();
        long x = Math.min(N, B - 1);
        System.out.println(A * x / B - A * (x / B));
        sc.close();
    }
}

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

void ioThings() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
    freopen("io\\err.txt", "w", stderr);
#endif
}

using   ll        = long long;
#define debug(x)    cerr << #x << ": <" << (x) << ">\n"
#define dotc()      int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second
#define mod         1000000007

int main() {
    ioThings();

    int a, b, c; cin >> a >> b >> c;
    cout << (a == b && a != c || a == c && a != b || b == c && a != b ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val MAX = 100000
    val (nl, k) = readListOfLong() 
    val n = nl.toInt()

    val buckets = (0..MAX).map { 0L }.toMutableList()

    for(i in 0 until n) {
        val (a, b) = readListOfInt()
        buckets[a] += b.toLong()
    }
    var cnt = k
    var ans = 0
    for(i in 0..MAX) {
        if(cnt <= buckets[i]) {
            ans = i
            break
        }
        cnt -= buckets[i]
    }
    println(ans)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 55960
N=int(input())
A=list(map(int, input().split())) 
k =  len(bin(max(A))[2:])
bit = [bin(i)[2:].zfill(k) for i in A]
mod = 10**9+7
ans = 0
for i in range(k):
  cnt = sum([1 for j in bit if j[i]=='1'])
  ans += cnt*(N-cnt)*(2**(k-i-1))
  ans %= mod  

print(ans)
  

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


int main(){
    string s;
    cin>>s;
    int cnt=0;
    
    if(s[0]==s[1] && s[1]==s[2])
        cnt++;
    
    cout<<(cnt ? "No":"Yes")<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#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;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int a[100][100];
int n;
int m;

int main(){
  cin >> n;
  vector<int> d(n);
  rep(i,n){
    cin >> d[i];
  }
  cin >> m;
  int t[m];
  rep(i,m)cin >> t[i];
  sort(d.begin(),d.end());
  rep(i,m){
    auto it=lower_bound(d.begin(),d.end(),t[i]);
    if(*it==t[i]){
      d.erase(it);
    }else{
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
return 0;}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<queue>
#include<list>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
const ll maxn = 1000 + 5;
char maze[maxn][maxn];
int ans = 0; 
int main(){
//	ios::sync_with_stdio(false);
//	ifstream cin("data.txt");
//	freopen("data.txt", "r", stdin);
	queue<pair<int, int> >q;
	int m, n;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> maze[i][j];
			if(maze[i][j] == '#')q.push(pair<int, int>(i, j));
		}
	}
	int temp = q.size();
	while(!q.empty()){
		//cout << q.front().first << " " << q.front().second << endl;
		//cout << "q.size() = " << q.size() << endl; 
		int r = q.front().first, l = q.front().second;		
		q.pop();
		if(r > 0){
			if(maze[r - 1][l] == '.'){
				maze[r - 1][l] = '#';
				q.push(pair<int, int>(r - 1, l));
			}
		}
		if(r < n - 1){
			if(maze[r + 1][l] == '.'){
				maze[r + 1][l] = '#';
				q.push(pair<int, int>(r + 1, l));
			}
		}
		if(l > 0){
			if(maze[r][l - 1] == '.'){
				maze[r][l - 1] = '#';
				q.push(pair<int, int>(r, l - 1));
			}
		}
		if(l < m - 1){
			if(maze[r][l + 1] == '.'){
				maze[r][l + 1] = '#';
				q.push(pair<int, int>(r, l + 1));
			}
		}
		if(--temp == 0){
			ans++;
			temp = q.size();
		}
		//cout << "ans = " << ans << endl;
		//cout << "temp = " << temp << endl;
	}
	cout << ans - 1;
	return 0;
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
long long n, k;
int main(){
    n = read(), k = read();
    long long a = n % k;
    if (abs(k-a) > a)
        cout << a << endl;
    else
        cout << abs(k-a) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstring>

using namespace std;

int main()
{
    char c[100010];

    scanf("%[^\n]", c);


    for (int i = 0; i < strlen(c); i++) {
        if (c[i] >= 'a' && c[i] <= 'z') {
            c[i] -= 0x20;
        }
        else if (c[i] >= 'A' && c[i] <= 'Z') {
            c[i] += 0x20;
        }
    }
    cout << c << endl;
}



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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// constexpr ll INF = 1LL << 60;
int getS(pair<int, int> p){
  return p.first * p.second;
}
bool cmp(pair<int, int> l, pair<int, int> r){
  return getS(l) < getS(r);
}
void solve(int N, int W, int D){
  vector<pair<int, int>> pieces(1, {W, D});
  REP(i, N){
    int p, s;
    cin >> p >> s;
    p--;
    int w, d;
    tie(w, d) = pieces[p];
    pieces.erase(pieces.begin()+p);
    pair<int, int> add1, add2;
    s %= 2*w+2*d;
    if(s < w){
      add1 = {s, d};
      add2 = {w-s, d};
    }
    else if(s < w+d){
      s-=w;
      add1 = {w, s};
      add2 = {w, d-s};
    }
    else if(s < 2*w+d){
      s -= w+d;
      add1 = {s, d};
      add2 = {w-s, d};
    }
    else{
      s-= 2*w+d;
      add1 = {w, s};
      add2 = {w, d-s};
    }
    if(getS(add1) > getS(add2)){
      swap(add1, add2);
    }
    pieces.push_back(add1);
    pieces.push_back(add2);
  }
  sort(pieces.begin(), pieces.end(), &cmp);
  REP(i, N+1){
    cout << getS(pieces[i]) << (i!= N ? " " : "\n");
  }
}

int main(){
  while(true){
    int n, w, d;
    cin >> n >> w >> d;
    if(n==0 && w==0 && d==0) break;
    solve(n, w, d);
  }
  return 0;
}




Measured memory_bytes: 3008
#include <iostream>

using namespace std;

int
main()
{
  int n;
  cin >> n;
  char c;
  for (int i = 0; i < n; ++i) {
    cin >> c;
    if (c == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long a,b,x; cin>>a>>b>>x;
    long long ans = 0;
    if(a==0){
        a=1;
        ++ans;
    }
    ans+=b/x-(a-1)/x;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7


def mod_power(n, p, m):
    if p == 0: return 1
    if p % 2 == 0:
        half = mod_power(n, p // 2, m)
        return half * half % m
    else:
        return n * mod_power(n, p - 1, m)


n = int(input())
a = list(map(int, input().split()))

csum_invs = [0]
t = 0
for i in range(1, n + 1):
    t += mod_power(i, MOD - 2, MOD)
    t %= MOD
    csum_invs.append(t)

fact = []
t = 1
for i in range(1, n + 1):
    t *= i
    t %= MOD
    fact.append(t)

ans = 0
for i in range(n):
    coef = csum_invs[n - i]
    coef += csum_invs[i + 1]
    coef -= 1
    t = coef * a[i]
    t %= MOD
    ans += t

ans *= fact[-1]
ans %= MOD

print(ans)

Measured memory_bytes: 15304
import Data.List

dist (_:[]) = []
dist (a:b:r) = (b-a):(dist (b:r))

ans' w m =
    let d = reverse $ sort $ dist m
        d'= drop (w-1) $ d
    in
        sum d'

ans [] = []
ans ([_,w]:m:r) = (ans' w m):(ans r)

main = do
  _ <- getLine
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o


Measured memory_bytes: 16428
#include <iostream>

using namespace std;

const int Z = 1e9+7;

int fp(int a, int x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return 1ll * a * fp(a, x - 1) % Z;
    }
    int t = fp(a, x / 2);
    return 1ll * t * t % Z;
}

int inv(int a) {
    return fp(a, Z - 2);
}

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

    int fac[n*m-1];
    fac[0] = 1;
    for (int i = 1; i <= n * m - 2; i++) {
        fac[i] = 1ll * fac[i-1] * i % Z;
    }
    int c0 = 1ll * fac[n*m-2] * inv(fac[k-2]) % Z * inv(fac[n*m-k]) % Z;

    int c1 = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int dx1 = 1ll * i * (i + 1) / 2 % Z;
            int dx2 = 1ll * (n - 1 - i) * (n - i) / 2 % Z;
            int dy1 = 1ll * j * (j + 1) / 2 % Z;
            int dy2 = 1ll * (m - 1 - j) * (m - j) / 2 % Z;
            c1 = (c1 + 1ll * m * (dx1 + dx2)) % Z;
            c1 = (c1 + 1ll * n * (dy1 + dy2)) % Z;
        }
    }
    c1 = 1ll * c1 * inv(2) % Z;

    cout << 1ll * c0 * c1 % Z << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define MAX_DATA 500000
#define N 2000000000

void merge(int[],int,int,int);
void mergeSort(int[],int ,int);
int A[MAX_DATA],count=0;

int main()
{
  int i,n;

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

  mergeSort(A,0,n);

  for(i = 0; i <n-1; i++){
    printf("%d ", A[i]);
  }
  printf("%d\n%d\n",A[i],count);
  return 0;
}
void merge(int temp[],int left,int mid,int right){
  int n1, n2, i, j, k, L[MAX_DATA], R[MAX_DATA];

  n1= mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i]=temp[left +i];
  }
  for(j=0;j<n2;j++){
    R[j]=temp[mid+j];
  }
    L[n1]=N;
    R[n2]=N;
    i=0;
    j=0;
   
  for(k=left;k<right;k++){
    count++;
    if(L[i] < R[j]){
      temp[k]=L[i];
      i=i+1;
    }
    else {
      temp[k]=R[j];
      j=j+1;
    }
  }
}
 
void mergeSort(int temp[],int left,int right){
  int mid;
  if(right > left+1){
    mid = (right + left)/2;
    mergeSort(temp, left, mid);
    mergeSort(temp, mid, right);
    merge(temp, left, mid, right);
  }
}

Measured memory_bytes: 5480
#include<cstdio>
#define reg register
typedef long long ll;
int main(){
	reg int n,a,b,c,d;scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);b-=a;
	for(reg int i=0;i<n;i++){
		reg ll l=1ll*(n-1)*c-1ll*i*(c+d),r=l+1ll*(n-1)*(d-c);
		if(l<=b&&b<=r)return 0*puts("YES");
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    int N, A;
    cin >> N >> A;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    
    vector<vector<vector<lint>>> dp(N + 1, vector<vector<lint>>(N + 1, vector<lint>(2510, 0)));
    dp[0][0][0] = 1;
    rep(i, N) rep(j, N + 1) rep(k, 2510) {
        dp[i + 1][j][k] += dp[i][j][k];
        if (j + 1 <= N && k + a[i] <= 2500) dp[i + 1][j + 1][k + a[i]] += dp[i][j][k];
    }
    lint ans = 0;
    for (int i = 1; i <= N; ++i) ans += dp[N][i][A * i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 52352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int N,A,B;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atoi(p);
  p=strtok(NULL," \n");
  A=atoi(p);
  p=strtok(NULL," \n");
  B=atoi(p);
  
  if(N*A<B){
    printf("%d\n",N*A);
  }else{
    printf("%d\n",B);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

pair<int,int> scantime(){
    int h1,h2,m1,m2;
    
    scanf("%d:%d-%d:%d",&h1,&m1,&h2,&m2);
    
    return make_pair(h1*60+m1,h2*60+m2);
}


int main(){
    int n,k,t,m,tc_t[100]={0},tc_s[100]={0},ans=0;
    pair<int,int> p,T[100];
    
    
    scanf("%d",&t);
    
    for(int i=0;i<t;i++){
        T[i]=scantime();
    }
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            p=scantime();
            
            for(int l=0;l<t;l++){
                if(p.first<=T[l].first && T[l].second<=p.second){
                    tc_t[l]++;
                }
            }
            
        }
    }
    
    scanf("%d",&m);
    
    for(int i=0;i<m;i++){
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            p=scantime();
            
            for(int l=0;l<t;l++){
                if(p.first<=T[l].first && T[l].second<=p.second){
                    tc_s[l]++;
                }
            }
        }
    }
    
    for(int i=0;i<t;i++){
        ans+=min(tc_t[i],tc_s[i]);
    }
    
    printf("%d\n",ans);
    
    return 0;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	
	for(int i = 0; i < k; ++i){
		int x, y;
		cin >> x >> y;
		int ans = 0;
		if(y * 2 + 1 == n){
			if(x <= n / 2){
				ans = x % 3;
			}
			else {
				ans = (n - x + 1) % 3;
			}
		}
		else if(y <= n / 2){
			if(x >= y && x <= n - y){
				ans = y % 3;
			}
			else if(x <= n / 2){
				ans = x % 3;
			}
			else {
				ans = (n - x + 1) % 3;
			}
		}
		else {
			if(x >= n - y && x <= y){
				ans = (n - y + 1) % 3;
			}
			else if(x <= n / 2){
				ans = x % 3;
			}
			else {
				ans = (n - x + 1) % 3;
			}
		}
		if(ans == 0)
			cout << 3 << endl;
		else {
			cout << ans << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define int long long

using namespace std;

int MOD = 1e9 + 7;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h, w; cin >> h >> w;
	vector<vector<int>> v(h, vector<int>(w,0));
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			char t; cin >> t;
			if(t == '.') v[i][j] = 1;	
		}
	}	

	vector<vector<int>> dp(h, vector<int>(w, 0));
	dp[0][0] = 1;
	for(int i = 1; i < w; i++) if(v[0][i]) dp[0][i] = dp[0][i-1] && 1;
	for(int i = 1; i < h; i++) if(v[i][0]) dp[i][0] = dp[i-1][0] && 1;

	for(int i = 1; i < h; i++){
		for(int j = 1; j < w; j++){
			if(v[i][j]){
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
			}
		}
	}
	cout << dp[h-1][w-1];


	#ifdef LOCAL
	cerr << "\n";
	#endif
	return 0;
}


Measured memory_bytes: 18936
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

int main(){
    int n;
    cin >> n;
    ll x[n], y[n], h[n], x0, y0, h0;
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]!=0){
            x0=x[i]; y0=y[i]; h0=h[i];
        }
    }

    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            bool b=true;
            ll dist=abs(i-x0)+abs(j-y0);
            ll height=h0+dist;
            for(int k=0; k<n; k++){
                if(h[k]!=max(height-abs(i-x[k])-abs(j-y[k]),0ll)){
                    b=false;
                }
            }
            if(b){
                cout << i << " " << j << " " << height << endl;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>      
using namespace std;
const int N = 2e5 + 100;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ull unsigned long long
#define ll long long
#define pii pair <int,int>
#define forn(l,i,n) for(int i = l;i <= n;++i)   
#define FOR(l,i,n) for(int i = l;i < n;++i)
#define all(v) v.begin(), v.end()
#define pll pair <ll,ll>
const ll inf = 1e9 + 7;
const ll ll_inf = 1e17 + 100;   
const double pi = 3.14159265358979323;
inline void fr(){
    freopen("gcd.in", "r", stdin);
    freopen("gcd.out", "w", stdout);
}
void boost()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
 
ll binpow (ll a, ll n)
{
    ll res = 1;
    while (n) {
        if (n & 1)
        {
            res *= a;
            res %= inf;
        }
        a *= a;
        n >>= 1;
        a %= inf;
    }
    return res;
}
        
ll n,w;
ll v[N],a[N];
ll dp[N];
ll ans;
 
main()	
{                                                                        
	cin >> n >> w;
	for (int i = 1;i <= n;++i)
	{
		cin >> a[i] >> v[i];
	}            
	for (int i = 1;i <= n;++i)
	{
		for (int j = w;j >= 0;--j)
		{
		   	if (dp[j] != 0 || j == 0)
		   	{
		   		dp[j + a[i]] = max(dp[j + a[i]],dp[j] + v[i]);
		   		if (j + a[i] <= w)
		   		ans = max(ans,dp[j + a[i]]);	
		   	}
		}
	}
	cout << ans;
}	 


Measured memory_bytes: 3840
// AOJ DPL_5_C Balls and Boxes 3
// n 個の区別できるボールを k 個の区別できる箱に入れる
// とき、可能な入れ方の総数を求めてください。
// ただし、
//    どのボールも、必ずいずれかの箱に入れる。
//    どの箱にも、1つ以上のボールを入れる。
// 答えは　階乗*第2種スターリング数 k! * stirling2(n, k)
// 2019.3.11 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MOD 1000000007
int tbl[1001][1001];

int fact(int n)
{
	int i;
	long long ans = 1;
	for (i = 2; i <= n; i++) ans = (ans * i) % MOD;
	return (int)ans;
}

int stirling2(int n, int k)
{
	int ans;

	if (k == 0) return 0;
	if (tbl[n][k]) return tbl[n][k];
	if (k == 1 || k == n) ans = 1;
	else ans = (((long long)k * stirling2(n - 1, k)) % MOD)
		+ stirling2(n - 1, k - 1);
	return tbl[n][k] = ans % MOD;
}

int main()
{
	int n, k;

	scanf("%d%d", &n, &k);
	if (n < k) puts("0");
	else printf("%d\n", (int)(((long long)fact(k)*stirling2(n, k)) % MOD));
	return 0;
}


Measured memory_bytes: 5652
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  multiset<ll> s;
  rep(i,n) {
    ll x;
    cin>>x;
    s.insert(x);
  }
  int ans=0;
  while(!s.empty()) {
    auto m = s.end();
    m--;
    s.erase(m);
    ll y=1;
    while(y<=*m)y*=2;
    if(s.find(y-*m)!=s.end()) {
      s.erase(s.find(y-*m));
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9600
n,m=map(int,input().split())
a=list(map(int,input().split()))
hq=[]
from heapq import heappush,heappop
for i in range(n):
	heappush(hq,-a[i])
ans=0
import math
for i in range(m):
	k=heappop(hq)
	ans+=math.ceil(-k/2)
	heappush(hq,(-k+k//2)*-1)
print(sum(a)-ans)



Measured memory_bytes: 14224
n=io.read("*n","*l")
a={}
for i=1,2 do
    a[i]={}
    for j=1,n do
        a[i][j]=io.read("*n")
    end
end

total=0
for i=1,n do
    count=0
    for j=1,i do
        count=count+a[1][j]
    end
    for k=i,n do
        count=count+a[2][k]
    end
    total=math.max(count,total)
end
print(total)

Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>vec(N);
    for (int64_t i=0; i<N; i++) {
        cin >> vec.at(i);
    }

    reverse(vec.begin(), vec.end());
    vector<int64_t>ans(N);
    int64_t count = 0;
    for (int i=0; i<N; i++) {
        if (i % 2 == 0) {
            ans[i-count] = vec[i];
        } else {
            ans[N-1 - count] = vec[i];
            count += 1;
        }
    }

    for (int64_t i=0; i<N; i++) {
        cout << ans[i];
        if (i < N-1)  {
            cout << " ";
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 6356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        double sum = 0;
        double ans = 0;
        int n = int.Parse(Console.ReadLine());
        int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        Array.Sort(arr);
        for (int i = 0; i <= n - 2; i++) sum += Math.Pow(2, i) * arr[i + 1];
        ans = (arr[0] + sum) / Math.Pow(2, n - 1);
        Console.WriteLine(ans);

    }



}



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

using namespace std;

const int Maxn = 1e5+7;

int n, maxv;
int v[2][Maxn], c[2][2];

int main()
{
	scanf("%d", &n);
	for(int i = 1, a; i <= n; ++i)
	{
		scanf("%d", &a);
		v[i&1][a]++;
		maxv = max(maxv, a);
	}
	for(int i = 1; i <= maxv; ++i)
	{
		if(v[0][i] > v[0][c[0][0]]) c[0][0] = i;
		if(v[1][i] > v[1][c[1][0]]) c[1][0] = i;
	}
	if(c[0][0] != c[1][0])
	{
		printf("%d\n", n-v[0][c[0][0]]-v[1][c[1][0]]);
	}
	else
	{
		for(int i = 1; i <= maxv; ++i)
		{
			if(i != c[0][0] && v[0][i] > v[0][c[0][1]]) c[0][1] = i;
			if(i != c[1][0] && v[1][i] > v[1][c[1][1]]) c[1][1] = i;
		}
		// else c[][] = 0
		printf("%d\n", n-max(v[0][c[0][0]]+v[1][c[1][1]], v[0][c[0][1]]+v[1][c[1][0]]));
	}
	return 0;
}

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

int main() {
	int n, m, matrix[100][100], vector[100];
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> matrix[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> vector[i];
	}

	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < m; j++) {
			sum += matrix[i][j] * vector[j];
		}
		cout << sum << endl;
	}
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

template <ll mod> class modint
{
private:
    ll x;

public:
    modint(ll x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(ll n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

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

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

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

    string s; cin >> s;
    int D; cin >> D;
    const int n = s.length();

    mint dp[n + 1][D][2] = {};
    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        int nd = s[i] - '0';
        for (int j = 0; j < D; j++) {
            for (int k = 0; k < 2; k++) {
                for (int d = 0; d <= (k ? 9 : nd); d++) {
                    dp[i + 1][(j + d) % D][k || (d < nd)] += dp[i][j][k];
                } 
            }
        }
    }

    mint ans = dp[n][0][0] + dp[n][0][1] - 1;

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

Measured memory_bytes: 15872
N = int(input())
H = list(map(int,input().split()))
 
c1 =0
c2 =0
for i in range(N-1):
  if H[i] >= H[i+1]:
    c1+=1
  else:
    if c1 > c2:
      c2=c1
    c1=0
if c1>c2:
  c2=c1
print(c2)

Measured memory_bytes: 15020
#include<iostream>
using namespace std;
int main(){
  int x=0;
  int ans=0;
  int n; cin>>n;
  string s; cin>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x+=1;
    }
    if(s[i]=='D'){
      x-=1;
    }
    if(x>ans)ans=x;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
 // freopen("input.txt","r",stdin);
#endif

  string s,t;
  cin>>s>>t;
  int n=s.size();
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]!=t[i])
      count++;
  }

  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    if (s.front() == s.back()) {
        if (s.length() % 2) cout << "Second" << endl;
        else cout << "First" << endl;
    }
    else {
        if (s.length() % 2) cout << "First" << endl;
        else cout << "Second" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = zeros(Int,4)
	for i in 1:n
		s = readline() |> chomp
		if s=="AC"
			a[1]+=1
		elseif s=="WA"
			a[2]+=1
		elseif s=="TLE"
			a[3]+=1
		else
			a[4]+=1
		end
	end
	println("AC x ",a[1])
	println("WA x ",a[2])
	println("TLE x ",a[3])
	println("RE x ",a[4])
end

main()

Measured memory_bytes: 193924
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include<string.h>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

char in[120];
pair<pair<string,int>,int> p[110];
	
int main(){
	int a;scanf("%d",&a);
	
	for(int i=0;i<a;i++){
		int t;scanf("%s%d",in,&t);
		string tmp=in;
		p[i]=make_pair(make_pair(in,-t),i);
	}
	
	std::sort(p,p+a);
	
	for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    c_4, c_2, c_0 = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            c_4 += 1
        elif a % 2 == 0:
            c_2 += 1
        else:
            c_0 += 1
    if c_2 == N:
        print('Yes')
    elif 0 < c_2 < N:
        print('Yes' if c_4 > 0 and c_4 >= c_0 else 'No')
    else:
        print('Yes' if c_4 >= c_0 - 1 else 'No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 15020
fun main(args: Array<String>) {
	val input = readLine() ?: return
	var max = 0
	var count = 0
	for (s in input) {
		if (s == 'A' || s == 'C' || s == 'G' || s == 'T') {
			count++
			if (count > max) {
				max = count
			}
		} else {
			count = 0
		}
	}
	println(max)
}

Measured memory_bytes: 33696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, h;cin>>n>>h;
    const int NM = 1e5+1;
    vector<int> a(n), b(n);
    int amx = 0;
    rep(i,n){
        cin>>a[i]>>b[i];
        chmax(amx, a[i]);
    }
    sort(all(b));
    // amx以上を投げる
    int ans = 0;
    while(!b.empty()){
        int t = b.back(); b.pop_back();
        if(t<amx) break;
        h-=t; ans++;
        if(h<=0)break;
    }
    if(h>0) ans+=(h+(amx-1))/amx;
    cout<<ans<<endl;
}

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

int main() {
    //a matrix of 10*3*4 initialized by 0 
    array<array<array<int,10>,3>,4> rooms;
    int i,j,k;
    int menber;
    for ( i = 0; i < 4; i++){
        for ( j = 0; j < 3; j++){
            for ( k = 0; k < 10; k++){
                rooms[i][j][k] = 0;
            } 
        }
    }
    cin >> j;
    while(cin >> i >> j >> k >> menber){
        rooms[i-1][j-1][k-1] += menber;
    }
    for ( i = 0; i < 4; i++){
        for ( j = 0; j < 3; j++){
            for ( k = 0; k < 10; k++){
                cout << " "<< rooms[i][j][k];
            }
            cout << endl; 
        }
        if(i < 3) cout << "####################"<<endl;
    }
    

    return 0;
}


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

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using S = string;
using SS = stringstream;
using C = char;
using LL = long long;
using VC = vector<char>;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using VVI = vector<vector<int>>;
using VVL = vector<vector<long>>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

template <class T>
void PrintVector(const vector<T> & v) {
  for (const auto & e: v) {
    cout << e << endl;
  }
}

template <class T>
void PrintVector(const vector<T> & v, I n) {
  rep(i, 0, n - 1) {
    cout << v[i] << endl;
  }
}
// I h, w;
// VI dx = {-1, 0, 1, 0};
// VI dy = {0, 1, 0, -1};
// vector<VC> maze(100, VC(100, '.'));
// VVL d(100, VL(100, kMax6));
// int BFS(int sx, int sy, int gx, int gy) {
//   queue<PLL> que;
//   que.emplace(sx, sy);
//   d[sx][sy] = 0;
//
//   while (!que.empty()) {
//     auto p = que.front();
//     que.pop();
//     if (p.X == gx && p.Y == gy) break;
//     rep(i, 0, 3) {
//       auto nx = p.X + dx[i];
//       auto ny = p.Y + dy[i];
//       if (nx >= 0 && nx < h && ny >= 0 && ny < w && maze[nx][ny] != '#' && d[nx][ny] == kMax6) {
//         que.emplace(nx, ny);
//         d[nx][ny] = d[p.X][p.Y] + 1;
//       }
//     }
//   }
//   return d[gx][gy];
// }
//
// int main(int argc, char const *argv[]) {
//   I w_cnt = 0;
//   cin >> h >> w;
//   rep(i, 0, h - 1) {
//     rep(j, 0, w - 1) {
//       char c;
//       cin >> c;
//       maze[i][j] = c;
//       if (c == '.') { ++w_cnt; }
//     }
//   }
//   auto min_len = BFS(0, 0, h - 1, w - 1);
//   if (min_len != kMax6) { cout << w_cnt - min_len - 1 << endl; }
//   else { cout << -1 << endl; }
//   return 0;
// }

int main(int argc, char const *argv[]) {
  S s;
  cin >> s;
  VI v(26, 0);
  rep(i, 0, s.size() - 1) {
    ++v[s[i] - 'a'];
  }
  if (s == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << endl;
  } else if (s.size() != 26) {
    cout << s;
    rep(i, 0, 25) {
      if (v[i] == 0) {
        cout << char('a' + i) << endl;
        break;
      }
    }
  } else {
    S s0(s);
    next_permutation(s0.begin(), s0.end());
    int i = 0;
    while (s0[i] == s[i]) { ++i; }
    rep(j, 0, i) cout << s0[j];
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

A = IR(5)
k = I()
for x, y in combinations(A, 2):
    if abs(x-y) > k:
        print(":(")
        exit()
print("Yay!")

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

LL mpow(LL a, LL i, LL M) {
    if (i == 0) return 1;
    LL r = mpow(a * a % M, i >> 1, M);
    if (i & 1) r = r * a % M;
    return r;
}

// NTT WEST
void NTT(vector<LL>& A, LL M, LL g) {
    int N = A.size();
    for (int i = 0, j = 0; j < N; j++) {
        if (i < j) swap(A[i], A[j]);
        for (int k = N >> 1; k > (i ^= k); k >>= 1);
    }
    for (int i = 1; i < N; i <<= 1) {
        LL q = mpow(g, (M - 1) / i / 2, M);
        LL qj = 1;
        rep(j, i){
            for (int k = j; k < N; k += i * 2) {
                LL l = A[k], r = A[k + i] * qj % M;
                A[k] = (l + r) % M;
                A[k + i] = (l + M - r) % M;
            }
            qj = qj * q % M;
        }
    }
}

struct Fuse { LL M, G; };

// trinitrotoluene EXPLODING!!
vector<LL> TNT(const vector<LL>& A, const vector<LL>& B, Fuse F) {
    int Z = 1; while (Z < A.size() + B.size()) Z <<= 1;
    vector<LL> ans(Z), Ax(Z), Bx(Z);
    LL iZ = mpow(Z, F.M - 2, F.M);
    rep(i, Z) Ax[i] = Bx[i] = 0;
    rep(i, A.size()) Ax[i] = A[i];
    rep(i, B.size()) Bx[i] = B[i];
    NTT(Ax, F.M, F.G);
    NTT(Bx, F.M, F.G);
    rep(i, Z) ans[i] = Ax[i] * Bx[i] % F.M;
    NTT(ans, F.M, mpow(F.G, F.M - 2, F.M));
    rep(i, Z) ans[i] = ans[i] * iZ % F.M;
    return move(ans);
}

const Fuse fuse[2] = { {998244353,3}, {1107296257,10} };

LL ExtGcd(LL a, LL b, LL& x, LL& y) {
    if (b == 0) { x = 1; y = 0; return a; }
    LL g = ExtGcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

struct ModEq {
    LL c1, c2, t1, t2, M;
    ModEq(LL m1, LL m2) {
        ExtGcd(m1, m2, c1, c2);
        c1 = (c1 + m2) % m2;
        c2 = (c2 + m1) % m1;
        t1 = m1; t2 = m2;
        M = m1 * m2;
    }
    LL operator()(LL a1, LL a2) {
        LL d = a1 + (a2 - a1) * c1 % t2 * t1;
        return (d + M) % M;
    }
};

const LL M = 200003;
int N;
LL I[M];
vector<LL> A;
vector<LL> C[2];

int main() {
    scanf("%d", &N);
    for (int i = 0, j = 1; i < M - 1; i++, j = j * 2 % M) I[j] = i;
    A.resize(M - 1);
    rep(i, N) {
        int a; scanf("%d", &a);
        if (a) A[I[a]]++;
    }
    rep(i, 2) C[i] = TNT(A, A, fuse[i]);
    ModEq X(fuse[0].M, fuse[1].M);
    rep(i, C[0].size()) C[0][i] = X(C[0][i], C[1][i]);
    rep(i, M - 1) C[0][i * 2] -= A[i];
    for (LL& c : C[0]) c /= 2;

    LL ans = 0;
    for (int i = 0, j = 1; i < C[0].size(); i++, j = j * 2 % M)
        ans += C[0][i] * j;

    cout << ans << endl;

    return 0;
}


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

int main() {
	int a,b,c,d,e;
	cin >> a;
	if (0 <= a <= 86400) {
		//?§?
		d = a % 60;
		//???
		b = a / 60;
		c = b % 60;
		//???
		e = a / 3600;

		cout << e << ":" << c << ":" << d << endl;
	}
	else {
		cout << "?????????????????\????????£?????´??°?????\?????????????????????" << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(void)
{
  int i,j,n;
  int sum=0;
  int sum1[100]={0};
  int w[100]={0};
  int x[100]={0};
  int min=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&w[i]);
    sum+=w[i];
  }
  
  for(i=0;i<n-1;i++){
    for(j=0;j<=i;j++){
      sum1[i]+=w[j];
    }
    x[i]=sum-2*sum1[i];
    if(x[i]<0)
      x[i]=-x[i];
  }
  
  min=x[0];
  
  for(i=1;i<n-1;i++){
    if(min>x[i])
      min=x[i];
  }
  printf("%d",min);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;

vector<bool> visited;

void dfs(const Graph &G, int v) {

    visited[v] = true;

    for (auto u : G[v]) { 
        if(visited[u]) {
            continue;
        }
        dfs(G, u);
    }
}

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

    Graph G(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;  y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int ans = 0;
    visited.assign(n, false);
    rep(i, n) {
        if(visited[i]) {
            continue;
        } 
        dfs(G, i);
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 10368
def Com(a, b) :
    list_a = list(a)
    list_b = list(b)
    list_a.reverse()
    list_b.reverse()
    while '*' in list_a :
        list_a.remove('*')
    
    ans = True
    for i in range(len(list_a)) :
        if list_a[i] != list_b[i] :
            ans = False
            break
    return ans

while True :
    n, m = map(int, input().split())
    if n == 0 and m == 0 :
        break

    atari = []
    money = []
    for i in range(n) :
        a, b = input().split()
        atari.append(a)
        money.append(int(b))

    cost = 0
    for i in range(m) :
        s = input()
        for j in range(n) :
            if Com(atari[j], s) == True :
                cost += money[j]
    print(cost)


Measured memory_bytes: 5616