akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

ORD_A = ord("a")


def str2list(s):
    return list(map(lambda c: ord(c) - ORD_A, s))


def list2str(xs):
    return "".join(map(lambda x: chr(x + ORD_A), xs))


def find_min(s, k):
    def to_a_cost(x):
        return (26 - x) % 26
    xs = str2list(s)
    n = len(s)
    for i in range(n):
        c = to_a_cost(xs[i])
        if c <= k:
            k -= c
            xs[i] = 0
    k %= 26
    for i in range(n)[::-1]:
        if xs[i] != 0:
            xs[i] += k
            break
    else:
        xs[-1] += k
    return list2str(xs)


def main():
    s = input()
    k = int(input())
    print(find_min(s, k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4980
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n1 = sc.nextInt();
    int n2 = sc.nextInt();
    int c1 = 0,c2 = 0;
    String s = sc.next();
    int count=0;
    int box[]=new int[n1];
    boolean ac = false;
    for(int i = 0;i < n1-1;i++){
        if(s.charAt(i)=='A'&&s.charAt(i+1)=='C'){
          count++;
    	}
      box[i+1]=count;
    }
    for(int l = 0;l < n2;l++){
      c1 = sc.nextInt();
      c2 = sc.nextInt();
      System.out.println(box[c2-1]-box[c1-1]);
    }
  }
}

Measured memory_bytes: 68752
double V[16],s,p;
int D,i,j,k,l;
main(){for(;scanf("%d",&D),D;){D+=3;
	for(i=0;i<D;++i)scanf("%lf",V+i);
	for(i=0;i<D;++i){
		for(j=0;j<D;++j)if(j!=i){
			for(s=k=0;k<D;++k)if(k!=i&&k!=j){
				p=V[k];
				for(l=0;l<D;++l)if(l!=k&&l!=i&&l!=j)p=p*(j-l)/(k-l);
				s+=p;
			}
			if(fabs(s-V[j])>0.1)break;
		}
		if(j==D){
			printf("%d\n",i);
			break;
		}
	}
}}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int s;
  cin >> s;
  vector<int> S;
  for(int i = 0;;i++){
    int a = s % 10;
    S.push_back(a);
    s /= 10;
    if(s == 0)break;
  }
  reverse(S.begin(),S.end());
  int siz = S.size();
  long int sum = 0;
  for(int bit = 0;bit < (1 << siz-1);bit++){//項に対して+の入る場所は-1になる
    long int inst = S[0];
    for(int i = 0;i < siz-1;i++){
      if(bit & (1<<i)){//(i,i+1の間)に+があるならそれまでの分を足して
        sum += inst;
        inst = S[i+1];//i+1項目をとりあえず入れる
      }else{
        inst = inst*10 + S[i+1];//+じゃないならば前までのを10倍して足す
      }
    }
    sum += inst;//最後の分
  }
  cout << sum << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int64_t> A(N);
    rep(i, N)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int tmp = 1, ans = 0;
    rep(i, N - 1)
    {
        //      cout << "A(i)=" << A[i] << endl;
        //    cout << "A(i+1)=" << A[i + 1] << endl;
        if (A[i] == A[i + 1])
        {
            tmp++;
        }
        else
        {
            if (tmp % 2 == 1)
            {
                ans++;
            }
            tmp = 1;
        }
    }
    if (tmp % 2 == 1)
        ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, C;
	cin >> N >> C;
	int x[N], v[N];
	rep(i, N) cin >> x[i] >> v[i];

	int vsum1[N + 1] = {};
	int vsum2[N + 1] = {};
	rep(i, N) vsum1[i + 1] = vsum1[i] + v[i];
	rep(i, N) vsum2[i + 1] = vsum2[i] + v[N - 1 - i];

	int Lsum[N + 1] = {};
	int LsumM[N + 1] = {};

	rep(i, N) Lsum[i + 1] = vsum1[i + 1] - x[i];
	rep(i, N) LsumM[i + 1] = max(LsumM[i], Lsum[i + 1]);


	int Rsum[N + 1] = {};
	int RsumM[N + 1] = {};
	rep(i, N) Rsum[i + 1] = vsum2[i + 1] - (C - x[N - 1 - i]);
	rep(i, N) RsumM[i + 1] = max(RsumM[i], Rsum[i + 1]);
	// cout << endl;
	// rep(i, N + 1) cout << LsumM[i] << " " <<Lsum[i] << " " << RsumM[i] << " " << Rsum[i] << endl;

	int ans = max(LsumM[N], RsumM[N]);
	// dump(ans);
	REP(i, 1, N) {
		int tmp1 = LsumM[N - i] + Rsum[i] - (C - x[N - i]);
		int tmp2 = RsumM[N - i] + Lsum[i] - x[i - 1];
		ans = max(ans, tmp1);
		ans = max(ans, tmp2);
		// dump(ans);
	}
	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6528
#[allow(unused_imports)]
use std::cmp::max;
use std::io;

fn main() {
    let input = input_number();
    let _n = input[0] as usize;
    let ai = input_number();

    let check = ai.iter().find(|x| **x == 0);
    if let Some(_) = check {
        println!("0");
        return;
    }

    let mut result = 1u64;
    let checker = 1000000000000000000u64;
    for value in ai {
        if result > checker {
            println!("-1");
            return;
        }
        if checker / result < value {
            println!("-1");
            return;
        }
        result = result * value;
    }
    println!("{}", result);
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn input_number() -> Vec<u64> {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<u64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: char = iter.next().unwrap().chars().nth(0).unwrap();
    let n: usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}


Measured memory_bytes: 4816
#include <iostream>

using namespace std;

int dp[1400][1400];

int main () {
  int H, W;
  cin>>H>>W;
  int ans=0;
  for (int h=0; h<H; ++h) {
    for (int w=0; w<W; ++w) {
      cin>>dp[h][w];
      dp[h][w] ^= 1;
      ans = max(dp[h][w], ans);
    }
  }

  for (int h=1; h<H; ++h) {
    for (int w=1; w<W; ++w) {
      if (dp[h][w] == 0) {
        dp[h][w] = 0;
      }
      else {
        dp[h][w] = min(dp[h-1][w-1], min(dp[h-1][w], dp[h][w-1])) + 1;
      }
      ans = max(dp[h][w], ans);
    }
  }

  cout<<ans*ans<<endl;


  return 0;
}


Measured memory_bytes: 10760
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
struct qujian
{
    int s;
    int e;
    int cc;
};
qujian qu[100005];
int edt[32],ch[32];
bool cmp(qujian x,qujian y)
{
    if(x.s==y.s)return x.e<y.e;
    return x.s<y.s;
}
int main()
{
    int n,c;
    scanf("%d%d",&n,&c);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d%d",&qu[i].s,&qu[i].e,&qu[i].cc);
    }
    sort(qu,qu+n,cmp);
    int tot=0;
    for(int i=0;i<n;i++)
    {
        int f=-1;
        for(int j=0;j<tot;j++)
        {
            if(qu[i].cc==ch[j])f=j;
            else if(edt[j]<qu[i].s)f=j;
            if(f!=-1)break;
        }
        if(f!=-1)
        {
            ch[f]=qu[i].cc;
            edt[f]=qu[i].e;
        }
        else
        {
            ch[tot]=qu[i].cc;
            edt[tot]=qu[i].e;
            tot++;
        }
    }
    printf("%d\n",tot);
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout); 
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x;
		cin>>x;
		n-=x;
		if(n<0){
			cout<<-1;
			return 0;
		}
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 3636
N = int(input())
values = []

for i in range(N):
  values.append(int(input()))
  
a = max(values)

copy_values = [v for v in values]

copy_values.remove(a)

if len(copy_values) == 0:
  b = a
else:
  b = max(copy_values)

for i in range(N):
  if values[i] == a:
    print(b)
  else:
    print(a)


Measured memory_bytes: 14076
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    int n, m;
    cin >> n >> m;
    vector<int> deg(n, 1);
    vector<bool> ball(n, 0);
    ball[0] = 1;

    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        if (ball[x]) {
            ball[y] = true;
            if (deg[x] == 1) {
                ball[x] = false;
            }
        }
        deg[x]--;
        deg[y]++;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += ball[i];
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end()
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int n; CI n;
	int ans = n / 111;
	if (n % 111) ans++;
	CO ans*111 EN;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

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

using namespace std;


class BUnevenNumbers {
public:
public:
    int N;
    int ans = 0;

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        FOR(i, 1, N+1) {
            if (to_string(i).length() % 2 != 0) ans++;
        }
        COUT(ans);
    }
};


int main() {
    BUnevenNumbers solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  var n = parseInt(input[0], 10);
  var str = '';
  var count = 0;
  var to = new Array(10);
  for(var i=0; i<10; i++){
    to[i] = new Array(10);
  	for(var j=0; j<10; j++){
     to[i][j] = 0;
    }
  }
  var count2 = 0;
  for(var i=1; i<=n; i++){
    str = i.toString(10);
    to[parseInt(str.charAt(0), 10)][parseInt(str.charAt(str.length-1), 10)]++;
    count += to[parseInt(str.charAt(str.length-1), 10)][parseInt(str.charAt(0), 10)]*2;
    if(parseInt(str.charAt(0), 10) == parseInt(str.charAt(str.length-1), 10)){
      count2++;
       }
  }
  console.log(count-count2);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 14256
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

int main() {

    int N, M;
    std::cin >> N >> M;

    std::vector<std::list<int>> nodes(N);
    std::vector<std::pair<int, int>> edges(M);
    for (int i = 0; i < M; ++i) {
        int a, b;
        std::cin >> a >> b;
        nodes[a - 1].push_back(b - 1);
        nodes[b - 1].push_back(a - 1);
        edges[i] = std::make_pair(a - 1, b - 1);
    }
    int ans = 0;
    for (int i = 0; i < M; ++i) {
        std::vector<bool> memo(N, false);
        std::queue<int> q;
        q.push(0);
        while (!q.empty()) {
            int from = q.front();
            q.pop();
            memo[from] = true;
            for (auto& to : nodes[from]) {
                if (
                    (edges[i].first == from && edges[i].second == to) ||
                    (edges[i].first == to && edges[i].second == from)
                    )continue;
                if (!memo[to]) {
                    q.push(to);
                }
            }
        }
        if (std::any_of(memo.begin(), memo.end(), [](auto a) { return !a; }))++ans;
    }

    std::cout << ans << std::endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;

bool isnp[10001];
int ans[10001];

int main(){
	for(int i = 2; i < 98; ++i){
		if( !isnp[i] ){
			for(int j = i * i; j <= 10000; j += i){
				isnp[j] = true;
			}
		}
	}

	vector<int> primes;
	for(int i = 2; i < 9999; ++i){
		if( !isnp[i] ) primes.push_back(i);
	}

	vector<int> sum(primes.size() + 1);
	for(int i = 0; i < primes.size(); ++i){
		sum[i+1] = sum[i] + primes[i];
	}

	for(int i = 1; i < sum.size(); ++i){
		for(int j = 0; j < i; ++j){
			if(sum[i] - sum[j] <= 10000){
				++ans[sum[i] - sum[j]];
			}
		}
	}
	
	int n;
	while(scanf("%d", &n), n != 0){
		printf("%d\n", ans[n]);
	}
}

Measured memory_bytes: 1120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int n = sc.nextInt();
			if (n % 1000 == 0) {
				System.out.println(0);
			} else {
				System.out.println(1000 - n % 1000);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  void solve() {
    string s;
    cin >> s;
    int ans = 0;
    string last = "";
    for (int i = 0; i < s.size(); ++i) {
      if (s.substr(i, 1) == last) {
        if (s.substr(i, 2) != last) {
          ans++;
          last = s.substr(i, 2);
          i++;
        } else {
          break;
        }
      } else {
        ans++;
        last = s.substr(i, 1);
      }
    }
    cout << ans << endl;
  }
};
class Solver2 {
 public:
  int n, m;
  Solver2(LL n, LL m) : n(n), m(m){};

  void solve() {
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);

  Problem::Solver sol;
  sol.solve();
  return 0;
}


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

int main() {
    string a, b;
    cin >> a >> b;

    if (a.size() > b.size())
        cout << "GREATER" << endl;
    else if (a.size() < b.size())
        cout << "LESS" << endl;
    else if (a == b)
        cout << "EQUAL" << endl;
    else {
        rep(i, a.size()) {
            int A = a[i] - '0';
            int B = b[i] - '0';
            if (A > B) {
                cout << "GREATER" << endl;
                break;
            } else if (A < B) {
                cout << "LESS" << endl;
                break;
            }
        }
    }

    return 0;
}


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

int main() 
{   
  

 
long long int n;
scanf("%lld",&n);
long long int h[n];

    for(long long int i = 0; i <n; i++){
   
scanf("%lld",&h[i]);
}
long long int dp[n];
dp[0]=0;
dp[1]=abs(h[0]-h[1]);
 for(long long int i = 2; i <n; i++){
   
dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
}
printf("%lld\n",dp[n-1]);


}

  
 

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int a, b, ans1, ans2;
    double ans3;
    
    scanf("%d%d", &a, &b);
    
    ans1 = a / b;
    ans2 = a % b;
    ans3 = (double)a / (double)b;
    
    printf("%d %d %.5f\n", ans1, ans2, ans3);
    
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>

using namespace std;

int main() {
    int N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    
    S = "#" + S + "#";

    auto can_reach = [&](int start, int end) {
        for (int i = start; i + 1 <= end; i++) {
            if (S[i] == '#' && S[i + 1] == '#') return false;
        }
        return true;
    };

    if (!can_reach(A, C) || !can_reach(B, D)) {
        cout << "No" << endl;
        return 0;
    }

    if (C > D) {
        bool snuke_can_over = false;
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                snuke_can_over = true;
            }
        }
        if (!snuke_can_over) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3912
from collections import deque
n, m = map(int, input().split())
E = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)
flag = [True for _ in range(n)]
ans = 0
for i in range(n):
    if flag[i]:
        counter = 1
        flag[i] = False
        que = deque([i])
        while que:
            now = deque.popleft(que)
            for j in E[now]:
                if flag[j]:
                    deque.append(que, j)
                    counter += 1
                    flag[j] = False
        ans = max(ans, counter)
print(ans)

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

using namespace std;

using LL = long long;

const int N = (int)1e5 + 5, LOG = 60;
int n, num[LOG];
LL a[N], xorSum, mx, ans;
vector<LL> basis;

int leftSetBit(LL val) { return val ? (int)__lg(val) : -1; }

void updBasis(LL val) {
    for (vector<LL>::iterator it = basis.begin(); it != basis.end(); ++it) {
        int tmp1 = leftSetBit(*it), tmp2 = leftSetBit(val);
        if (tmp1 == tmp2) val ^= *it;
        else if (tmp1 < tmp2) {
            basis.insert(it, val);
            val = 0;
            break ;
        }
    }
    if (val) basis.push_back(val);
    assert( (int)basis.size() <= LOG);
}

bool testBit(LL _a, int _bit) { return (_a >> _bit) & 1; }

int main() {
    scanf(" %d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf(" %lld", a + i);
        for (int j = 0; j < LOG; ++j) if (testBit(a[i], j) ) ++num[j];
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < LOG; ++j) if (testBit(a[i], j) && (num[j] & 1) ) a[i] ^= (1LL << j);
        updBasis(a[i]);
    }

    for (int i = 0; i < LOG; ++i) if (num[i] & 1) ans |= (1LL << i);

    for (LL _ : basis) {
        if (!testBit(mx, leftSetBit(_) ) ) mx ^= _;
    }

    printf("%lld", ans + (mx << 1) );

    return 0;
}


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

long long arr[3000][3000];

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

    long long x,sum=0,temp,ans;
    cin>>x;

    for(int i=0;i<n;i++)
    {
        cin>>arr[0][i];
        sum+=arr[0][i];
    }
    ans=sum;
    for(int i=1;i<=n;i++)
    {
        temp=sum+x;
        for(int j=0;j<n;j++)
        {
            arr[i][j]=arr[i-1][j];
            if(arr[i-1][j]>arr[i-1][(j-1+n)%n])
            {
                temp-=arr[i-1][j]-arr[i-1][(j-1+n)%n];
                arr[i][j]=arr[i-1][(j-1+n)%n];
            }
        }

        sum=temp;
        ans=min(ans,sum);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 39424
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

int n;

void read()
{
	cin >> n;
}

void solve()
{
	vector<int> answer; 
	
	int c = 0;
	n -= 2;
	answer.push_back(3);
	answer.push_back(9);

	if(n == 1)
	{
		cout << "2 5 63" << endl;
		return;
	}

	while(n >= 2 && c + 4 <= 30000)
	{
		answer.push_back(c + 2);
		answer.push_back(c + 4);
		c += 6;
		n -= 2;
	}

	c = 12;
	while(n >= 2 && c + 9 <= 30000)
	{
		answer.push_back(c + 3);
		answer.push_back(c + 9);
		c += 12;
		n -= 2;
	}

	c = 0;
	while(n)
	{
		answer.push_back(c + 6);
		c += 6;
		n -= 1;
	}

	for(int x: answer) cout << x << " ";
	cout << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}



Measured memory_bytes: 640
import math

N, M = map(int, input().split())

if N == M:
    print(2*pow(math.factorial(N), 2) % (10**9+7))
elif abs(N-M) == 1:
    print(math.factorial(N)*math.factorial(M) % (10**9+7))
else:
    print(0)

Measured memory_bytes: 5180
#include <iostream>
#define D 6
using namespace std;

class dice {
    int f[D];
public:
    dice(int n[]) {
        for (int i = 0; i < D; i++)
            f[i] = n[i];
    }
    
    void roll(int a, int b, int c, int d) {
        int t = f[a];
        f[a] = f[b];
        f[b] = f[c];
        f[c] = f[d];
        f[d] = t;
    }
    
    void rollX() { roll(0, 2, 5, 3); }
    void rollY() { roll(0, 1, 5, 4); }
    void rollZ() { roll(1, 2, 4, 3); }
    
    bool friend same(dice d1, dice d2);
};

bool same(dice d1, dice d2)
{
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 4; j++) {
            int k = 0;
            while (1) {
                if (d1.f[k] == d2.f[k]) {
                    k++;
                    if (k == D)
                        return true;
                } else {
                    break;
                }
            }
            d1.rollZ();
        }
        if (i % 2 == 0)
            d1.rollY();
        else
            d1.rollX();
    }
    return false;
}

int main()
{
    int num[D], q;
    
    for (int i = 0; i < D; i++)
        cin >> num[i];
    dice d1(num);
    for (int i = 0; i < D; i++)
        cin >> num[i];
    dice d2(num);
    
    cout << (same(d1, d2) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            var A = GetIntArray();
            var B = Enumerable.Range(1, N).Select(s => A[s - 1] - s).OrderBy(s=>s).ToArray();
            long ans = 0;
            for(int i = 0; i < N; i++)
            {
                ans += Math.Abs(B[i] - B[N / 2]);
            }

            Console.Write(ans);
        }



        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

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

using namespace std;

int
main()
{
    int64_t a,b,c,k;
    cin >> a >> b >> c >> k;

    if((a + b) >= k){
        if(a < k)
            cout << a << endl;
        else {
            cout << k << endl;
        }
        return 0;
    }

    int64_t d = k - (a + b);
    if(c < d)
        cout << a - c << endl;
    else
        cout << a - d << endl;

    return 0;

}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;	
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}

void solve() {
	string a, b;
	cin >> a >> b;
	reverse(b.begin(), b.end());
	if (a == b) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}     	

Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 2;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    for j in 0..26 {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


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

int main() {
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    rep(i,n) {
        cin>>x[i];
        y[i]=x[i];
    }
    sort(y.begin(),y.end());
    rep(i,n) {
        if (x[i]<=y[n/2-1]) cout<<y[n/2]<<endl;
        else cout<<y[n/2-1]<<endl;
    }
}


Measured memory_bytes: 3712
#include<stdio.h>
#define N 10000

int G[N][N];

int main(){
  int n,i,j,k,b[N],a[N];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&b[j]);
      G[a[i]][b[j]] = 1;
    }
  }

 
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",G[i][j]);
      if(j < n){
      printf(" ");
      }
    }
    printf("\n");
    }

  return 0;
}



Measured memory_bytes: 2192
X, Y, A, B, C = map(int, input().split())
*p, = map(int, input().split())
*q, = map(int, input().split())
*r, = map(int, input().split())

p.sort(reverse=True)
q.sort(reverse=True)

l = p[:X]+q[:Y]+r
l.sort(reverse=True)
print(sum(l[:X+Y]))

Measured memory_bytes: 119148
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> p;
typedef long long ll;
typedef pair<ll,ll> pll;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;
const ll MOD=1e9+7;
ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%MOD;
        a=a*a%MOD;
        x>>=1;
    }
    return res;
}
int main(){
    int N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;++i) cin>>A[i];
    vector<vector<ll> > prime(N,vector<ll>(1e3+1,0));
    map<ll,int> big;
    for(int i=0;i<N;++i){
        for(int j=2;j*j<=A[i];++j){
            if(A[i]%j==0){
                while(A[i]%j==0){
                    A[i]/=j;
                    prime[i][j]++;
                }
            }
        }
        if(A[i]>1){
            if(A[i]<=1e3){
                prime[i][A[i]]++;
                A[i]=1;
            }
            else{
                big[A[i]]++;
            }
        }
    }
    vector<ll> m(1e3+1,0);
    for(int j=0;j<=1e3;++j){
        for(int i=0;i<N;++i){
            m[j]=max(m[j],prime[i][j]);
        }
    }
    vector<vector<ll> > Bp(N,vector<ll>(1e3));
    for(int i=0;i<N;++i){
        for(int j=0;j<=1e3;++j){
            Bp[i][j]=m[j]-prime[i][j];
        }
    }
    vector<ll> B(N,1);
    for(int i=0;i<N;++i){
        for(int j=2;j<=1e3;++j){
            B[i]=B[i]*power(j,Bp[i][j])%MOD;
        }
    }
    bool ok=true;
    if((int)big.size()!=0){
        for(auto it:big){
            if(it.second<N) ok=false;
        }
    }
    if(!ok){
        for(auto it:big){
            for(int i=0;i<N;++i){
                if(A[i]!=it.first) B[i]=B[i]*it.first%MOD;
            }
        }
    }
    ll ans=0;
    for(int i=0;i<N;++i){
        ans=(ans+B[i])%MOD;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 161016
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int x,i,j,y,a[1005];
    scanf("%d",&x);
    memset(a,0,sizeof(a));
    a[1]=1;
   for(i=2;i<=1000;i++)
   {
       y=i;
       for(j=2;pow(i,j)<=1000;j++)
       {
           y=y*i;
           a[y]=1;
       }
   }
   for(i=x;i>=0;i--)
   {
       if(a[i]==1)
        break;
   }
   printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> x(5); // int型の配列変数xを宣言
  
  for (int i = 0; i < 5; i++){
   cin >>  x.at(i);
  }
 
  
  int answer = 0;
  //x = { 1, 2, 3, 0, 5 }; 
  for (int i = 0; i < 5; i++){
  if(x.at(i) == 0){
    //cout << "A"<<endl;
    answer = i+1;
    cout << answer;
    break;
  }
   else{
     //cout <<"B";
     //cout <<i<<endl;
     answer = answer;
   }
      
 
    
  }
  
}


Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10 ** 7)

def solve(g, p, index, y, z, k):
    p[index] = k - y - z
    x = 1
    for i in g[index]:
        if p[i] == -1:
            solve(g, p, i, x, y, k)
            y += 1

def main():
    n, k = map(int, input().split())
    graph =[[] for _ in range(n)]
    p = [-1]*n
    for _ in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)
    s = None
    for i in range(n):
        if len(graph[i]) == 1:
            s = i
            break
    if s is None:
        print(k)
        sys.exit()
    solve(graph, p, s, 0, 0, k)
    ans = 1
    for i in p:
        ans *= i
        ans %= 10**9 + 7
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 113328
from sys import stdin
N = int(stdin.readline().rstrip())
XY = [[] for _ in range(N)]
for i in range(N):
    A = int(stdin.readline().rstrip())
    for j in range(A):
        x, y = [int(_) for _ in stdin.readline().rstrip().split()]
        XY[i].append([x-1, y])

ans = 0
for i in range(2 ** N):
    flag = True
    for j in range(N):
        if ((i >> j) & 1) == 1:
            for x, y in XY[j]:
                if ((i >> x) & 1) != y:
                    flag = False
                    break
    if flag:
        ans = max(ans, bin(i).count('1'))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int x[100000];
int main(){
	int a,b,s;
	cin>>a>>b>>s;
	for(int i=0;i<a;i++) cin>>x[i];
	int sa=abs(x[a-1]-s);
	if(a!=1) sa=max(sa,abs(x[a-2]-x[a-1]));
	cout<<sa<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
S = input()
W = [0] * (n+1)
w = 0
ans = float("inf")

for i in range(n):
    if S[i] == "W":
        w += 1
    
    W[i+1] = w
    
for i in range(n):
    res = W[i] + ((n-W[n]) - (i+1-W[i+1]))
    ans = min(ans,res)
    
print(ans)

Measured memory_bytes: 15244
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int n;
    int k;
    scanf("%d %d" , &n ,&k);

    if(n%k==0){
        puts("0");
    }else{
        puts("1");
    }
    return 0;

}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int r; cin >> r;
  cout << r*r << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, s: String);

    let mut count = 0;
    let mut buff = 'A';
    for sv in s.chars() {
        if buff != sv {
            buff = sv;
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2288
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
	ll n,x,m;
	cin >> n >> x >> m;
	vector<int> memo(m,0);
	int idx = 1;
	memo[x] = idx;
	vector<ll> ans_tot;
	ans_tot.push_back(0);
	ans_tot.push_back(x);
	ll loop_start;
	ll loop_end;
	bool isloop = false;
	while(idx < n){
		idx++;
		ll now = x*x % m;
		if(memo[now] != 0){
			loop_start = memo[now];
			loop_end = idx-1;
			isloop = true;
			break;
		}
		x = now;
		memo[now] = idx;
		ans_tot.push_back(ans_tot[idx-1]+now);
	}
	ll ans = 0;
	if(isloop){	
		ans += ans_tot[loop_start-1];
		ll loop_sum = ans_tot[loop_end] - ans_tot[loop_start-1];
		ll loop_length = loop_end - loop_start + 1;
		ll loop_count = (n-loop_start+1) / loop_length;
		ll res = (n-loop_start+1) % loop_length;
		ans += loop_sum * loop_count;
		ans += ans_tot[loop_start+res-1] - ans_tot[loop_start-1];
	}
	else ans = ans_tot.back();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4204
fun main(args: Array<String>) {
    val (n, x0) = readLine()!!.split(" ").map(String::toInt)
    val x = readLine()!!.split(" ").map(String::toInt).map{abs(x0 - it)}.reduce{a, b -> gcd(a, b)}
    print(x)
}

tailrec fun gcd(a: Int, b: Int): Int {
    if(b == 0) return a
    return gcd(b, a % b)
}

fun abs(n: Int): Int {
    return if (n >= 0) n else -n
}

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

typedef long long ll;
ll MOD = 1e7 + 7, n ;
pair <double, double> pt[10] ;
vector<pair<double, double> > vec ;
bool visit[10] ;
double val = 0, combo = 0 ;

void checkAll(ll len)
{
  if(len == n) {
    combo++ ;
    for(int i = 0; i < vec.size() - 1; i++) {
      val += sqrt( (abs(vec[i].first - vec[i + 1].first) * abs(vec[i].first - vec[i + 1].first) ) + (abs(vec[i].second - vec[i + 1].second) * abs(vec[i].second - vec[i + 1].second) ) ) ;
    }
  }

  for(int i = 0; i < n; i++) {
    if(!visit[i]) {
      vec.push_back(pt[i]) ;
      visit[i] = true ;
      checkAll(len + 1) ;
      visit[i] = false ;
      vec.pop_back() ;
    }
  }
  return ;
}

int main()
{
  cin >> n ;
  pt[n] ;
  for(int i = 0; i < n; i++) {
    cin >> pt[i].first >> pt[i].second ;
  }
  memset(visit, false, sizeof visit) ;

  checkAll(0) ;
  val /= combo ;

  cout << setprecision(15) << val << endl ;
}


Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())

to = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

q = deque([1])
dist = [-1] * (n + 1)
# print(to)

while q:
    v = q.popleft()

    for u in to[v]:
        if dist[u] != -1:
            continue
        q.append(u)
        dist[u] = v

print("Yes")
# print(dist)

for i in range(2, n + 1):
    print(dist[i])


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

#define rep(i,a,b)     for(int i=a;i<(b);i++)
#define lop(n)         for(int i=0;i<n;i++)
#define revlop(n)      for(int i=n-1;i>=0;i--)
#define trav(a,x)      for(auto &a :x)
#define all(x)         begin(x),end(x)
#define mod            1000000007
#define inf            1e18
#define ps(x,y)        fixed<<setprecision(y)<<x
#define w(x)           int x; cin>>x;

#define pb             push_back
#define mp             make_pair
#define lb             lower_bound
#define ub             upper_bound
#define bs             binary_search
#define F              first
#define S              second

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

void solve()
{
  int n, x, t;
  cin >> n >> x >> t;

  int c = n / x;

  if (n % x)
    c++;

  cout << t*c;
}

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int test = 1;
  //cin >> test;

  while (test--)
  {
    solve();
    cout << "\n";
  }

  return 0;
}

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

signed main(){
	int n;
	std::cin >> n;
	std::vector<ll> a(n);
	for(int i = 0; i < n; i++) std::cin >> a[i];
	ll ans = 1000, now = a[0];
	for(int i = 1; i < n; i++){
		if(a[i] > now){
			ans += (ans / now) * (a[i] - now);
			now = a[i];
		}
		if(a[i] < now) now = a[i];
	}
	std::cout << ans << std::endl;
}


Measured memory_bytes: 3576
# ABC 079 C Train Ticket
S = [i for i in list(input())]

for i in range(2**(len(S)-1)):
  ops = [S[0]]
  for j in range(len(S)-1):
    if (i >> j) & 1:
      ops.append("+")
      ops.append(S[j+1])
    else:
      ops.append("-")
      ops.append(S[j+1])
      
  expr = "".join(ops)
  if eval(expr) == 7:
    print(expr + "=7")
    break

Measured memory_bytes: 3064
/**
*    created: 30.06.2020 16:22:41
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

namespace AtCoder
{
    class Abc165D
    {
        public static void Main()
        {
            var abn = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            var a = abn[0];
            var b = abn[1];
            var n = abn[2];

            var k = n < b ? n : b - 1;
            Console.WriteLine(a * k / b);
        }
    }
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint a;cin >> a;
    //vector<lint> v(n);
    set<lint> s;
    s.insert(a);
    REP(i, 1000000) {
        if(a%2==0){
            a /= 2;
        }else{
            a = 3 * a + 1;
        }
        if(s.count(a)){
            cout << i+2 << "\n";

            return 0;
        }
        s.insert(a);
    }

    
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int h;
    int n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }

    vi dp(h+1, INF);
    dp[0] = 0;
    rep(i, n) {
        rep(j, h+1) {
            if(j+a[i] < h) {
                dp[j+a[i]] = min(dp[j+a[i]], dp[j]+b[i]);
            } else {
                dp[h] = min(dp[h], dp[j]+b[i]);
            }
        }
    }

    cout << dp[h] << endl;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,a,b = readInts()
X = readInts()
ans = 0
for i in range(1,n):
    ans += min(b, (X[i]-X[i-1])*a)
print(ans)


Measured memory_bytes: 22256
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int n;
  int *s;
  vector<double> out;
  while(1){
    scanf("%d", &n);
    if(n == 0)
      break;
    else{
      s = new int[n];
      double a = 0;
      for(int i = 0; i < n; i++){
	scanf("%d", &s[i]);
	a += s[i];
      }
      double avg = a / n;
      double k = 0;
      for(int i = 0; i < n; i++){
	double j = s[i] - avg;
	k += j * j;
      }
      double var = k / n;
      out.push_back(sqrt(var));
      delete[] s;
    }
  }
  while(!out.empty()){
    printf("%.8f\n", out.front());
    out.erase(out.begin());
  }
  return 0;
}

Measured memory_bytes: 1088
import math
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=0
t=0
for i in range(len(a)):
    k=0
    p=0
    for j in range(i+1,n):
        if a[i]>a[j]:
            k+=1
        if b[i]>b[j]:
            p+=1
    m=math.factorial(n-i-1)
    s+=m*k
    t+=m*p
 

print(abs(s-t))


Measured memory_bytes: 38256
n = input()
t = map(int, raw_input().split())
v = map(int, raw_input().split())
t = [2 * i for i in t]
v = [2 * i for i in v]
f = [1000 for i in range(sum(t) + 1)]

s = 0
for i in range(n):
	for j in range(s, s + t[i] + 1):
		f[j] = min(f[j], v[i])
	s += t[i]
f[0] = 0
f[s] = 0

for i in range(1, s + 1):
	f[i] = min(f[i], f[i - 1] + 1)

for i in range(s)[::-1]:
	f[i] = min(f[i], f[i + 1] + 1)

print (sum(f[:-1]) + sum(f[1:])) / 8.0

Measured memory_bytes: 4588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        String s = next();
        int res = Integer.MAX_VALUE;
        for (char c = 'a'; c <= 'z'; c++) {
            if (s.indexOf(c) == -1) continue;
            int max = 0;
            int l = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == c) l = -1;
                l++;
                max = Math.max(max, l);
            }
            res = Math.min(res, max);
        }
        out.println(res);
    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 23252
#include<stdio.h>

#define N 500000
#define SENTINEL 10000000000

int count=0;

int main()
{
  int A[N],n,i;

  scanf("%d",&n);
  for(i = 0; i < n ; i ++){
    scanf("%d",&A[i]);
  }
  
  Merge_Sort(A,0,n);
  
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i < n-1){
      printf(" ");
    }
  }
  
  printf("\n%d\n",count);

  return 0;
  
} 



void Merge(int A[],int left,int mid,int right){
  int n1,n2;
  int i,j,k;
  int L[N],R[N];
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i = 0; i < n1; i ++){
    L[i] = A[left + i];
  }
  for(i = 0; i < n2; i ++){
    R[i] = A[mid + i];
  }
  
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  
  i = 0;
  j = 0;
 
  
  for (k = left; k <= right-1; k ++)
    {
      count++;
      if (L[i] <= R[j]){
	A[k] = L[i];
	i ++;
      }else{
	A[k] = R[j];
	j ++;
      }
    }
}

void Merge_Sort(int A[],int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    Merge_Sort(A, left, mid);
    Merge_Sort(A, mid, right);
    Merge(A,left,mid,right);
  }
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dp = Enumerable.Repeat(int.MaxValue, n + 1).ToArray();
            dp[0] = 0;

            for (var i = 1; i <= n; i++)
            {
                for (var six = 1; six <= i; six *= 6)
                    dp[i] = Math.Min(dp[i], dp[i - six] + 1);
                for (var nine = 1; nine <= i; nine *= 9)
                    dp[i] = Math.Min(dp[i], dp[i - nine] + 1);
            }

            Console.WriteLine(dp[n]);
        }
    }
}


Measured memory_bytes: 13268