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

int main(){
    ll n;
    cin >> n;
    deque<ll> ans;
    while(n--){
        ll a;
        cin >> a;
        if(n & 1) ans.push_back(a);
        else ans.push_front(a);
    }
    for(auto& i : ans) cout << i << ' ';
    cout << endl;
}


Measured memory_bytes: 3840
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    /* let [n, d] = lines[0].split(' ').map( _ => parseInt(_)) */
    let s = lines[0]
    let t = lines[1]
    let ans = 0
    for(let i = 0; i < s.length; i++) {
        if(s[i] != t[i]) {
            ans++
        }
    }

    console.log(ans)
});

Measured memory_bytes: 34240
using System;

namespace ABC147B
{
    class Program
    {
        static void Main(string[] args)
        {
            string msg = Console.ReadLine();

            var count = 0;
            var length = msg.Length / 2;
            for (int i = 0; i < length; i++)
            {
                if (msg[i].ToString() != msg[msg.Length -1 - i].ToString())
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
while True:
    N,W = map(int,input().split())
    if N == 0: break
    src = [int(input()) for i in range(N)]
    highest = max(src)
    bands = highest//W + 1
    hist = [0 for i in range(bands)]
    for i in range(N):
        hist[src[i] // W] += 1
    ans = maxn = 0
    for i,n in enumerate(hist):
        ans += n * (bands-1-i)
        maxn = max(n, maxn)
    print(ans / maxn / (bands-1) + 0.01)

Measured memory_bytes: 5620
#include <bits/stdc++.h>
int arr[100000];
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }
    sort(arr + 1, arr + n + 1);
    cout << arr[(n / 2) + 1] - arr[n / 2] << endl;
    return 0;
}


Measured memory_bytes: 640
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();

function main(){
  var waitTime = calc();
  for(var i = 0, len = input.length - 1; i < len;i++){
    console.log(waitTime[parseInt(input[i], 10)]);
  }
}

function calc(){
  var seats = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var groupMembers = [2,5,2,2,2];
  var eatTimes = [19,39,25,36,22,42];
  
  var headGroup = -1;
  var pastMinutes = 0;
  var waitTime = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var lastMembers = 100;
  
  while(true){
    // たべおわる
    var i;
    for(i = 17; i--;){
      seats[i] = max(--seats[i], 0);
    }
    
    // 来店
    if(headGroup == -1 && pastMinutes % 5 == 0){
      headGroup = pastMinutes / 5;
    }
    
    // ちゃくせき
    while(headGroup != -1 && i != 17){
      var needsSequencialSeats = groupMembers[headGroup % 5];
      var sequencialSeats = 0;
      var startIndex = -1;
      
      for(i = 0, len = seats.length; i < len; i++){
        sequencialSeats = seats[i] == 0 ? sequencialSeats + 1 : 0;
        
        if(sequencialSeats == needsSequencialSeats){
          var eatTime = eatTimes[headGroup % 6];

          startIndex = i - (needsSequencialSeats - 1);
          // すわれるみたい
          waitTime[headGroup] = pastMinutes - (headGroup * 5);
          for(var j = startIndex, len = (needsSequencialSeats + startIndex); j < len; j++){
            seats[j] = eatTime;
          }
          
          headGroup = (((headGroup + 1) * 5) <= pastMinutes) ? headGroup + 1 : -1;
          if(!(--lastMembers)){
            // 100グループ着席
            return waitTime;
          }
          break;
        }
      }
    }
    
    pastMinutes++;
  }
  
}

function max(a, b){
  var t = (a - b);
  return a - (t & (t >> 31));
}

Measured memory_bytes: 8432
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) for(int i = a, i <= b; i++)
#define REPD(i, a, b) for(int i = a, i >= b; i--)
#define SQ(a) (a) * (a)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); ++it)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define sz(a) int((a).size())
#define endl "\n"
#define PI 3.1415926535
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(t) int x; cin >> t; while(t--)
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int>> minpq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void fio()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
	fio();
	int n;
	msi m;
	w(n)
	{
		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: 3660
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    foreach (i; 0 .. N)
    {
        A[i] -= i + 1;
    }
    long s = A.sum();
    long eval(long x)
    {
        return A.map!(a => abs(a - x)).sum();
    }

    long ans = long.max;

    long ok = -(10 ^^ 9);
    long ng = +(10 ^^ 9);

    while (1 < ng - ok)
    {
        long m = (ok + ng) / 2;
        if (eval(m + 1) <= eval(m))
        {
            ok = m;
        }
        else
        {
            ng = m;
        }
    }

    writeln(min(eval(ok), eval(ok - 1), eval(ok + 1)));
}


Measured memory_bytes: 11608
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
ans = 0
for i in range(n):
	    for j in range(i+1,n):
	    	    bottom  = j
	    	    top = n
	    	    while top -bottom > 1:
	    	    	    middle = (top+bottom)//2
	    	    	    if l[middle] <l[i]+l[j]:
	    	    	    	    bottom = middle
	    	    	    else:
	    	    	    	    top = middle
	    	    ans += bottom - j 
print(ans)

Measured memory_bytes: 41452
Option Strict On

Module Module1
    Sub Main()
        'let'
        Dim tmp() As Long =
            Array.ConvertAll(Of String, Long) _
            (Console.ReadLine().Split(), AddressOf Long.Parse)
        Dim a As Long = tmp(0)
        Dim b As Long = tmp(1)
        Dim c As Long = tmp(2)
        Dim d As Long = tmp(3)

        Dim arr() As Long = New Long() {a, b, c}

        'var'
        Dim flg As Boolean


        For i As Int32 = 0 To UBound(arr) - 1
            If Math.Abs(arr(i) - arr(i + 1)) > d Then
                flg = True
            End If
        Next
        If Math.Abs(a - c) <= d Then flg = False

        Console.WriteLine(New String() {"Yes", "No"}(Convert.ToInt32(flg)))

    End Sub


End Module


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

typedef long long ll;

int main(){
  while(1){
  ll a,b;
  cin>>a>>b;
  if(a==0){break;}
  ll mi=1e18;
  for(int i=1;i*i<=a;i++){
    if(a%i==0){
      for(int t=1;t*t<=b;t++){
	if(b%t==0){
	  vector<ll> A={i,t,a/i,b/t};
	  sort(A.begin(),A.end());
	  ll cost=0;
	  for(int j=1;j<4;j++){
	    cost+=(A[j]-A[j-1])*(A[j]-A[j-1]);
	  }
	  mi=min(mi,cost);
	}
      }
    }
  }
  cout<<mi<<endl;
  }


  return 0;
}



Measured memory_bytes: 3076
package main

import (
	f "fmt"
	"strconv"
	"strings"
)

func main() {
	var n string
	f.Scan(&n)

	arr := strings.Split(n, "")
	ans := num(arr)
	if ans%9 == 0 {
		f.Println("Yes")
	} else {
		f.Println("No")
	}
}

func num(arr []string) int {

	var num int
	for i, _ := range arr {
		n, _ := strconv.Atoi(arr[i])
		num += n
	}
	return num

}


Measured memory_bytes: 6536
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }


void main() {
    int n = readint();
    int[] a = 0 ~ readints() ~ 0;

    auto d = new int[n + 1];
    foreach (i; 0..n+1) {
        d[i] = abs(a[i] - a[i+1]);
    }
    long D = d.sum;

    foreach (i; 0..n) {
        long x = D - d[i] - d[i+1] + abs(a[i] - a[i+2]);
        writeln(x);
    }
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n; cin >> n;
    ll ans=1;
    ll odd=1;

    for(int i = 0; i < n; i++) {
        int a;cin >> a;
        if(a%2==0) odd *= 2;
        ans *= 3;
    }

    cout << ans - odd << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>

int main() {
    int a, b, c ,d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    if (abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int sum=0;
    int tmp=n;
    while(tmp){
        sum+=tmp%10;
        tmp/=10;
    }
    if(n%sum==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
     int n,r,c=0;
     scanf("%d",&n);
     if(n>=100&&n<=999){
          while(n>0){
               r=n%10;
               if(r==7){
                c++;
                break;
               }
               n=n/10;
          }
          if(c>0)
               printf("Yes");
          else
               printf("No");
     }
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  FiniteField base = 1;
  for (int i = 1; i <= n - 1; i++) {
    base *= i;
  }
  FiniteField factor = 1;
  FiniteField ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += base * factor * (xs[i + 1] - xs[i]);
    factor += FiniteField(1) / (i + 2);
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    long long mod = 1000000007;
    //freopen("i.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    long long arr[n];
    for(int i = 0;i < n;i++){
        cin >> arr[i];
    }

    static long long dp[100][100001];

    for(int i = 0;i < n;i++){
        for(int j = 0;j <= k;j++){
            dp[i][j] = 0;
        }
    }

    for(int i = 0;i <= arr[0];i++){
        dp[0][i] = 1ll;
    }

    for(int i = 1;i < n;i++){
        for(int j = 1;j <= k;j++){
            //if(dp[i-1][j] == -1)break;
            dp[i-1][j] += dp[i-1][j-1];
            dp[i-1][j] %= mod;
        }
        for(int j = 0;j <= k ;j++){

            int l = max(0ll,j-arr[i]);
            int r = j;
            long long ans = dp[i-1][r];
            if(l != 0) ans -= dp[i-1][l-1];
            ans += mod;
            ans += mod;
            ans %= mod;
            dp[i][j] = ans;
        }
        //for(int j = 0;j <= k;j++){
        //    cout << dp[i][j] << " ";
        //}
        //cout << "\n";
    }
    /*
    dp.push_back(1);
    for(int i = 0;i < n;i++){
        for(int j = 1;j < dp.size();j++){
            dp[j] += dp[j-1];
            dp[j] %= mod;
        }

        for(int j = 0;j < dp.size();j++){
            cout << dp[j] << " ";
        }

        //cout << "\n";
        for(long long j = 0;j < dp.size()+arr[i];j++){
            if(j > k) break;
            int l = max(0ll,j-arr[i]);
            int r = min((long long)dp.size()-1,j);
            long long ans = dp[r];
            if(l != 0) ans -= dp[l-1];
            ans += mod;
            ans += mod;
            ans %= mod;
            dp2.push_back(ans);
        }
        swap(dp,dp2);
        dp2.clear();

        for(int j = 0;j < dp.size();j++){
            cout << dp[j] << " ";
        }
        cout << "\n";

    }
    if(k >= dp.size()) cout << 0;
    else cout << dp[k];
    */
    cout << dp[n-1][k];
    return 0;
}


Measured memory_bytes: 78336
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int min(int a,int b){
    if(a<=b)return a;
    else return b;
}
int main()
{   int n,l[201],i,ans=0;
    scanf("%d",&n);
    for(i=0;i<2*n;i++){
        scanf("%d",&l[i]);
    }
    
    qsort(l,2*n,sizeof(int),compare);
    for(i=0;i<2*n-1;i++){
        ans+=min(l[i],l[i+1]);
        i++;
    }
    printf("%d",ans);
    return 0;
}


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

int main(){
    long long i;
    long long N,N_sqrt;
    long long total;
    long long result;
    cin>>N;
    N_sqrt=sqrt(N);
    for(i=1;i<=N_sqrt;i++){
        if(i==1){
            result=N-1;
        }else if(N%i==0 && N/i+i-2<result){
            result=N/i+i-2;
        }
    }

    cout<<result<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define pb  push_back 
#define rep(i,n) for(int i=0; i<(n);i++)
using namespace std;

int mapper[256] = {};

int formula(const string& s, int& i) {
  char c = s[i++];
  int v,v2;
  switch(c) {
  case '0':
  case '1':
  case '2': return c -'0';
  case 'P':
  case 'Q':
  case 'R': return mapper[c];
  case '-':
    v = formula(s,i);
    return (-v+2)%3;
  case '(':
    v = formula(s,i);
    char op = s[i++];
    v2 = formula(s,i);
    i++;
    if (op=='*') {
      return min(v, v2);
    } else {
      return max(v, v2);
    }
  }
  return 0;
}

int main(){
  string s;
  while(cin>>s,s!=".") {

    int count = 0;
    rep(p,3) rep(q,3) rep(r,3) {
      int i = 0;
      mapper['P'] = p;
      mapper['Q'] = q;
      mapper['R'] = r;
      if (formula(s,i) == 2) {
	//cout << "ok " << p << q << r << endl;
	count++;
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 1188
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int main(){
	string s;
	while(cin >> s){
		char res = '0';
		for(int i=0; i<3; ++i){
			if(s[3*i] == s[3*i+1] && s[3*i] == s[3*i+2] && s[3*i] != 's'){
				res = s[3*i];
			} else if(s[i] == s[i+3] && s[i] == s[i+6] && s[i] != 's'){
				res = s[i];
			} else if(s[0] == s[4] && s[0] == s[8] && s[0] != 's'){
				res = s[0];
			} else if(s[2] == s[4] && s[2] == s[6] && s[2] != 's'){
				res = s[2];
			}
		}

		if(res == '0'){
			res = 'd';
		}

		cout << res << endl;
	}

    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=200005;
const int P=998244353;

int n;
int a[N],b[N];
int L;
int ans;

#define f(x) ((x)&(L-1))

inline bool cmp(int x,int y){return f(x)<f(y);}

void init(){
	int tmp;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=0;i<=28;i++){
		
		//if(i<=2) printf("%d:\n",i);
		
		L=1<<i;
		sort(a+1,a+n+1,cmp);
		sort(b+1,b+n+1,cmp);
		
		//if(i<=2) for(int j=1;j<=n;j++) printf("%d ",f(a[j])); printf("\n");
		//if(i<=2) for(int j=1;j<=n;j++) printf("%d ",f(b[j])); printf("\n");
		
		tmp=0;
		for(int j=1;j<=n;j++) tmp^=(b[j]&L);
		for(int l=1,r=n+1;l<=n;l++){
			while(f(a[l])+f(b[r-1])>=L && r>1) r--;
			
			//if(i<=2) printf("%d %d ",l,r);
			
			if(n&1) if(a[l]&L) ans^=L;
			if((n-r+1)&1) ans^=L;
			ans^=tmp;
			
			//if(i<=2) printf("- (cur:%d\n",ans);
			
		}
	}
	printf("%d\n",ans);
}

int main(){
	init();
	return 0;
}

Measured memory_bytes: 1792
<?php
$n = trim(fgets(STDIN));

$k = 0;
while(true){
    $num = pow(-2,$k);
    if($n % (abs($num) * 2) == 0){
        $a[] = 0;
    }else{
        $n -= $num;
        $a[] = 1;
    }
    $k++;
    if($n == 0)break;
}
$a = array_reverse($a);
echo implode("", $a);
    


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

inline bool in_maze(int n, int max)
{
	return (0 <= n && n < max);
}

int main()
{
	int h, w;
	int max_cost = -1;

	cin >> h >> w;

	vector<string> maze;

	for (int i = 0; i < h; i++)
	{
		string s;
		cin >> s;
		maze.push_back(s);
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			vector<vector<int>> v(h, vector<int>(w, -1));
			queue<pair<int, int>> q;
			int cost = 0;
			int x = j, y = i;

			if (maze[i][j] == '#')
			{
				continue;
			}

			q.push({x, y});
			v[y][x] = 0;

			while (!q.empty())
			{
				pair<int, int> point = q.front();
				q.pop();

				x = point.first;
				y = point.second;
				cost = v[y][x];
				vector<pair<int, int>> next_points = {
					{x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}};

				if (max_cost < cost)
				{
					max_cost = cost;
				}

				for (auto &next_p : next_points)
				{
					int n_x = next_p.first;
					int n_y = next_p.second;

					if (in_maze(n_x, w) && in_maze(n_y, h) && v[n_y][n_x] == -1 && maze[n_y][n_x] != '#')
					{
						q.push({n_x, n_y});
						v[n_y][n_x] = cost + 1;
					}
				}
			}
		}
	}

	cout << max_cost << endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long a, b, x;
    cin >> a >> b >> x;
    long long c = max(0ll, x - b) / (a - b);  //0もlong long型であるからllをつける
    x %= 1000000007;
    c %= 1000000007;
    b %= 1000000007;
    cout << (b * c + x) % 1000000007 << endl;
}



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

ll N, L;
const int MAX_N = 1.0e5 + 100;
ll a[MAX_N];

int main() {
    cin >> N >> L;
    for (int i = 0; i < N; i++) cin >> a[i];

    bool f = false;
    int last;
    for (int i = 0; i < N-1; i++) {
        if (a[i] + a[i+1] >= L) {
            last = i+1;
            f = true;
            break;
        }
    }

    if (f) {
        cout << "Possible" << endl;
        for (int i = 1; i < N; i++) {
            if (i != last) {
                cout << i << endl;
            }
            else {
                break;
            }
        }
        for (int i = N-1; i >= 1; i--) {
            if (i != last) {
                cout << i << endl;
            }
            else {
                break;
            }
        }
        cout << last << endl;
    }
    else {
        cout << "Impossible" << endl;
    }

    
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		ll ans = max(a, b) * max(c, d);
		ans = max(ans, min(a, b) * min(c, d));
		ans = max(ans, max(a, b) * min(c, d));
		ans = max(ans, min(a, b) * max(c, d));
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 3648
N = int(input())
h_list = list(map(int, input().split()))

ans = 0
h_min = min(h_list)

ans += h_min

pre = h_min
for i in range(N):
    h = h_list[i]
    if i == 0:
        ans += h - h_min
        pre = h
    else:
        if h >= pre:
            ans += h - pre
            pre = h
        else:
            pre = h
print(ans)

Measured memory_bytes: 3064
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

dp = [10**9+1]*n
dp[0] = 0
dp[1] = dp[0] + abs(h[1]-h[0])

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

print(dp[n-1])

Measured memory_bytes: 52448
#include <stdio.h>

int main()
{
    long long k, a, b;
    long long ans;
    int nokori;

    scanf("%lld %lld %lld", &k, &a, &b);

    if (b - a <= 1) {
	ans = 1 + k;
    } else if (1 + k - 2 < a) {
	ans = 1 + k;
    } else {
	nokori = k - (a - 1);
	if (nokori % 2 == 0) {
	    ans = a + (b-a) * (nokori/2);
	} else {
	    ans = a + (b-a) * (nokori-1)/2 + 1;
	}
    }
    printf("%lld\n", ans);

    return 0;
}
	


Measured memory_bytes: 128
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long W = long.Parse(str[1]);
        long[] Av = new long[0];
        long[] Aw = new long[0];
        long[] Bv = new long[0];
        long[] Bw = new long[0];
        for(int j=0;j<2;j++){
            int n = j == 0 ? N/2 : N - N/2;
            long[] v = new long[1 << n];
            long[] w = new long[1 << n];
            long[] tv = new long[n];
            long[] tw = new long[n];
            for(int i=0;i<n;i++){
                str = Console.ReadLine().Split(' ');
                tv[i] = long.Parse(str[0]);
                tw[i] = long.Parse(str[1]);
            }
            for(int i=0;i<1 << n;i++){
                long vs = 0;
                long ws = 0;
                for(int k=0;k<20;k++){
                    if((i & (1 << k)) != 0){
                        vs += tv[k];
                        ws += tw[k];
                    }
                }
                v[i] = vs;
                w[i] = ws;
            }
            Array.Sort(w,v);
            List<long> dv = new List<long>();
            List<long> dw = new List<long>(); 
            int vp = 0;
            long lv = v[0] - 1;
            while(vp < v.Length){
                long maxv = v[vp];
                while(vp < v.Length - 1 && w[vp] == w[vp+1]){
                    vp++;
                    maxv = Math.Max(maxv,v[vp]);
                }
                if(lv < maxv){
                    lv = maxv;
                    dv.Add(lv);
                    dw.Add(w[vp]);
                }
                vp++;
            }
            if(j == 0){
                Av = dv.ToArray();
                Aw = dw.ToArray();
            }
            else{
                Bv = dv.ToArray();
                Bw = dw.ToArray();
            }
        }
        {
            int p = Aw.Length-1;
            long max = 0;
            for(int i=0;i<Bw.Length;i++){
                while(p >= 0 && Bw[i]+Aw[p] > W){
                    p--;
                }
                if(p == -1){
                    break;
                }
                else{
                    max = Math.Max(max,Bv[i]+Av[p]);
                }
            }
            sb.Append(max+"\n");
        }
    }
}

Measured memory_bytes: 42200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,start,end) for(int i=start; i<=end; i++)
#define repd(i,start,end) for(int i=start; i>=end; i--)
#define all(x) x.begin(),x.end()

void solve() {
	string s;
	cin >> s;
	ll ans=0;

	for(char c: s)
		ans+=c-'0';

	if(ans%9==0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


}

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

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

d, n = Is()
if n == 100:
    n += 1
print(n*100**d)


Measured memory_bytes: 63340
#define taskname "test"

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 5005;
const lli inf = 1e18;
int n, a, b;
int p[maxn];

lli dp[maxn][maxn];

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

void solve()
{
    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf);
    dp[1][1] = 0;
    for(int i = 2; i <= n; ++i)
    {
        dp[i][i] = 0;
        for(int j = 1; j < i; ++j)
        {
            if(p[j] < p[i]) dp[i][i] += b;
            else dp[i][i] += a;
        }
        for(int j = 1; j < i; ++j)
        {
            if(dp[i - 1][j] == inf) continue;
            if(p[j] < p[i])
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + a);
                dp[i][i] = min(dp[i][i], dp[i - 1][j]);
            }
            else /// p[j] > p[i]
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + b);
        }
    }
    lli ans = inf;
    for(int j = 1; j <= n; ++j)
        ans = min(ans, dp[n][j]);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}


Measured memory_bytes: 195968
# 2019-11-13 08:30:54(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    a, b = [int(x) for x in sys.stdin.readline().split()]
    if a >= 13:
        ans = b
    elif a >= 6:
        ans = b // 2
    else:
        ans = 0
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

template <typename T>
struct BIT {
    int siz;
    vector<T> bit;

    BIT(int N) : siz(N + 1), bit(siz) {}

    void add(int k, T x) {
        while (k < siz) {
            bit[k] += x;
            k += (k & -k);
        }
    }

    T sum(int k) {
        T res(0);
        while (k > 0) {
            res += bit[k];
            k -= (k & -k);
        }
        return res;
    }
};

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

    string S;
    cin >> S;

    int N = S.length();
    vector<int> cnt(26);
    vector<vector<int>> v(26);
    for (int i = 0; i < N; ++i)
        cnt[S[i] - 'a']++, v[S[i] - 'a'].emplace_back(i);

    int ocnt = 0;
    for (int i = 0; i < 26; ++i)
        ocnt += cnt[i] & 1;
    if ((N & 1 && ocnt >= 2) || (!(N & 1) && ocnt >= 1)) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> pos(N);
    int pcnt = 0;
    for (int i = 0; i < N; ++i) {
        int num = S[i] - 'a';
        if (v[num].back() < i)
            continue;

        if (v[num].back() == i) {
            pos[N / 2] = i;
            continue;
        }

        pos[pcnt] = i;
        pos[N - 1 - pcnt] = v[num].back();
        v[num].pop_back();
        pcnt++;
    }

    ll ans = 0;
    BIT<int> bit(N);
    for (int i = 0; i < N / 2; ++i) {
        int idx = pos[i] - bit.sum(pos[i] + 1);
        int ridx = pos[N - 1 - i] - bit.sum(pos[N - 1 - i] + 1);
        ans += (idx - i) + (N - 1 - i - ridx);
        bit.add(pos[N - 1 - i] + 1, 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5944
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
int n, m, a, c;
ll p;
ll gcd(ll a, ll b){
	for(; b; swap(a%=b,b));
	return a;
}
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n){
		scanf("%d", &a);
		int t = 1;
		for(; a%2==0; a/=2) t *= 2;
		if(!i) c = t, p = a;
		p = a * p / gcd(a,p);
		if(p > m || t != c) return 0*puts("0");
	}
	printf("%lld\n", (m + p*c/2) / (p*c));
}

Measured memory_bytes: 256
#include<stdio.h>
int commonfactor(int a ,int b)
{
	if(a%b==0)
	  return b;
	return commonfactor(b,a%b);
}
int main()
{
	int a,b,k;
	scanf("%d %d %d",&a,&b,&k);
	int n=1;
	int cf;
	int bcf;
	bcf=commonfactor(a,b);
	cf=bcf;
	int i;
	for(i=2;i<=bcf;i++)
	{
		if(n!=k)
		{
			if(bcf%i==0)
			{
				cf=bcf/i;
				n++;
			}
		}
	}
	printf("%d",cf);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
int main(void)
{
    int a,b;
    cin >> a >> b;
    if(a<6)pr(0);
    else if(a<13)pr(b/2);
    else pr(b);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define REPI(i, a, n)	for(ll (i)=(a);(i)<(int)(n);(i++))
#define REP(i,n) REPI(i,0,n)
#define REP1(i,n) for(ll (i)=1;(i)<=(n);(i++))
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;
 
	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
 
/*template<class T>
void VecUniqErs(vector<T> *v) {
	std::sort(ALL(v));
	&v.erase(unique(ALL(&v)), &v.end());
}*/

template<typename T>
int contains(std::vector<T> vec, int number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll fact(ll n) {
	ll m;
	if (n == 0) {
		return 1;
	}
	m = fact(n - 1);
	return n * m;
}
 
ll Combination(unsigned long long n, unsigned long long r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
 
struct vec {
	ll x, y;
 
	bool operator == (const vec &v) const{
		return x == v.x && y == v.y;
	}
 
};
 
namespace std {
	template<>
	class hash<vec> {
	public:
		size_t operator () (const vec& p) const { return p.x%SIZE_MAX; }
	};
}

int main() {
	ll N;
	cin >> N;
	vector<string> S(N);
	REP(i,N){
		cin >> S[i];
	}
	std::sort(ALL(S));
	S.erase(unique(ALL(S)), S.end());
	cout << S.size() << endl;

	return 0;
}

Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
int main() {
     string n;
     cin >> n;
     if(n[0] == n[1] && n[1] == n[2]) cout << "Yes" << endl;
     else if(n[1] == n[2] && n[2] == n[3]) cout << "Yes" << endl;
     else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N  = scan.nextInt();
        String S  = scan.next();
        int[] w = new int[N];
        int[] e = new int[N];
        for(int i=0;i<N;++i){
            if(S.charAt(i)=='E')e[i]++;
            else w[i]++;
        }
        for(int i=1;i<N;++i)w[i]+=w[i-1];
        for(int i=N-2;i>=0;--i)e[i]+=e[i+1];
        int ans = N;
        for(int i=0;i<N;++i){
            int res = 0;
            if(i>0)res+=w[i-1];
            if(i<N-1)res+=e[i+1];
            ans=Math.min(ans, res);
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 31176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int N;
pair<int, int> A[200001];//A_i, i

int main(){
  cin >> N;
  rep(i, N){
    int a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A, A + N);
  rep(i, N){
    if(A[N-1].second == i){
      cout << A[N-2].first <<endl;
    }else{
      cout << A[N-1].first <<endl;
    }
  }
}

Measured memory_bytes: 3200
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{

public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
       BufferedWriter out=new BufferedWriter(new OutputStreamWriter(System.out));
        int n=s.nextInt();
      // Stack<Integer>stk=new Stack<>();
       int res=-1,j=1;
       for(int i=0;i<n;i++){
       	int x=s.nextInt();
       	if(x==j){j++;}
       }
       if(j!=1) res=n-(j-1);
        out.write(res+"\n");
        out.flush();
  }
}


Measured memory_bytes: 65476
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, X[10];
	vector<long long> V[2];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> X[i];
	for (int i = 0; i < N; i++) {
		long long Y;
		cin >> Y;
		V[X[i]].push_back(Y);
	}
	if (V[0].empty() || V[1].empty()) {
		cout << 0 << endl;
		return 0;
	}
	sort(V[0].begin(), V[0].end());
	sort(V[1].begin(), V[1].end());
	cout << V[0][0] + V[1][0] << endl;
}


Measured memory_bytes: 3136
n,w=map(int,input().split())
l=[list(map(int, input().split())) for i in range(n)]
c=0
d=0
for i in range(n):
    c+=l[i][1];d+=l[i][0]
dp=[[0]*(c+1) for _ in range(n)]
for i in range(1,l[0][1]+1):
    dp[0][i]=l[0][0]
for i in range(l[0][1]+1,c+1):
    dp[0][i]=d
for i in range(1,n):
    for j in range(1,c+1):
        if j<=l[i][1]:
            dp[i][j]=min(dp[i-1][j],l[i][0])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i-1][j-l[i][1]]+l[i][0])
#print(dp)
for i in range(c,0,-1):
    if dp[-1][i]<=w:
        print(i)
        break

Measured memory_bytes: 119788
#include<iostream>

using namespace std;

int main(){

    int n;
    cin >> n;

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

    int ans = 0, highest = 0;
    for(int i=0;i<n;i++){
        if(h[i]>=highest){
            ans++;
            highest = h[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def D(n,d):
  r=0
  while n>0:
    r=r+n%d
    n=n//d
  return r

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

n=int(input())
s=int(input())
if n-s==0:
  print(n+1)
  exit()
if s>n:
  print(-1)
  exit()

A=make_divisors(n-s)
for i in range(len(A)):
  if D(n,A[i]+1)==s:
    print(A[i]+1)
    exit()
print(-1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll k,x;
	cin>>k>>x;

	ll a,b;
	a=max((ll)(-1000000),x-k+1);
	b=min((ll)1000000,x+k-1);
	for(ll i=a;i<=b;i++){
		cout<<i<<" ";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int n, k;
signed main() {
	cin >> n >> k;
	int p = 1, ans = 0;
	while (p <= n) {
		ans++;
		p *= k;
	}
	cout << ans << endl;
	ggr
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d;
  
  e = c/b;
  if (c%b > 0)
    e++;
  
  f = a/d;
  if (a%d > 0)
    f++;
    
  if (e <= f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



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


int main() {
    int N;
    cin >> N;
    vector<long> A(N);
    vector<long> B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cin >> B[i];
    }
    vector<int> indexArray(N);
    for (int i = 0; i < N; i++) {
        indexArray[i] = i;
    }
    sort(indexArray.begin(), indexArray.end(), [&B](long i1, long i2) {return B[i1] < B[i2];});
    long jikan = 0;
    for (auto i: indexArray) {
        long shimekiri = B[i];
        jikan = jikan + A[i];
        if (jikan > shimekiri) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    int arr[n+5][n+5];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i][0];
        for(int j=1;j<=m;j++)cin>>arr[i][j];
    }

    long long mk=1e12;

     for(int i=1;i<=pow(2,n);i++)
    {
        vector<int>v;
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                v.push_back(j+1);
            }
        }

       // for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;

       long long sum=0;
        int frr[m+5]={0};
        for(int i=0;i<v.size();i++)
        {
          int pk=v[i];
          sum+=arr[pk][0];
          for(int j=1;j<=m;j++)
          {
              frr[j]+=arr[pk][j];
          }
        }
        bool vr=true;
        for(int i=1;i<=m;i++)if(frr[i]<k)vr=false;
        if(vr)mk=min(mk,sum);
    }
    if(mk==1e12)cout<<-1<<endl;
    else cout<<mk<<endl;
}


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

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    
    int cnt = 0;
    int n;
    cin >> n;
    rep (i, n) {
        int x, y;
        cin >> x >> y;
        if (x == y) cnt++;
        else cnt = 0;
        if (cnt >= 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3636
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 998244353


def resolve():
    n, a = map(int, input().split())
    X = list(map(int, input().split()))
    MAX = sum(X)
    dp = [[[0] * (MAX + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        x = X[i - 1]
        for j in range(n + 1):
            for k in range(MAX + 1):
                dp[i][j][k] += dp[i - 1][j][k]
                if k + x < MAX + 1 and j + 1 <= n:
                    dp[i][j + 1][k + x] += dp[i - 1][j][k]
    res = 0
    for j in range(1, n + 1):
        total = a * j
        if total <= MAX:
            res += dp[n][j][total]
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 118116
N=int(input())

begins=['a']
while(len(begins[0])<N):
    _begins=[]
    for b in begins:
        n=len(set(b))
        for i in range(n+1):
            _begins.append(b+chr(ord('a')+i))
    begins=_begins

for b in sorted(begins):
    print(b)


Measured memory_bytes: 13884