akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <map>
#include <memory>
#include <stack>
#include <vector>

using namespace std;

int main()
{
    auto pv = [](const vector<int>& v) {
        for (size_t i = 0; i < v.size(); ++i) {
            printf("%2d", v[i]);
            if (i != v.size() - 1) {
                putchar(' ');
            }
        }
        putchar('\n');
    };
    auto pm = [pv](const vector<vector<int>>& m) {
        for (auto&& c : m) {
            pv(c);
        }
    };

    while (true) {
        int n;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }

        vector<int> ps;
        for (auto i = 0; i < n - 1; ++i) {
            int p;
            scanf("%d", &p);
            ps.push_back(p);
        }
        vector<int> ds;
        for (auto i = 0; i < n - 1; ++i) {
            int p;
            scanf("%d", &p);
            ds.push_back(p);
        }

        vector<vector<int>> m;
        m.resize(n);
        for (auto&& c : m) {
            c.resize(n, 0);
        }
        for (auto i = 0; i < n - 1; ++i) {
            m[i + 1][ps[i] - 1] = ds[i];
            m[ps[i] - 1][i + 1] = ds[i];
        }
        // pm(m);

        vector<int> children(m.size());
        for (auto i = 0; i < n; ++i) {
            auto cc =
                count_if(begin(m[i]), end(m[i]), [](int a) { return a != 0; });
            children[i] = cc;
        }
        vector<bool> v(m.size());
        // vector<int> paths;
        // map<pair<int, int>, int> memo;

        int sum = 0;
        function<pair<int, int>(int)> f = [&sum, &children, &m, &f, &v](int i) {
            v[i] = true;
            if (children[i] == 1) {
                return make_pair(0, -1);
            }
            int max_ = 0;
            int idx = -1;
            for (size_t j = 0; j < m.size(); ++j) {
                if (v[j] || m[i][j] == 0) {
                    continue;
                }
                auto r = f(j);
                sum += m[i][j];
                if (r.second == -1) {
                    continue;
                }
                sum += m[i][j] * 2;
                r.first += m[i][j];
                // printf("%d, %d\n", r.first, r.second);
                if (r.first > max_) {
                    max_ = r.first;
                    idx = r.second;
                }
            }
            if (idx == -1) {
                return make_pair(0, i);
            }
            // printf("return %d, %d\n", max_, idx);
            return make_pair(max_, idx);
        };

        auto r =
            f(distance(begin(children), find_if(begin(children), end(children),
                                                [](int n) { return n != 1; })));
        // printf("final %d, %d\n", r.first, r.second);
        for (auto&& i : v) {
            i = false;
        }
        auto rr = f(r.second);
        // printf("final %d, %d\n", rr.first, rr.second);
        printf("%d\n", sum / 2 - rr.first);
    }
}

Measured memory_bytes: 5080
from collections import deque

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


def bfs(si, sj):
    offset = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    INF = 10 ** 9 + 7
    d = [[INF] * W for _ in range(H)]
    d[si][sj] = 0 if X[si][sj] == "." else INF
    q = deque()
    q.append((si, sj))
    while q:
        u, v = q.popleft()
        for i, j in offset:
            if (0 <= u + i < H and 0 <= v + j < W and X[u + i][v + j] == "."
                    and d[u + i][v + j] > d[u][v] + 1):
                d[u + i][v + j] = d[u][v] + 1
                q.append((u + i, v + j))

    res = 0
    for x in d:
        for v in x:
            if v < INF:
                res = max(res, v)

    return res


ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, bfs(i, j))

print(ans)


Measured memory_bytes: 74912
N,M = gets.split.map &:to_i
S = {}
M.times {
  a,b = gets.split.map &:to_i
  cs = gets.split.map &:to_i
  c = cs.map{ |c| 1 << (c-1) }.reduce(:+)
  S[c] ||= a
  S[c] = [S[c], a].min
}
T = S.dup
S.each{ |s,cs|
  T.keys.each{ |t|
    ct = T[t]
    u = (s | t)
    cu = cs + ct
    next if T[u] && cu >= T[u]
    T[u] = cu
  }
}
p T[(1 << N) - 1] || -1

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

long long f(long long a) {
	if (a <= 0)
		return 0;
	long long ans = (a+1)/2%2;
	int bit = 0;
	while((1ll<<bit+1) <= a)
		bit++;
	// cout<<"Probe: bit="<<bit<<" ans="<<ans<<endl;
	for (long long probe; a>1 && bit>0; bit--) {
		probe = (1ll<<bit);
		// cout<<"\ta="<<a<<" bit="<<bit<<" probe="<<probe<<endl;
		if (a >= probe) {
			if (bit>=0 && (a-probe+1)%2 != 0)
				ans |= (1ll<<bit);
			a -= probe;
		}
		// cout<<"\t"<<ans<<endl;
	}
	return ans;
}
int main() {
	long long a, b;
	cin>>a>>b;
	cout<<(f(a-1)^f(b))<<endl;
	return 0;
}

Measured memory_bytes: 256
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  const N = input[0].trim().split(' ').map(Number)[0];
  const C = input[0].trim().split(' ').map(Number)[1];
  const K = input[0].trim().split(' ').map(Number)[2];
  const T = input.slice(1, input.length).map(Number);
  T.sort((a, b) => a - b);

  let s = 0;
  let cnt = 0;
  let ret = 1;
  for(let i=1; i<N; i++){
    if(T[s] <= T[i] && T[i] <= T[s] + K){
      cnt += 1;
      if(cnt === C){
        ret +=1;
        s = i;
        cnt = 0;
      }
    } else {
      ret += 1;
      s = i;
      cnt = 0;
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 28500
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0

for i in range(n):
    for j in range(1,k+1):
        if 0<=i-j<n:
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])

Measured memory_bytes: 55392
(let ((a (read))
      (b (read)))
  (loop :named main
        :for x :from 1 :to 1000
        :if (and (= (floor (* x 0.08)) a)
                 (= (floor (* x 0.1)) b))
        :do (progn
              (format t "~A~%" x)
              (return-from main))
        :finally (format t "-1~%")))


Measured memory_bytes: 24444
#include <iostream>
#include <vector>

using lli=long long int;
const lli mod=1000000007;

struct ds{
  lli data[4];
  ds() : data{} {}
  lli get(bool y, bool x){
    return data[y*2+x];
  }
};

int main(){
  lli L, R;
  std::cin >> L >> R;

  lli dp[62][4] = {};

  lli di = 1LL<<60;
  bool t0 = true, t1 = true;
  for(int i = 60; i >= 0; i--){
    if(t0){
      if(R&di){
        t0 = false;
        if(L&di){
          t1 = false;
          dp[i][0] += 1;
        }else{
          dp[i][1] += 1;
        }
      }
      di >>= 1;
      continue;
    }
    if(t1){
      if(L&di){
        t1 = false;
        dp[i][2] += 1;
      }else{
        dp[i][3] += 1;
      }
    }
    dp[i][1] += dp[i+1][1];
    dp[i][2] += dp[i+1][2];
    dp[i][3] += 3*dp[i+1][3];
    if(R&di){
      dp[i][1] += dp[i+1][1];
      dp[i][3] += dp[i+1][1];
    }
    if((L&di) == 0){
      dp[i][2] += dp[i+1][2];
      dp[i][3] += dp[i+1][2];
    }
    if((R&di) && (L&di) == 0){
      dp[i][1] += dp[i+1][0];
      dp[i][2] += dp[i+1][0];
    }
    if((R&di) || (L&di) == 0){
      dp[i][0] += dp[i+1][0];
    }
    dp[i][0] %= mod;
    dp[i][1] %= mod;
    dp[i][2] %= mod;
    dp[i][3] %= mod;

    di >>= 1;
  }

  std::cout << (dp[0][0]+dp[0][1]+dp[0][2]+dp[0][3])%mod << std::endl;

  return 0;
}



Measured memory_bytes: 256
s = str(input())

date = [int(s[:2]), int(s[2:])]

if 1 <= date[0] <= 12 and 1 <= date[1] <= 12:
    print('AMBIGUOUS')
elif 1 <= date[1] <= 12:
    print('YYMM')
elif 1 <= date[0] <= 12:
    print('MMYY')
else:
    print('NA')

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

int n,m,p,ridx;
map<string,vector<int> > derived;
map<string,string> var;
map<string,int> idx;
string in;
vector<int> rvalue;

bool factor(int idx);
bool term(int idx);

bool formula(int idx) {
    bool inner = term(idx);
    if(!inner) return inner;

    vector<int> dim(rvalue);
    while(ridx < in.length() && (in[ridx] == '+' || in[ridx] == '-')) {
        bool inner2 = term(ridx+1);

        for(int i=0; i<n; ++i)
            if(dim[i] != rvalue[i])
                inner2 = false;
        if(!inner2) return inner2;
    }
    rvalue = vector<int>(dim);
    return true;
}

bool term(int idx) {
    bool inner = factor(idx);
    if(!inner) return inner;

    vector<int> dim(rvalue);
    while(ridx < in.length() && (in[ridx] == '*' || in[ridx] == '/')) {
        char op = in[ridx];
        bool inner2 = factor(ridx+1);
        if(!inner2) return inner2;

        for(int i=0; i<n; ++i)
            dim[i] += (op=='*')?rvalue[i]:-rvalue[i];

    }
    rvalue = vector<int>(dim);
    return true;
}

inline bool ok(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); }
bool factor(int idx) {
    if(in[idx] == '(') {
        bool o = formula(idx+1);
        ridx++;
        return o;
    }
    string rname = "";
    while(ok(in[idx])) {
        rname += string(1,in[idx]);
        idx++;
    }
    ridx = idx;
    rvalue = derived[var[rname]];
    return true;
}

int main() {
    while(cin>>n>>m>>p, n|m|p) {
        derived.clear(); var.clear(); idx.clear();

        for(int i=0; i<m; ++i) {
            string name;
            vector<int> dim(n);
            cin>>name;
            for(int j=0; j<n; ++j) cin>>dim[j];
            derived[name] = dim;
            idx[name] = i;
        }

        cin>>in;
        for(int i=0; i<p; ++i) {
            string vname,dname;
            cin>>vname>>dname;
            var[vname] = dname;
        }

        if(formula(0)) {
            string ans = "undefined";
            int ai = -1;
            for(map<string,vector<int> >::iterator it = derived.begin();
                it != derived.end(); ++it) {
                bool same = true;
                for(int i=0; i<n; ++i)
                    same = same && (rvalue[i] == (it->second)[i]);
                if(same && idx[it->first] > ai) {
                    ans = it->first;
                    ai = idx[it->first];
                }
            }
            cout<<ans<<endl;
        END:;
        } else cout<<"error"<<endl;
    }
}

Measured memory_bytes: 964
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int intIn = new Integer(in.readLine());
		if(intIn < 0 || intIn > 86400) {
			return;
		}
		int h = intIn / 3600;
		int m = (intIn - h * 3600) / 60;
		int s = intIn - (h * 3600 + m * 60);
		System.out.println(h + ":" + m + ":" + s);

	}

}



Measured memory_bytes: 24252
#include <iostream>
using namespace std;
int main(void){
  int a[7],b[7];
  for(int i = 0; 7 > i; i++){
    cin >> a[i] >> b[i];
  }
  for(int i = 0; 7 > i; i++){
    cout << a[i] - b[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3116
s = gets.chomp.split('')

n = Array.new(s.size + 1, nil)

n.size.times do |i|
  if i == 0
    if s[i] == '<'
      n[i] = 0
    else
      n[i] = n[i+1] + 1 if n[i+1]
    end
  elsif i == n.size-1
    if s[i-1] == '<'
      n[i] = n[i-1] + 1 if n[i-1]
    else
      n[i] = 0
    end
  else
    if s[i-1] == '<'
      if s[i] == '<'
        n[i] = n[i-1] + 1 if n[i-1]
      else
        n[i] = [n[i-1], n[i+1]].max + 1 if n[i-1] && n[i+1]
      end
    else
      if s[i] == '>'
        n[i] = n[i+1] + 1 if n[i+1]
      else
        n[i] = 0
      end
    end
  end
end

(n.size - 1).downto(0) do |i|
  if i == 0
    if s[i] == '<'
      n[i] = 0
    else
      n[i] = n[i+1] + 1 if n[i+1]
    end
  elsif i == n.size-1
    if s[i-1] == '<'
      n[i] = n[i-1] + 1 if n[i-1]
    else
      n[i] = 0
    end
  else
    if s[i-1] == '<'
      if s[i] == '<'
        n[i] = n[i-1] + 1 if n[i-1]
      else
        n[i] = [n[i-1], n[i+1]].max + 1 if n[i-1] && n[i+1]
      end
    else
      if s[i] == '>'
        n[i] = n[i+1] + 1 if n[i+1]
      else
        n[i] = 0
      end
    end
  end
end

p n.inject(:+)

Measured memory_bytes: 49300
(* O(n log n) *)
Scanf.scanf "%d %d" @@ fun n k ->
  let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
  Array.sort (fun x y -> compare y x) ls;
  Array.sub ls 0 k |> Array.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(b>c){
    tmp=b;
    b=c;
    c=tmp;
  }
  if(a>b){
    tmp=a;
    a=b;
    b=tmp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
ll po(ll x,ll n){
    if(n==0) return 1;
    if(n%2==1) return (x*po(x,n-1));
    else {
        ll k=po(x,n/2);
        return (k*k);
    }
}
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
 
int32_t main(){
    IOS;
    ll a,b,k,i,j,ok = 0;
    cin >> k >> a >> b ;
    for(i=a;i<=b;i++){
        if(i%k==0) {
            ok = 1;
            break;
        }
    }
    if(ok) cout <<"OK\n";
    else cout <<"NG\n";

} 

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define MAX 1000000
using namespace std;

long long factorial[MAX] = {0}, finverse[MAX] = {0},
          inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if(n == k && n == 0) return 1;
  if(n < 0 || k < 0 || n < k) return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] %
         N;
}

vector<int> v;
long long n, m;
void setv();
long long solve();

int main() {
  cin >> n >> m;
  setv();
  smodfact();
  cout << solve() << endl;
  return 0;
}

void setv() {
  for(int i = 2; i <= sqrt(m); ++i) {
    int cnt = 0;
    while(m % i == 0) {
      ++cnt;
      m /= i;
    }
    if(cnt != 0) v.push_back(cnt);
  }
  if(m != 1) v.push_back(1);
}

long long solve() {
  long long ans = 1;
  for(int i = 0; i < v.size(); ++i) {
    ans *= calccomb(v[i] + n - 1, v[i]);
    ans %= N;
  }
  return ans;
}

Measured memory_bytes: 23680
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();
		int d = sc.nextInt();
		int e = sc.nextInt();
		
		int aa = a % 10;
		int bb = b % 10;
		int cc = c % 10;
		int dd = d % 10;
		int ee = e % 10;
      
      if(aa == 0){
        aa += 10;
      } if(bb == 0){
        bb += 10;
      }if(cc == 0){
        cc += 10;
      } if(dd == 0){
        dd += 10;
      } if(ee == 0){
        ee += 10;
      }
		int min = 10;
		if(min > aa){
		    min = aa;
		}if(min > bb){
		    min = bb;
		}if(min > cc){
		    min = cc;
		}if(min > dd){
		    min = dd;
		}if(min > ee){
		    min = ee;
		}
      int aaa = 0;
      int bbb = 0;
      int ccc = 0;
      int ddd = 0;
      int eee = 0;
      
      	if(a%10 != 0){
		 aaa =(int)Math.ceil(a / 10.0)*10;
        }else{
         aaa = a;
        }
      if(b%10 != 0){
		bbb = (int)Math.ceil(b / 10.0)*10;
        }else{
         bbb = b;
        }
      if(c%10 != 0){
		 ccc = (int)Math.ceil(c / 10.0)*10;
        }else{
         ccc = c;
        }
      if(d%10 != 0){
		 ddd = (int)Math.ceil(d / 10.0)*10;
        }else{
         ddd = d;
        }
      if(e%10 != 0){
		 eee = (int)Math.ceil(e / 10.0)*10;
        }else{
         eee = e;
        }
		int ans = aaa + bbb + ccc + ddd + eee - 10 + min;
		System.out.println(ans);
	}
}


Measured memory_bytes: 35684
#include <iostream>
#include<algorithm>

using namespace std;

int main() {

	int R[200000], n;

	cin >> n;
	for (int i = 0; i < n; i++)cin >> R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  vector<in> a(n);
  rep(i,n)
    cin>>a.at(i);
  in sum=0;
  rep(i,n){
    sum+=a.at(i);
    sum=sum % MOD;
  }
  in sum2;
  sum2=sum*sum;
  
  sum2 = sum2 % MOD;
  in nijouwa=0;
  rep(i,n){
    in h=0;
    h=a.at(i)*a.at(i);
    h=h % MOD;
    nijouwa += h;
    nijouwa = nijouwa % MOD;
  }
  sum2 = sum2 + MOD - nijouwa;
  sum2 = sum2 % MOD;
  //cout<<sum2<<endl;
  if(sum2 % 2==0)
    cout<<sum2/2<<endl;
  else
    cout<<(sum2+MOD)/2<<endl;
  //cout<<nijouwa;
}

Measured memory_bytes: 4840
n = int(input())
 
#zahyo[i][j], iはi番目の地点、j=0はx座標、j=1はy座標、j=2は高さhを表す
zahyo = [list(map(int,input().split())) for i in range(n)] 
 
for cx in range(101):
  for cy in range(101):
    flag =0
    for i in range(n):
      if zahyo[i][2]>0:
        H0 = abs(cx-zahyo[i][0])+abs(cy-zahyo[i][1])+zahyo[i][2]
        break
    for i in range(n):
      if zahyo[i][2] != max(0, H0-abs(cx-zahyo[i][0])-abs(cy-zahyo[i][1])):  
        flag=1
        break
    if flag==0:
      print(cx,cy,H0)
      exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);


string s1(string s){
    bool abc[26];
    for(int i=0;i < 26;i++)
    {
        abc[i]=true;
    }

    for(int i=0;i < s.size();i++)
    {
        abc[s.at(i)-'a']=false;
    }

    for(int i=0;i < 26;i++)
    {
        if(abc[i]==true){
            s+=(char)i+'a';
            break;
        }
    }
    return s;
}

string s2(string s){
    bool abc[26];
    for(int i=0;i < 26;i++)
    {
        abc[i]=true;
    }

    for(int i=0;i < (int)s.size()-1;i++)
    {
        abc[s.at(i)-'a']=false;
    }
    char c=s.back();
    s.pop_back();

    for(int i=(c+1-'a');i < 26;i++)
    {
        if(abc[i]==true){
            s+=(char)i+'a';
            return s;
        }
    }
    return s;
}

signed main(){
    string s,t;
    cin>>s;

    if(s.size()<26){
        cout << s1(s) << endl;
        return 0;
    }
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }

    t=s2(s);
    s.pop_back();

    while(t==s){
        t=s2(s);
        s.pop_back();
    }

    cout << t << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

class UnionFind {
public:
    vector<int> par;

    UnionFind(int n) : par(n, -1) {};

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int size(int x) {
        return -par[root(x)];
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int ans = n;
    rep(i, 0, m) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        if (!uf.same(x, y)) {
            uf.unite(x, y);
            ans--;
        }
    }

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


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

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,m,a[maxn],b[maxn],k,sum1[maxn],sum2[maxn],l,r,mid;
bool flag;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m >> k;
    rep(n) cin >> a[i];
    rep(m) cin >> b[i];
    sum1[0]=sum2[0]=0;
    rep(n) sum1[i+1]=sum1[i]+a[i];
    rep(m) sum2[i+1]=sum2[i]+b[i];
    l=0,r=n+m;
    while(l<r){
        mid=l+r+1>>1;
        flag=false;
        rep(mid+1) if(i<=n&&mid-i<=m) if(sum1[i]+sum2[mid-i]<=k) flag=true;
        if(flag) l=mid;
        else r=mid-1;
    }
    print1(l);
    return 0;
}


Measured memory_bytes: 9908
import java.util.Scanner;

public class Main {

	/**
	 * Digit Sums
	 */
	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = n;
			int s = 0;
			while (m > 0) {
				s = s + (m % 10);
				m = m / 10;
			}
			if (n % s == 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
#define PI (acos(-1))
// #define int long long

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

signed main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vll X(n);
  rep(i, n) cin >> X[i];

  ll warp_count = 0;
  ll ans = 0;
  rep(i, n - 1) {
    ll cost = (X[i + 1] - X[i]) * a;
    if (cost < b)
      ans += cost;
    else
      warp_count++;
  }
  ans += warp_count * b;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define X first
#define Y second
typedef long long ll;
using namespace std;

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

int n;
int a[3010];

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	ll f = 0;
	for (int i = 0; i < n; i ++) {
		cin >> a[i];
		f += a[i]-1;
	}

	cout << f;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define 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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<61
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,q; cin >> a  >> b >>q;
  vector<ll> s(a), t(b), x(q);
  REP(i,a){
      cin >> s[i];
  }
  REP(i,b){
      cin >> t[i];
  }
  REP(i,q){
      cin >> x[i];
  }
  REP(i,q){
      auto st = lower_bound(all(s), x[i]);
      auto tt = lower_bound(all(t), x[i]);
      ll ls,rs,lt,rt;
      if(st==s.begin()){
          ls = LINF;
          rs = *st - x[i];
      }else if(st==s.end()){
          ls = x[i]-*(st-1);
          rs = LINF;
      }else{
          ls = x[i]-*(st-1);
          rs = *st-x[i];
      }
      if(tt==t.begin()){
          lt = LINF;
          rt = *tt-x[i];
      }else if(tt==t.end()){
          lt = x[i]-*(tt-1);
          rt = LINF;
      }else{
          lt = x[i]-*(tt-1);
          rt = *tt-x[i];
      }
      ll ans = LINF;
      ans = min(ans, max(rs,rt) );
      ans = min(ans, max(ls,lt));
      ans = min(ans, 2*rt + ls);
      ans = min(ans, 2*rs + lt);
      ans = min(ans, 2*ls + rt);
      ans = min(ans, 2*lt + rs);
      cout << ans << endl;

  }

}



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

using namespace std;

string S;

char dp[501][501];

char dfs(int l, int r){
    //cout << "dfs: " << l << "," << r << endl;
    if(dp[l][r] != -1){
        return dp[l][r];
    }
    if(l == r){
        return dp[l][r] = 1;
    }else if(r - l == 1 || r - l == 2){
        return dp[l][r] = 0;
    }
    if(!(S[l] == 'm' && S[r-1] == 'w')){
        return dp[l][r] = 0;
    }
    for(int i = l + 1; i < r-1;i++){
        if(S[i] != 'e') continue;
        if(dfs(l + 1,i) && dfs(i+1,r - 1)){
            return dp[l][r] = 1;
        }
    }
    return dp[l][r] = 0;
}

int main(){
    cin >> S;
    for(int i = 0;i<501;i++)for(int j = 0;j<501;j++){
        dp[i][j] = -1;
    }
    if(dfs(0,S.size()) == 1){
        cout << "Cat" << endl;
    }else{
        cout << "Rabbit" << endl;
    }
}

Measured memory_bytes: 1432
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll a[100010];
ll ans;
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n+1)scanf("%lld",a+i);
	rep(i,1,n+1)if(a[i]==i){
		ans++;
		i++;
	}
	printf("%lld\n",ans);
	return 0;
}

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

namespace _0338
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool found = false;
            int i;
            for (i = 1000; !found; i--)
            {
                if (x[0] % i == 0 && x[1] % i == 0) found = true;
            }
            i++;
            Console.WriteLine(x[0] / i * x[1] / i * x[2]);
        }
    }
}

Measured memory_bytes: 9592
#include <stdio.h>

void	ft_swap(int *a, int *b)
{
	int tmp;
	
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void	ft_qsort(int *tab, int left, int right)
{
	int Left = left;
	int Right = right;
	int pivot = tab[(left + right) / 2];

	while (1)
	{
		while (tab[Left] < pivot)
			Left++;
		while (tab[Right] > pivot)
			Right--;
		if (Left >= Right)
			break ;
		ft_swap(&tab[Left], &tab[Right]);
		Left++;
		Right--;
	}

	if (Left - 1 > left)
		ft_qsort(tab, left, Left - 1);
	if (Right + 1 < right)
		ft_qsort(tab, Right + 1, right);
}

int		main(void)
{
	int n;
	scanf("%d", &n);
	int tab[n];
	int i = 0;
	while (i < n)
		scanf("%d", &tab[i++]);
	ft_qsort(tab, 0, n - 1);
	int arc = tab[n / 2];
	int abc = tab[(n / 2) - 1];
	printf("%d\n", arc - abc);
	return (0);
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int n;
	cin >> n;
	map<string, int> m;
	for (int i = 0; i < n;  i++) {
		string s;
		cin >> s;
		m[s]++;
	}
	cout << "AC" << " x " << m["AC"] << endl;
	cout << "WA" << " x " << m["WA"] << endl;
	cout << "TLE" << " x " << m["TLE"] << endl;
	cout << "RE" << " x " << m["RE"] << endl;
	return 0;
}

//!

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x, ll n, int md) {
    if (n == 0)return 1;
    if (n % 2 == 0)return modexp((x * x) % md, n / 2, md);
    return (x * modexp((x * x) % md, n / 2, md)) % md;
}


int main() {
    fastio;
    // clock_t tm = clock();
    ll n;
    cin>>n;
    vl a(n);
    f(i,0,n)cin>>a[i];
    sort(all(a),greater<ll>());
    ll ans=0;
    ans+=a[0];
    ll k=n-2;
    f(i,1,n){
        //cout<<k<<" "<<ans<<endl;
        if(k>0){
            --k;
            ans+=a[i];
        }
        if(k>0){
            --k;
            ans+=a[i];
        }
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s = "aiueo";
    char c;
    cin >> c;
    bool b = false;
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == c) {
            b = true;
            break;
        }
    }
    if (b) {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = 2*a+2*b;
    System.out.println(area+" "+length);
    sc.close();
  }
}



Measured memory_bytes: 26168
#include<iostream>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    int a,b[11400],c[11400],d,e,f,g,h;
    cin >>a;
    if(a==0) break;
    for(int n=0;n<=a;n++){
      cin >>b[n];
      if(n!=0){
        c[n]=b[n]-b[n-1];
      }
    }
    d=c[1];
    e=0;
    g=0;
    h=0;
    for(int n=1;n<=a;n++){
      if(h>0){
        if(d+b[n-2]!=b[n]){
          e=n;
          g++;
        }
        h--;
      }
      else{
        if(d+b[n-1]!=b[n]){
          e=n;
          g++;
          h++;
        }
      }
    }
    if(g==1) cout <<b[e]<<'\n';
    if(g>1){
      if(c[a]==b[2]-b[0]) cout <<b[1]<<'\n';
      else cout <<b[0]<<'\n';
    }
  }
  return(0);
}



Measured memory_bytes: 3176
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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 Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define INF 999999999999

ll comb(int n,int k){
  ll res = 1;
  if (k>n-k) k=n-k;
  rep(i,k){
      res*=(n-i);
      res/=(i+1);
  }
  return res;
}

int main(){
  int N; ll sum=0;
  cin>>N;
  vector < string > s(N);
  map < string,int > cnt;
  rep(i,N){
    cin>>s[i];
    Sort(s[i]);
    cnt[s[i]]++;
  }

  for(auto itr=cnt.begin();itr!=cnt.end();itr++){
    if(cnt[itr->first]>=2) sum+=comb(cnt[itr->first],2);
  }
  cout<<sum<<endl;
  return 0;
}


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

typedef unsigned long long ll;

ll md = 1000000007;

int main(int, char**) 
{
	int n, m = 0;
	cin >> n;
	vector<int> a(n+1);
	vector<int> b(n+1);

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	for (int i = n; i > 0; i--) {
		int x = 0;
		for (int j = i + i; j <= n; j += i) {
			if (b[j] > 0) x++;
		}

		if ((a[i] > 0) ^ (x % 2 > 0)) {
			b[i] = 1;
			m++;
		} else b[i] = 0;
	}

	cout << m << endl;
	bool isF = false;
	for (int i = 1; i <= n; ++i) {
		if (b[i] > 0) {
			if (isF) cout << " ";
			isF = true;
			cout << i;
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 2432
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

enum class seq_mode {
  unknown,
  increasing,
  decreasing
};

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> A;
  tools::read(A, N);

  seq_mode mode = seq_mode::unknown;
  i64 answer = 1;
  for (auto it = ++A.begin(), prev_it = A.begin(); it != A.end(); prev_it = it, ++it) {
    switch (mode) {
    case seq_mode::unknown:
      if (*prev_it < *it) {
        mode = seq_mode::increasing;
      } else if (*prev_it > *it) {
        mode = seq_mode::decreasing;
      }
      break;
    case seq_mode::increasing:
      if (*prev_it > *it) {
        mode = seq_mode::unknown;
        ++answer;
      }
      break;
    case seq_mode::decreasing:
      if (*prev_it < *it) {
        mode = seq_mode::unknown;
        ++answer;
      }
      break;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] m = Enumerable.Repeat(0, nx[0]).Select(_ => int.Parse(Console.ReadLine())).ToArray(); ;
        Console.WriteLine(nx[0] + (nx[1] - m.Sum()) / m.Min());
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = 0;
		int max = 0;
		int n = sc.nextInt();
		String s = sc.next();
		
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'I')
				x++;
			else if (s.charAt(i) == 'D')
				x--;
			
			if (max < x)
				max = x;
		}
		
		System.out.println(max);
	}
}

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

class AB {
    static int N, W, A, B;
    static string S;
    
    static void Main() {
        S = Console.ReadLine();
        string ans = "";
        for(int i = 0; i < S.Length; i++) {
            switch (S[i]) {
                case '1':
                    ans += "1";
                    break;
                case '0':
                    ans += "0";
                    break;

                case 'B':
                    if (ans.Length != 0) {
                        ans = ans.Remove(ans.Length - 1);
                    }
                    break;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 2648
def main():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    sum_A = [0]
    sum_B = [0]

    for i in range(n):
        sum_A.append(sum_A[i] + A[i])

    for i in range(m):
        sum_B.append(sum_B[i] + B[i])

    # R = []

    # b = m - 1
    # flag = False
    # while b > -1:
    #     if sum_B[b] <= k:
    #         R.append(b + 1)
    #         flag = True
    #         break
    #     else:
    #         b -= 1

    # if not flag:
    #     R.append(0)

    r = 0
    j = m

    for i in range(n + 1):
        a = sum_A[i]
        if a > k:
            break

        while j > -1:
            if sum_B[j] > k - a:
                j -= 1
            else:
                r = max(r, i + j)
                break

    print(r)
        # a = sum_A[i]

        # # b = m - 1 ←これがいらないのが肝
        # flag = False
        # while b > -1:
        #     if sum_B[b] <= k - a:
        #         R.append(i + 1 + b + 1)
        #         flag = True
        #         break
        #     else:
        #         b -= 1

        # if not flag:
        #     if 0 <= k - a:
        #         R.append(i + 1)
        #     else:
        #         R.append(0)

    # print(max(R))


if __name__ == '__main__':
    main()


Measured memory_bytes: 47552
//#ifdef JUDGE
//#include <fstream>
//std::ifstream cin("input.txt");
//std::ofstream cout("output.txt");
//#else
#include <iostream>
#include <bits/stdc++.h>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
#define ll long long
ll sd(ll n)
{
    ll a=0;
    while (n>0)
    {
        a+=n%10;
        n/=10;
    }
    return a;
}
void solve()
{
   int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1);
  return;
}
int main()
{
    ll t=1;
    //cin >>t;
    while(t--)
        solve();

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,q;
vector<int> v;
int ans=0;
int a[51],b[51],c[51],d[51];
int check()
{
    int cnt=0;
    for(int i=1;i<=q;i++)
    {
       if(v[b[i]-1]-v[a[i]-1]==c[i])
       cnt+=d[i];
    }
    return cnt;
}
void dfs(int i,int curr)
{
    if(i>n)
    {
       ans=max(ans,check());
       return;
    }
    for(int j=curr;j<=m;j++)
    {
        v.push_back(j);
        dfs(i+1,j);
        v.pop_back();
    }
}
int main()
{
   cin>>n>>m>>q;
   for(int i=1;i<=q;i++)
   {
       cin>>a[i]>>b[i]>>c[i]>>d[i];
   }
   dfs(1,1);
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	h := r.nextInt()

	m := 1
	cnt := 0
	ans := 0
	for h > 0 {
		ans += m
		cnt += m
		if h == 1 {
			break
		}
		m *= 2
		h /= 2
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 640
while 1:
    T,P,R=map(int,input().split())
    if not T and not P and not R:break
    d={str(i):{str(j):[False,0] for j in range(1,P+1)} for i in range(1,T+1)}
    for _ in range(R):
        tid,pid,time,m=input().split()
        if not d[tid][pid][0]:
            if m=="WRONG":
                d[tid][pid][1]+=1
            else:
                d[tid][pid][0]=True
                d[tid][pid][1]*=1200
                d[tid][pid][1]+=int(time)
    l=[]
    for i in d.keys():
        cd=[j for j in d[i].values() if j[0]]
        sc=sum([j[1] for j in cd])
        l.extend([(int(i),len(cd),sc)])
    p=sorted(l,key=lambda x:(-x[1],x[2],x[0]))
    for i in p:
        print(i[0],i[1],i[2])



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

int main()
{
    int N;
    cin >> N;
    double ans = 0;
    if(N%2==0) ans = 0.5;
    else
    {
        double a = (double)(N-1)/2;
        double b = (double)(N-1)/2+1;
        ans = b/(a+b);
    }
    printf("%lf\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n, k;
    cin >> n >> k;
    int v[n];
    fore(i,0,n) cin >> v[i];
    sort(v, v+n, greater<int>());
    int sum = 0;
    fore(i,0,k) sum += v[i];
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    bitset<100*100+100> dp;
    dp[0]=true;
    rep(i,n){
        cin>>a;
        dp|=dp<<a;
        sum+=a;
    }
    rrrep(i,sum,0){
        if(dp[i]==true&&i%2==0){
            Cout(i/2);
            return 0;
        }
    }
    return 0;
}



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

ll dp[3001][3001];

ll fun(ll *arr, int i,int j, int&n){
    
    if(i > j) 
      return 0;
    
    if(dp[i][j] != -1){
        return dp[i][j];
    }
        
   dp[i][j] =    max((arr[i] + min(fun(arr,i+2,j,n) , fun(arr,i+1,j-1,n))),
                    (arr[j] + min(fun(arr,i+1,j-1,n), fun(arr,i,j-2,n))) );
     
    return dp[i][j];
}




void solve(){
    int n;
    cin >> n;
     ll *arr = new ll[n];
     ll sum = 0;
    for(int i=0 ;i<n; i++){
       cin >> arr[i];
       sum += arr[i];
    }
    memset(dp,-1,sizeof(dp));
    cout << 2 *fun(arr,0,n-1,n) - sum;
    return;
}
int main(){
//  #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif 
solve();

return 0;
}

Measured memory_bytes: 70784