akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  
  int A[200];
  for( int i=0; i<N; i++ ){
    cin >> A[i];
  }
  
  int num = 0;
  while( true ){
    int flg = 0;
    for( int i=0; i<N; i++ ){
      if( (A[i] % 2) != 0 ){
        flg = 1;
        break;
      }
      A[i] /= 2;
    }
  
    if( flg == 0 ){
      num++;
    }
    else{
      break;
    }
  }
  
  cout << num << endl;
}


Measured memory_bytes: 3560
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

int main() {
	int x = 1;
	int i = 1;
	cin >> x;
	while (x != 0) {
		cout << "Case " << i << ": " << x << endl;
		i++;
		cin >> x;
	}
}


Measured memory_bytes: 3020
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll mod=1e9+7;
const int sz=2e5+9;
int n,k;
ll f[sz];
ll ans;

ll add(ll a,ll b){return ((a%mod+b%mod)%mod+mod)%mod;}
ll mul(ll a,ll b){return (a%mod*b%mod)%mod;}

ll modpow(ll b,ll p){
	if(!b) return 0;
	if(!p) return 1;
	ll u=modpow(b,p>>1);
	u=mul(u,u);
	if(p&1) return mul(u,b);
	return u;
}

ll c(ll N,ll K){
	ll num=f[N];
	ll den=mul(f[K],f[N-K]);
	return mul(num,modpow(den,mod-2));
}

ll st_br(ll x, ll y){ // x boxes, y stars
	return c(x+y-1,y);
}

int main(){
	cin>>n>>k;
	f[0]=f[1]=1;
	for(int i=2; i < sz; ++i){
		f[i]=mul(i,f[i-1]);
	}
	for(int m=0; m <= min(n,k); ++m){
		if(m==n) break;
		ll t1=c(n,m);
		ll t2=st_br(n-m,m);
		ans=add(ans,mul(t1,t2));
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#ITP1_7_D
n,m,l=map(int,input().split())
A=[[0 for i in range(m)]for j in range(n)]
B=[[0 for i in range(l)]for j in range(m)]
C=[[0 for i in range(l)]for j in range(n)]
for i in range(n):
  D=list(map(int,input().split()))
  for j in range(m):
    A[i][j]=D[j]
for i in range(m):
  E=list(map(int,input().split()))
  for j in range(l):
    B[i][j]=E[j]

for i in range(n):
  for j in range(l):
    h=int(0)
    for k in range(m):
      h=h+(A[i][k]*B[k][j])
    C[i][j]=h
for i in range(n):
  for j in range(l):
    print(C[i][j],end="")
    if j != l-1:
      print(" ",end="")
  print("")


Measured memory_bytes: 7152
// abc100_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

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

    int D, N;
    cin >> D >> N;

    int ans;
    if (N == 100){
        ans = 101 * pow(100, D);
    } else {
        ans = N * pow(100, D);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

  ll d;
  cin >> d;
  vl c(26);
  rep(i,26) cin>>c[i];
  vvl s(d, vl(26));
  rep(i,d) {
    rep(j,26) {
      cin >> s[i][j];
    }
  }

  vl last(26, 0);
  vl ans(d);
  rep(i, d) {
    ll day = d + 1;
    vl cost(26, 0);
    ll maxcost = -1;
    ll sel = 0;
    rep(j, 26) {
      cost[j] = c[j] * (day - last[j]) + s[i][j];
      if (maxcost < cost[j]) {
        maxcost = cost[j];
        sel = j;
      }
    }
    ans[i] = sel;
    cout << sel + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3288
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] c1 = sc.next().toCharArray();
		char[] c2 = sc.next().toCharArray();
		char[] c3 = sc.next().toCharArray();
		System.out.println(String.valueOf(c1[0]) 
				+ String.valueOf(c2[1]) + String.valueOf(c3[2]));
	}
}


Measured memory_bytes: 21972
#include<stdio.h>
int main(){
	int s[9000],n,m,t,f,i;
	while(scanf("%d%d",&n,&m),n)
		for(i=t=f=1;i<=n+m;i++){
			scanf("%d",&s[i]);
			if(i>n){;
				if(t+=s[t+=s[i]],t>=n&f==1)
					printf("%d\n",i-n,f=0);
			}
		}
}

Measured memory_bytes: 0
#include<stdio.h>
int main (void){
 char s[100];
 scanf("%s",s);
 char *ss=s;
 int c=0;
 while(*ss){
  c++;
  ss++;
 }
 printf("%c%d%c\n",s[0],(c-2),s[c-1]);
 return 0;
}


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

map<int, int> sozai1;
map<int, int> sozai2;
map<int, int> pin;

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

  rep(i, N) {
    // 2ケタから3ケタ
    auto end2 = sozai2.end();
    for (auto itr = sozai2.begin(); itr != end2; ++itr) {
      pin[10 * itr->first + S[i]] = 1;
    }

    // 1ケタから2ケタ
    auto end1 = sozai1.end();
    for (auto itr = sozai1.begin(); itr != end1; ++itr) {
      sozai2[10 * itr->first + S[i]] = 1;
    }
    // 0ケタから1ケタ
    sozai1[S[i]] = 1;
  }
  
  cout << pin.size() << "\n";
  return 0;
}


Measured memory_bytes: 384
e1,e2,e3,e4=map(int,input().split())
if(e1==e2)&((e2==e3==e4)or(e3==e4)):
    print("yes")
elif(e2==e3)&((e3==e1==e4)or(e1==e4)):
    print("yes")
elif(e3==e4)&((e4==e1==e2)or(e1==e2)):
    print("yes")
elif(e4==e1)&((e1==e2==e3)or(e2==e3)):
    print("yes")
else:
    print("no")


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

using namespace std;

int N, Q;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

struct SegmentTree {
private:
    int n;
    vector<lli> node;

public:
    SegmentTree(string &s) {
        int sz = s.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        for(int i=0; i<sz; i++) node[i+n-1]= (1LL<<(s.at(i)-'a'));
        for(int i=n-2; i>=0; i--) node[i] = node[2*i+1]|node[2*i+2];
    }

    void update(int x, char val) {
        x += (n - 1);
        node[x] = (1LL<<(val-'a'));
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2*x+1]|node[2*x+2];
        }
    }

    lli getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        lli vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        lli vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return vl|vr;
    }
};

lli bitCnt(lli num){
    lli cnt=0;
    while(num>0){
        if(num%2)cnt++;
        num/=2;
    }
    return cnt;
}

signed main(){

	lli n;
	string s;
	cin>>n>>s;

	SegmentTree tree(s);

	lli q;
	cin>>q;

	REP(i,0,q){
		lli k;
		cin>>k;
		if(k==1){
			lli index;
			char a;
			cin>>index>>a;
			tree.update(index-1,a);
		}
		else{
			lli x,y;
			cin>>x>>y;
			x--,y--;
            lli num = tree.getmin(x,y+1);
            cout<<bitCnt(num)<<endl;
		}
	}

	return 0;
}

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

class Program
{
    static void Main()
    {
        C();
    }

    static void C()
    {
        // 入力
        var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x));
        var N = NM.ElementAt(0);
        var M = NM.ElementAt(1);
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x) - 1).ToArray();
        var X = new long[M];
        var Y = new long[M];
        for (int i = 0; i < M; i++)
        {
            var XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x) - 1);
            X[i] = XY.ElementAt(0);
            Y[i] = XY.ElementAt(1);
        }

        // iが書かれたボールの個数
        var num = new long[N];
        for (int i = 0; i < N; i++)
        {
            num[A[i]]++;
        }

        // xを覆う区間の個数
        var range = new long[N];
        for (int i = 0; i < N; i++)
        {
            for (long j = i; j > i - num[i] && j >= 0; j--)
            {
                range[j]++;
            }
        }

        // 覆われていない場所の数
        long count = 0;
        for (int i = 0; i < N; i++)
        {
            if (range[i] == 0) count++;
        }

        // 出力部
        for (int i = 0; i < M; i++)
        {
            // 更新部
            if (A[X[i]] - num[A[X[i]]] + 1 >= 0)
            {
                if (range[A[X[i]] - num[A[X[i]]] + 1] > 0) 
                {
                    range[A[X[i]] - num[A[X[i]]] + 1]--;
                    if (range[A[X[i]] - num[A[X[i]]] + 1] == 0) count++;
                }
            }
            num[A[X[i]]]--;

            if (Y[i] - num[Y[i]] >= 0)
            {
                range[Y[i] - num[Y[i]]]++;
                if (range[Y[i] - num[Y[i]]] == 1) count--;
            }
            num[Y[i]]++;

            A[X[i]] = Y[i];

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 41840
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#define SIZE 100005
#define MX 35

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

int A[SIZE];
int dp[2][MX];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	int pos=0;
	memset(dp[pos],-1,sizeof(dp[pos]));
	dp[pos][0]=0;
	for(int i=0;i<n;i++)
	{
		int cnt=0,now=1;
		while(now<A[i]) now*=2,cnt++;
		pos^=1;
		memset(dp[pos],-1,sizeof(dp[pos]));
		for(int j=0;j<=cnt;j++)
		{
			if(dp[pos^1][j]==-1) continue;
			int add=cnt-j;
			if(add>0||now==A[i])
			{
				if(dp[pos][cnt]==-1) dp[pos][cnt]=dp[pos^1][j]+add;
				else dp[pos][cnt]=min(dp[pos][cnt],dp[pos^1][j]+add);
			}
			else if(j>0)
			{
				if(dp[pos][cnt-1]==-1) dp[pos][cnt-1]=dp[pos^1][j]+add;
				else dp[pos][cnt-1]=min(dp[pos][cnt-1],dp[pos^1][j]+add);
			}
		}
		for(int j=MX-1;j>0;j--)
		{
			if(dp[pos][j]!=-1)
			{
				if(dp[pos][j-1]==-1) dp[pos][j-1]=dp[pos][j];
				else dp[pos][j-1]=min(dp[pos][j-1],dp[pos][j]);
			}
		}
	}
	printf("%d\n",dp[pos][0]);
	return 0;
}


Measured memory_bytes: 640
use std::io::*;

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let v = buf.split_whitespace().collect::<Vec<_>>();
    println!(
        "{}",
        if &v[1][..v[1].len() - 1] == v[0] {
            "Yes"
        } else {
            "No"
        }
    )
}


Measured memory_bytes: 2132
package main

import (
	"fmt"
)

func main() {
	var n, st int
	fmt.Scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n-1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
		st += b[i]
	}
	for i := 0; i < n-1; i++ {
		fmt.Scan(&c[i])
	}
	for i := 1; i < n; i++ {
		if a[i] == a[i-1]+1 {
			st += c[a[i]-2]
		}
	}
	fmt.Println(st)
}


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

int main(){
  ll r, d, x;
  cin >> r >> d >> x;
  
  for(int i = 0; i < 10; i++){
      x = r * x - d;
      cout << x << endl;
  }
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
namespace io
{
	//#define USE_FEAD_IO
#ifdef USE_FEAD_IO
#define BUF_SIZE 5000010
	char buf[BUF_SIZE]; int cur = BUF_SIZE; FILE *in = stdin;
	inline char gnc()
	{
		if (cur == BUF_SIZE) { fread(buf, BUF_SIZE, 1, in); cur = 0; }
		return buf[cur++];
	}
#else
	inline char gnc()
	{
		return (char)getchar();
	}
#endif
	template<typename T>
	inline void gi(T &dx)
	{
		dx = 0;
		int yc = gnc();
		bool nega = false;
		while (yc < '0' || yc > '9') { nega = (yc == '-' ? true : nega); yc = gnc(); }
		while (yc >= '0' && yc <= '9') { dx = (T)(dx * 10 + yc - '0'); yc = gnc(); }
		if (nega) { dx = -dx; }
	}
	void gc(char &a)
	{
		do a = gnc(); while (!isgraph(a));
	}
	void gss(char *jc)
	{
		*jc = gnc();
		while (!isgraph(*jc)) *jc = gnc();
		while (isgraph(*jc)) *++jc = gnc();
		*jc = 0;
	}
#if __cplusplus >= 201103l || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103l)
	template<typename T, typename ...Args> inline void gi(T &a, Args &...args)
	{ gi(a); gi(args...); }
#else
	template<typename t1, typename t2> inline void gi(t1 &a, t2 &b) { gi(a); gi(b); }
	template<typename t1, typename t2, typename t3> inline void gi(t1 &a, t2 &b, t3 &c) { gi(a); gi(b); gi(c); }
	template<typename t1, typename t2, typename t3, typename t4> inline void gi(t1 &a, t2 &b, t3 &c, t4 &d) { gi(a); gi(b); gi(c); gi(d); }
	template<typename t1, typename t2, typename t3, typename t4, typename t5> inline void gi(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) { gi(a); gi(b); gi(c); gi(d); gi(e); }
#endif
}
using namespace io;

typedef long long ll;

string a;
map<char, ll> g;
int main()
{
	ll ans = 1;
	cin >> a;
	for (int i = 1; i <= a.size(); ++i) {
		char c = a[i - 1];
		ans += (i - 1);
		ans -= g[c];
		++g[c];
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 640
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	Map<String, Integer> map = new HashMap<>();
    	for (int i = 0; i < N; i++) {
    		String s = sc.next();
    		if (map.containsKey(s)) {
    			map.put(s, map.get(s)+1);
    		} else {
    			map.put(s, 1);
    		}
    	}
    	int M = sc.nextInt();
    	for (int i = 0; i < M; i++) {
    		String s = sc.next();
    		if (map.containsKey(s)) {
    			map.put(s, map.get(s)-1);
    		} else {
    			map.put(s, -1);
    		}
    	}
    	int max = 0;
    	for (String key : map.keySet()) {
    		int value = map.get(key);
    		if (max < value) {
    			max = value;
    		}
    	}
    	System.out.println(max);
    }
}

Measured memory_bytes: 21716
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

  	Int A, B; cin >> A >> B;
    cout << (A-1)*(B-1) << endl;
}


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

int main(){
	int i,ave,tmp,sum = 0;

	for(i = 0;i < 5;i++){
		cin>>tmp;
		if(tmp < 40)
			sum += 40;
		else
			sum += tmp;
	}
	ave = sum/5;
	cout<<ave<<endl;
	return 0;
}

Measured memory_bytes: 1160
// AOJ Volume 1 Problem 0197 Greatest Common Divisor: Euclidean Algorithm

#include <stdio.h>

int main(void)
{
    int x, y;
    int tmp;
    int step;
    
    while (1){
        scanf("%d%d", &x, &y);
        if (x == 0 && y == 0){
            break;
        }
        
        if (x < y){
            tmp = x;
            x = y;
            y = tmp;
        }
        
        step = 0;
        do {
            x %= y;
            
            tmp = x;
            x = y;
            y = tmp;

            step++;
        } while (y != 0);
        
        printf("%d %d\n", x, step);
   }
   return (0);
}

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

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  for(int i=a;i<=b;i++){
    int x=i%10, y=i/10000%10;
    int z=i/10%10, w=i/1000%10;
    if(x==y&&z==w)ans++;
  }
  cout << ans << endl;
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i,N){
    cin >> S[i];
  }
  sort(S.begin(),S.end());
  S.push_back("#");
  vector<pair<int,string>> p;

  int c = 1;
  rep(i,N){
    if(S[i] == S[i+1]){
      c++;
    }
    else{
      c = -c;
      p.push_back(make_pair(c,S[i]));
      c = 1;
    }
  }
  sort(p.begin(),p.end());
  int t = p[0].first;
  rep(i,p.size()){
    if(p[i].first == t) cout << p[i].second << endl;
  }

}

Measured memory_bytes: 20708
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
#define mp make_pair

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=;



int main(){
	int N;
	cin>>N;
	int gr=0;
	bool di[31];
	rep(i,31)di[i]=false;
	set<int, greater<int> > st;
	rep(_,N){
		int a;
      	cin>>a;
		gr^=a;
		int k=0;
		while(true){
			if((a>>k) & 1){
				di[k]=true;
				break;
			}
			k++;
		}
	}
	if(gr==0){
		cout<<0<<endl;
		return 0;
	}
	
	int t=30;
	while(t>=0){
		if((gr>>t)&1)break;
		t--;
	}
	int ans=0;
	for(int i=30; i>=0; i--)if(di[i]){
		if(i==t){
			ans++;
			gr^=(1<<(t+1))-1;
		}
		else if(i>t) continue;
		else{
			ans=-1;
			break;
		}
		if(gr==0)break;
		while(t>=0){
			if((gr>>t)&1)break;
			t--;
		}
	}
	if(gr!=0)ans=-1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;

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

    ll H, W;
    cin >> H >> W;

    ll ans = INF;

    for (ll h = 1; h <= H; h++) {
        ll w = W / 2;
        ll A = h * W;
        ll B = (H - h) * w;
        ll C = (H - h) * (W - w);
        ll Smax = max(A, max(B, C));
        ll Smin = min(A, min(B, C));
        ans = min(ans, Smax - Smin);
    }

    for (ll h = 1; h <= H; h++) {
        ll A = h * W;
        ll rest = H - h;
        ll B = rest / 2 * W;
        ll C = (rest + 1) / 2 * W;
        ll Smax = max(A, max(B, C));
        ll Smin = min(A, min(B, C));
        ans = min(ans, Smax - Smin);
    }

    for (ll w = 1; w <= W; w++) {
        ll h = H / 2;
        ll A = w * H;
        ll B = (W - w) * h;
        ll C = (W - w) * (H - h);
        ll Smax = max(A, max(B, C));
        ll Smin = min(A, min(B, C));
        ans = min(ans, Smax - Smin);
    }

    for (ll w = 1; w <= W; w++) {
        ll A = w * H;
        ll rest = W - w;
        ll B = rest / 2 * H;
        ll C = (rest + 1) / 2 * H;
        ll Smax = max(A, max(B, C));
        ll Smin = min(A, min(B, C));
        ans = min(ans, Smax - Smin);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
def solve():
    s = input()
    c0 = s[0] == "A"
    c1 = s[2:-1].count("C") == 1
    c2 = sum([1 for c in s if c.isupper()]) == 2
    return "AC" if c0 and c1 and c2 else "WA"


if __name__ == "__main__":
    print(solve())


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

int main() {
  int A, B, X;
  cin >> A >> B >> X;

  int ans = 100000;
  for (int i = 0; i <= X / 1000 + 1; i++) {
    for (int j = 0; j <= X / 500 + 1; j++) {
      if (1000 * i + 500 * j >= X) {
        ans = min(ans, A * i + B * j);
      }
    }
  }

  cout << ans << endl;
}


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


int main(void){
  int n,t,i,j;
  ll a[403]={},dp[403][403]={},s;
  
  cin >> n;
  for (i=1;i<=n;i++) cin >> a[i];
  
  for (i=1;i<=n;i++) a[i]+=a[i-1];
  
  for (t=2;t<=n;t++){
    for (i=1;i+t<=n+1;i++){
      s=1e13;
      for (j=i+1;j<i+t;j++){
        s=min(s,dp[i][j]+dp[j][i+t]+a[i+t-1]-a[i-1]);
      }
      dp[i][i+t]=s;
    }
  }
  
  cout << dp[1][n+1] << endl;
  
  return 0;
}

Measured memory_bytes: 1536
//A - Security
#include<stdio.h>

int main()
{
	bool flag=true;
	char c,ci;
	scanf("%c",&c);
	scanf("%c",&ci);
	if(ci==c)flag=false;
	scanf("%c",&c);
	if(ci==c)flag=false;
	scanf("%c",&ci);
	if(ci==c)flag=false;
	if(flag)
	printf("Good");
	else
	printf("Bad");
	return 0;
}

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

vector<int> v[100100];
int sum;

signed main ( ) {

    int n, m;
    cin >> n >> m;
    for ( int i = 0; i < n; i++ ) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }

    priority_queue<int> p;
    for ( int i = 1; i <= m; i++ ) {
        for ( int j : v[i] ) {
            p.push(j);
        }
        if ( !p.empty() ) {
            sum += p.top();
            p.pop();
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 5632
#include <iostream>

using namespace std;

int main() {
	int m, d; cin >> m >> d;
	int ans = 0;
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= d; ++j) {
			if (j / 10 < 2 || j % 10 < 2) continue;
			if (i == (j / 10) * (j % 10)) ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Yes() std::cout << "Yes" << std::endl
#define No() std::cout << "No" << std::endl
#define Say(s) std::cout << s << std::endl
const ll MOD = 1000000007;
const ll INF = 1061109567;

/*ll yakusu(const ll& target)
{
    std::vector<long long> ret;
    for (long long i = 1; i * i <= target; i++) {
        if (target % i == 0) {
            ret.push_back(i);
            if (i * i != target)
                ret.push_back(target / i);
        }
    }
    ll ans = ret.size();
    return ans;
}*/

int main()
{
    ll n;
    std::cin >> n;
    ll ans = 0;
    for (ll i = 1; i < n; ++i) {
        ans += (n - 1) / i;
    }
    Say(ans);
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var ans = true;


		var lastWord = Console.ReadLine();
		var old = new HashSet<string>();
		old.Add(lastWord);
		for (var i = 1; i < n && ans; ++i) {
			var newyork = Console.ReadLine();
			if (old.Contains(newyork) || newyork.First() != lastWord.Last()) {
				ans = false;
			} else {
				old.Add(newyork);
				lastWord = newyork;
			}
		}

		Console.WriteLine(ans ? "Yes" : "No");

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll mod = 1e9 + 7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> s, t;
  rep(i,n) {
    cin >> a[i];
    if (a[i] < 0) t.push_back(a[i]);
    else s.push_back(a[i]);
  }
 
  int S = s.size();
  int T = t.size();
  bool ok = false;
  if (S > 0) {
    if (n == k) ok = (T%2==0);
    else ok = true;
  } else {
    ok = (k%2==0);
  }
 
  ll ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i,k) ans *= a[i],ans %= mod;
  } else {
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (k%2 == 1) {
      ans *= s.back();
      s.pop_back();
    }
    vector<ll> p;
    while (s.size() >= 2) {
      ll x = s.back(); s.pop_back();
      x *= s.back(); s.pop_back();
      p.push_back(x);
    }
    while (t.size() >= 2) {
      ll x = t.back(); t.pop_back();
      x *= t.back(); t.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i,k/2) ans *= p[i]%mod,ans %= mod;
  }
 
  cout << (ans + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 6428
H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(list(input()))
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    if 0 <= i + k < H and 0 <= j + l < W and S[i+k][j+l] == '#':
                        cnt += 1
            S[i][j] = str(cnt)
for i in range(H):
    print(''.join(S[i]))

Measured memory_bytes: 9160
#include<stdio.h>
int main(void){
int num[3],i,j,key;
scanf("%d %d %d",&num[0],&num[1],&num[2]);
for(i=0;i<3;i++){if(num[i]<1||num[i]>10000) return 0;}
for(i=1;i<3;i++){
key=num[i];
for(j=i-1;j>=0;j--){
if(key>=num[j]){
num[j+1]=key;
break;
}
else{
num[j+1]=num[j];
} }
if(j<0){
num[0]=key;
}}
for(i=0;i<3;i++){
printf("%d",num[i]);
if(i<=1)
printf(" ");
}
printf("\n");
return 0;
}

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

vector<int> v;

void draw(){
    for(vector<int>::iterator it = v.begin(); it != v.end(); it++){
        if( it != v.begin() ) cout << ' ';
        cout << *it;
    }
    cout << endl;
}

void rec(int h, int b){
    v.push_back(h);
    if( b == 0 ){
        draw();
    }
    for(int i = min(h, b); i > 0; i--) rec(i, b-i);
    v.pop_back();
}

int solve(int n){
    for(int i = n; i > 0; i--){
        rec(i, n-i);
    }
}

int main(){
    int n;
    while( true ){
        cin >> n;
        if( !n ) break;
        solve( n );
    }
    return 0;
}

Measured memory_bytes: 1216
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

//0-index 抽象化半開区間遅延セグツリー
template<typename T, typename E>
class segment_tree{
    typedef function<T(T,T)> F; //要素に適用する演算
    typedef function<T(T,E)> G; //作用素の適用
    typedef function<E(E,E)> H; //作用素の合成
    typedef function<E(E,int)> P;
private:
    int num_of_elm_;
    vector<T> dat_, lazy_;
    F f_;
    G g_;
    H h_;
    P p_;
    T ident_;
    E op_ident_;
public:
    segment_tree(int n, F f, G g, H h, P p, T ident, E op_ident):f_(f), g_(g), h_(h), p_(p), ident_(ident), op_ident_(op_ident){
        num_of_elm_ = 1;
        while(num_of_elm_<n)num_of_elm_*=2;
        dat_ .resize(2*num_of_elm_,ident);
        lazy_.resize(2*num_of_elm_,op_ident);
    }

    void eval(int k, int len){
        if(lazy_[k] == op_ident_)return ;

        if(k<num_of_elm_){
            lazy_[k*2]=h_(lazy_[k*2], lazy_[k]);
            lazy_[k*2+1]=h_(lazy_[k*2+1], lazy_[k]);
        }
        dat_[k] = g_(dat_[k],p_(lazy_[k], len));
        lazy_[k] = op_ident_;
    }
    
    T update(int L, int R, int val, int l=0, int r=0, int k=1){
        if(k==1)r = num_of_elm_;
        
        eval(k,r-l);
        if(r<=L || R<=l)return dat_[k];
        else if(L<=l && r<=R){
            lazy_[k] = h_(lazy_[k], val);
            return g_(dat_[k], p_(lazy_[k], r-l));
        }
        else{
            return dat_[k] = f_(update(L,R,val,l,(l+r)/2,k*2), update(L,R,val,(l+r)/2,r,k*2+1));
        }

    }
    
    T query(int L, int R,int l=0,int r=0, int k=1){
        if(k==1)r = num_of_elm_;

        eval(k,r-l);
        if(r<=L || R<=l)return ident_;
        else if(L<=l && r<=R){
            return dat_[k];
        }
        else{
            return f_(query(L,R,l,(l+r)/2,k*2), query(L,R,(l+r)/2,r,k*2+1));
        }
    }
};

int main(){
    int n,q;
    cin>>n>>q;
    auto f = [](int a, int b){return min(a,b);};
    auto g = [](int a, int b){return b;};
    auto h = g;
    auto p = [](int a, int len){return a;};
    segment_tree<int,int> st(n, f, g, h, p, (1LL<<31)-1, -1);
    rep(i,q){
        int com,x,y;
        cin>>com>>x>>y;
        if(com==0){
            st.update(x,x+1,y);
        }else{
            cout<<st.query(x,y+1)<<endl;
        }
    }
}




Measured memory_bytes: 4956
from itertools import accumulate
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    acc_A = [0] + list(accumulate(A))
    acc_B = [0] + list(accumulate(B))

    ans = 0
    b_ind = M
    for i, a in enumerate(acc_A):
        remain = K - a
        if remain < 0:
            break
        while acc_B[b_ind] > remain:
            b_ind -= 1

        tmp = i + b_ind
        ans = max(ans, tmp)
   
    print(ans)
       


if __name__ == "__main__":
    main()


Measured memory_bytes: 50468
### ----------------
### ここから
### ----------------

import sys
import math
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    a,b,x=map(int, readline().rstrip().split())
    if x <= a*a*b/2:
        l = x*2/b/a
        print(math.degrees(math.atan(b/l)))
        return
    l = (2*x)/(a*a)-b
    print(math.degrees(math.atan((b-l)/a)))
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

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

    return 0;
    
}


Measured memory_bytes: 3076
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      if (c>=a&&c<=b) {
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
}
}


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

int main(void)
{
	int x, y,z;

	while (1)
	{
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		if (x > y)
		{
			z = x;
			x = y;
			y = z;
		}
		cout << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 100005;

int n, ans, m;

bool check(int k) {
    m = n;
    while (m%k == 0) m /= k;
    return m%k == 1;
}

pls give {
    AC;
    cin >> n;
    for (int i=1; i*i<=n; i++) {
        if (n%i == 0) {
            if (i != 1 and check(i)) ans++;
            if (i*i != n and check(n/i)) ans++;
        }
    }
    // cout << ans << nl;
    for (int i=1; i*i<=(n-1); i++) {
        if ((n-1)%i == 0) {
            if (i != 1 and check(i)) {
                ans++;
            }
            if (i*i != (n-1) and check((n-1)/i)) {
                ans++;
            }
        }
    }
    cout << ans << nl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>


using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll n; cin >> n;
	ll sm = 0;
	vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i], sm += a[i];
	sm /= 2;
	ll s2 = a[0];
	for (int i = 1; i < n; i += 2) s2 += a[i];
	s2 -= sm;
	vector<ll> x(n); x[0] = s2;
	for (int i = 1; i < n; i++) x[i] = a[i] - x[i - 1];
	vector<ll> res(n); for (int i = 1; i < n; i++) res[i] = x[i - 1] * 2;
	res[0] = x.back() * 2;
	for (int i = 0; i < n; i++) cout << res[i] << " \n"[i + 1 == n];
	return 0;
}

Measured memory_bytes: 5516
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,q;
    cin>>n>>k>>q;
    int x[q];
    map<int,int>mp;

    for(int i=0;i<q;i++)
    {
        cin>>x[i];
       mp[x[i]]++;
    }

    for(int i=1;i<=n;i++)
    {
        if((mp[i]+k-q)>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    string S ,T;
    cin >> S >> T;
    ll ans = 0;
    rep(i,S.size())
        if(S[i]!=T[i])ans ++;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3892
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll t=1,h,w,n,x=0,y=0,z=0,min=100000000000,k,ans=0;
    string s1,s2,s3;
    cin >> n >> k;
    ans = k;
    for(int i=0;i<n-1;i++){
        ans *= (k-1);
    }
    cout << ans <<endl; 
    return 0;
}


Measured memory_bytes: 256
import numpy as np
N, L = map(int, input().split())
zenbu=[]
for i in range(N):
  aj=L+i
  zenbu.append(aj)
aji=sum(zenbu)
zenbu_abs=np.abs(zenbu)
a=zenbu_abs.argmin()


eat=zenbu[a]
kotae=aji-eat
print(kotae)

Measured memory_bytes: 12508
#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 n = s.size();
  reverse(s.begin(), s.end());
  int tmp =0;
  int x = 1;int m = 2019;
  int ans=0;
  map <int,int> mp;
  rep(i,n){
    if(i==0){
      mp[tmp]++;
      tmp=(s[i]-'0')*x;
      tmp%=m;
      if(mp[tmp]!=0)ans+=mp[tmp];
      x=x*10%m;
      mp[tmp]++;
    }
    else{
      tmp=tmp+(s[i]-'0')*x;
      tmp%=m;
      if(mp[tmp]!=0)ans+=mp[tmp];
      x=x*10%m;
      mp[tmp]++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3752
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] a = new long[n + 1];
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();

        long[][][] dp = new long[2][n + 1][2];
        dp[0][0][1] = -(1L << 60);
        int x = 1;
        for (int i = 1; i < n; i++) {
            dp[x][i][0] = Math.max(dp[1 - x][i - 1][0] + a[i], dp[1 - x][i - 1][1] - a[i]);
            dp[x][i][1] = Math.max(dp[1 - x][i - 1][0] - a[i], dp[1 - x][i - 1][1] + a[i]);
//            debug(dp[x][i]);
            x = 1 - x;
        }
        x = 1 - x;
        long ans = Math.max(dp[x][n - 1][0] + a[n], dp[x][n - 1][1] - a[n]);
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 57740
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	string s;cin>>s;
	if(s=="zyxwvutsrqponmlkjihgfedcba"){
		puts("-1");return 0;
	}
	else if(s.size()!=26){
		set<char>se;
		for(char c:s){
			se.insert(c);
		}
		rep(i,26){
			if(!se.count('a'+i)){
				s+=(char)('a'+i);
				break;
			}
		}
		cout<<s<<endl;
	}
	else{
		set<char>se;
		for(int i=s.size()-1;i>=0;i--){
			se.insert(s[i]);
			if(s[i]<*se.rbegin()){
				cout<<s.substr(0,i)+*se.upper_bound(s[i])<<endl;
				return 0;
			}
		}
	}
}

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

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second

const int N = 105;
const int K = 1e5 + 5;
const int inf = 1e9 + 5;

pii a[N];
int dp[K];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n, w;
    cin >> n >> w;
    for (int i=1; i<=n; i++) cin >> a[i].fi >> a[i].se;
    for (int i=0; i<K; i++) dp[i] = inf;
    dp[0] = 0;
    for (int i=1; i<=n; i++) {
        for (int j=K-1; j>=0; j--) {
            if (dp[j] < inf) dp[j + a[i].se] = min(dp[j + a[i].se], dp[j] + a[i].fi);
        }
    }
    int ans = 0;
    for (int i=0; i<K; i++) {
        if (dp[i] <= w) ans = i;
    }
    cout << ans << "\n";
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;

	if((a[a.size() - 1] == b[0])
		&& (b[b.size() - 1] == c[0]))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]

for i in a:
    result = []
    for j in zip(*b):
        result.append(sum([a * b for (a,b) in zip(i, j)]))
    print(*result)

Measured memory_bytes: 6588
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main()
{
    int h,w,k,cnt = 1;
    cin >> h >> w >> k;
    vector<vector<char> > s(h,vector<char>(w));
    vector<vector<int> > ans(h,vector<int>(w));
    vector<bool> c(h,false);
    rep0(i, h)rep0(j, w){
        cin >> s[i][j];
        if(s[i][j] == '#')c[i] = true;
    }
    rep0(i, h){
        bool f = false;
        rep0(j, w){
            if(!c[i] && i != 0){
                ans[i][j] = ans[i - 1][j];
            }else{
                if(s[i][j] == '#'){
                    if(!f)--cnt;
                    ++cnt;
                    f = true;
                }
                ans[i][j] = cnt;
            }
        }
        if(c[i])++cnt;
    }
    int cnt2 = 0;
    rep0(i, h){
        if(c[i]){
            cnt2 = (int)i;
            break;
        }
    }
    rep0(j, cnt2)rep0(i, w)ans[j][i] = ans[cnt2][i];
    
    rep0(i, h){
        rep0(j, w)cout << ans[i][j] << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    int l,r,d;
    cin>>l>>r>>d;
    l-=1;
    int x=l/d;
    int y=r/d;
    cout<<y-x;
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3000005;
const int maxm = maxn*2;
const int inf = 0x3f3f3f3f;
int n,a[maxn],b[maxn],ta[maxn],tb[maxn];
int fa[maxn];
int date[maxn];
int vis[maxn];
int fi(int x)
{
    if(fa[x]==x) return x;
    else return fa[x] = fi(fa[x]);
}
void uni(int x,int y)
{
    int xi = fi(x),yi = fi(y);
    if(xi!=yi){
        fa[xi] = yi;
    }
    return;
}
map<int,int>mp;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>a[i]; a[n+1]^=a[i];
        mp[a[i]]++;
    }
    mp[a[n+1]]++;
    for(int i = 1;i<=n;i++){
        cin>>b[i]; b[n+1]^=b[i];
        mp[b[i]]--;
    }
    mp[b[n+1]]--;
    for(int i = 1;i<=n+1;i++){
        if(mp[a[i]]!=0) {
            cout<<-1<<endl; return 0;
        }
    }
    int ans = 0,cnt = 0;
    n ++;
    for(int i = 1;i<=n;i++){
        if(a[i]!=b[i]||(i==n)){
            date[++cnt] = a[i];
            date[++cnt] = b[i];
            if(i<n) ans++;
        }
    }
    if(ans==0){
        cout<<0<<endl;return 0;
    }
    sort(date+1,date+1+cnt);
    cnt = unique(date+1,date+1+cnt) - date - 1;
    for(int i = 1;i<=cnt;i++) fa[i] = i;
    for(int i = 1;i<=n;i++){
        if(a[i]!=b[i]){
            a[i] = lower_bound(date+1,date+cnt+1,a[i]) - date;
            b[i] = lower_bound(date+1,date+cnt+1,b[i]) - date;
            if(!vis[a[i]]) vis[a[i]] = 1;
            if(!vis[b[i]]) vis[b[i]] = 1;
            uni(a[i],b[i]);
        }
    }
    for(int i = 1;i<=cnt;i++) if(fa[i]==i) ans++;
    cout<<ans - 1<<endl;
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

const int N = 2e5 + 100;
vi f(N,-1), s(N,1);

int Find(int x)
{
	stack<int> stk;
	while(f[x] != -1) stk.push(x), x = f[x];
	while(!stk.empty()) f[stk.top()] = x, stk.pop();
	return x;
}

int main()
{
	fastIO;

	int n, m; cin >> n >> m;
	int ans = 1;

	for(int i = 0; i < m; i++)
	{
		int a, b; cin >> a >> b;
		a = Find(a); b = Find(b);
		if(a == b) continue;
		f[a] = b; s[b] += s[a];
		ans = max(ans,s[b]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4664