akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main()
{
  int n, i, j,  minj, A, count;
  int data[99];
  count = 0;
   
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &data[i]);
  }
  
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(data[j] < data[minj]){
        minj = j;
      }
    }
    A = data[i];
    data[i] = data[minj];
    data[minj] = A;
    if(i != minj){
      count++;
    }
  }

  
  printf("%d", data[0]);
  for(i = 1; i < n; i++){
    printf(" %d", data[i]);
  }
  printf("\n%d\n", count);
}

Measured memory_bytes: 1848
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
P=list(map(int,input().split()))
for i in range(200):
  if x-i not in P:
    print(x-i)
    exit()
  elif x+i not in P:
    print(x+i)
    exit()

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

vector<vector<int> > G(300030);
vector<ll> dist(300030,-1);

int main(){
    ll N,M; cin >> N >> M;
    for (int i = 0; i < M; i++){
        int u,v; cin >> u >> v; u--, v--;
        G[3*u].push_back(3*v+1);
        G[3*u+1].push_back(3*v+2);
        G[3*u+2].push_back(3*v);
    }
    ll S,T; cin >> S >> T; S--, T--;

    queue<ll> que;
    que.push(3*S);
    dist[3*S] = 0;
    while (que.size()){
        ll now = que.front();
        que.pop();
        for (auto e : G[now]){
            if (dist[e] != -1) continue;
            dist[e] = dist[now]+1;
            que.push(e);
        }
    }
    if (dist[3*T] == -1){
        cout << -1 << endl;
    } else {
        cout << dist[3*T]/3 << endl;
    }
}


Measured memory_bytes: 18944
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  if (2 * C > A + B) {
    cout << A * X + B * Y << endl;
    return 0;
  }

  ll answer = 0;
  for (ll i = 0; i <= 100'100; i++) {
    answer = 2 * C * i;
    if (i == X) {
      const ll rest = Y - i;
      answer += min(B * rest, 2 * C * rest);
      break;
    }
    if (i == Y) {
      const ll rest = X - i;
      answer += min(A * rest, 2 * C * rest);
      break;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main(){
    int N, W;
    cin >> N >> W;
    int item[N+1][2];
    item[0][0] = 0; item[0][1] = 0;
    for (int i = 1; i < N+1; ++i){
        int v, w;
        cin >> v >> w;
        item[i][0] = v; item[i][1] = w;
    }
    int c[N+1][W+1];
    for(int i = 0; i < W+1; i++){
        c[0][i] = 0;
    }
    for(int j = 0; j < N+1; j++){
        c[j][0] = 0;
    }
    for(int i = 1; i < N+1; ++i){
        int v = item[i][0];
        int w = item[i][1];
        for(int j = 1; j < W+1; ++j){
            if(j < w){
                c[i][j] = c[i-1][j];
            }else{
                c[i][j] = max(c[i-1][j], c[i-1][j-w] + v);
            }
        }
    }
    cout << c[N][W] << endl; 
}

Measured memory_bytes: 7036
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
long long ipow(long long a, long long b)
{
    if(b==0) return 1;
    long long ans = ipow(a, b/2);
    ans *= ans; ans%=MOD;
    if(b&1) ans *= a; ans %= MOD;
    return ans;
}
long long fact[202020];
long long invfact[202020];
long long solve(int n, int r)
{
    long long ans = fact[n+r]*invfact[r]%MOD;
    return ans * invfact[n] % MOD;
}
int main()
{
    fact[0] = 1; invfact[0] = 1;
    for(int i=1; i<202020; ++i)
    {
        fact[i] = i*fact[i-1] % MOD;
        invfact[i] = ipow(fact[i], MOD-2);
    }
    int H, W, A, B;
    scanf("%d%d%d%d", &H, &W, &A, &B);
    long long ans = 0;
    for(int i=0; i<H-A; ++i)
    {
        ans += solve(B-1, i) * solve(W-B-1, H-i-1) % MOD; 
    }
    ans %= MOD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3456
from collections import deque

K=int(input())
q=deque([i for i in range(1,10)])
for _ in range(K-1):
  x=deque.popleft(q)
  a=x%10
  if a!=0 and a!=9:
    deque.append(q,x*10+a-1)
    deque.append(q,x*10+a)
    deque.append(q,x*10+a+1)
  elif a==0:
    deque.append(q,x*10)
    deque.append(q,x*10+1)
  else:
    deque.append(q,x*10+8)
    deque.append(q,x*10+9)
print(deque.popleft(q))

Measured memory_bytes: 18936
#include <iostream>
#include <string>
#define NIL 0
using namespace std;

struct BTNode{
  int key;
  BTNode *parent;
  BTNode *left;
  BTNode *right;
};

BTNode *root = NIL;

void insert(int value){
  BTNode *x = root;
  BTNode *y = NIL;
  BTNode *z = new BTNode;
  z->key = value;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(BTNode *x){
  if(x == NIL) return;
  inorder(x->left);
  cout << " " << x->key;
  inorder(x->right);
}

void preorder(BTNode *x){
  if(x == NIL) return;
  cout << " " << x->key;;
  preorder(x->left);
  preorder(x->right);
}

int main(){
  int n, v;
  string cmd;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> cmd;
    if(cmd == "insert"){
      cin >> v;
      insert(v);
    }
    else if(cmd == "print"){
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 26452
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long a[114514];
    a[1]=1;
    for(int i=2;i<114514;i++){
        a[i]=(a[i-1]*i)%1000000007;
    }
    cout<<a[n]<<endl;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var K = ReadLong();
            var (A, B) = Read2Longs();

            for (long i = A; i <= B; i++)
            {
                if (i % K == 0) return "OK";
                {

                }
            }

            return "NG";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28212
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>

using namespace std;

int main(){

    int V, E;
    cin >> V >> E;
    vector<vector<int>> edge(V);
    vector<int> count_in(V);
    for(int i = 0; i < V; i++){
        count_in[i] = 0;
    }

    int s, t;
    for(int i = 0; i < E; i++){
        cin >> s >> t;
        edge[s].emplace_back(t);
        count_in[t]++;
    }

    queue<int> q;
    for(int i = 0; i < V; i++){
        if(count_in[i] == 0){
            q.push(i);
        }
    }

    vector<int> ans;

    while(!q.empty()){
        int temp = q.front();
        q.pop();

        if(count_in[temp] == 0){
            ans.emplace_back(temp);
            for(int i = 0; i < (int)edge[temp].size(); i++){
                int to = edge[temp][i];
                count_in[to]--;
                if(count_in[to] == 0){
                    q.push(to);
                }
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 3708
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N, K;
	string S;
	cin >> N >> K;
	cin >> S;
	switch (S[K-1]) {
		case 'A':
			S[K-1] = 'a';
			break;
		case 'B':
			S[K-1] = 'b';
			break;
		case 'C':
			S[K-1] = 'c';
			break;
	}
	cout << S << endl;


	return 0;
}



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

long long dp[100002][105];
long long a[100005];
long long w[100005];
long long v[100005];

int main()
{
    long long n , W;

    cin >> n >> W;

    long long cur = 0;

    for(long long i = 1 ; i<=n ; i++)
    {
        cin >> w[i] >> v[i];
        cur+=v[i];
    }

    long long ans = 0;

    for(int i = 1 ; i<=cur ; i++)
        for(int j = 0 ; j<=n ; j++)
            dp[i][j] = 1000000000000;

    for(long long i = 1 ; i<=cur ; i++)
    {
        for(int j = 1 ; j<=n ; j++)
        {
            if(v[j]<=i)
            {
                dp[i][j] = min(dp[i][j-1] , dp[i-v[j]][j-1]+w[j]);
            }
            else
            {
                dp[i][j] = dp[i][j-1];
            }

            if(dp[i][j]<=W)
                ans = max(ans , i);
        }
    }

    cout <<  ans;

    return 0;
}


Measured memory_bytes: 82560
string = input()
rep = int(input())
for i in range(rep):
    l = input().split()
    query = l[0]
    a = int(l[1])
    b = int(l[2])

    if   query == "print":
        print(string[a:b+1])
    elif query == "reverse":
        string = string[:a] + string[a:b+1][::-1] + string [b+1:]
        #print(f"str:{string}")
    elif query == "replace":
        p = l[3]
        string = string[:a] + p + string [b+1:]
        #print(f"str:{string}")


Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const long long LINF = 1000000000000000018ll;
const int INF = 1000000009;
const int mod = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int n; cin >> n;
  vector<vector<int>> dp(n+1, vector<int>(3, 0));

  vector<vector<int>> abc(n+1, vector<int>(3, 0));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> abc[i][j];
    }
  }

  // dp[i][j] := i日目に j {a, b, c} を選んだときの幸福度の総和の最大値
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) { continue; } // 前と同じ活動はできない
        dp[i+1][j] = max(dp[i+1][j], dp[i][k] + abc[i][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    ans = max(ans, dp[n][i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11264
S = input()[::-1]
word = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]
judge = [True, True, True, True]
count = 0
while any(judge):
  for i in range(len(word)):
    if S[:len(word[i])] == word[i]:
      S = S[len(word[i]):]
    else:
      count += 1
    if S == '':
      print('YES')
      exit()
    if count == 4:
      print('NO')
      exit()
  count = 0

Measured memory_bytes: 9136
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        k: usize,
        s: chars,
    }
    let mut k = k;
    if s[0] == 'R' {
        for i in 0..n {
            if s[i] == 'L' {
                s[i] == 'R';
            } else {
                s[i] == 'L';
            }
        }
    }

    let mut result = 0;
    for i in 1..n {
        if s[i - 1] == s[i] {
            result += 1;
        }
    }

    let mut right = n - 1;
    while s[0] != s[right] {
        right -= 1;
    }
    let right_r = n - right - 1;

    let mut count = 0;
    for i in 0..right {
        if s[i] != s[i + 1] {
            count += 1;
        }
    }
    if count / 2 > k {
        result += 2 * k;
        k = 0;
    } else {
        result += count;
        k -= count / 2;
    }

    if k > 0 && right_r > 0 {
        result += 1;
    }
    println!("{}", result);
}


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

constexpr int MAX_N = 100000, INF = 2147483647;

int n, q;

int seg[MAX_N * 4], lazy[MAX_N * 4];

bool flag[MAX_N * 4];

void init(int size) {

	n = 1;

	while (n < size)
		n  *= 2;

	for (int i = 0; i < n * 2 - 1; ++i) {
		seg[i] = INF;
		lazy[i] = INF;
	}
}

void eval(int k, int l, int r) {

	if (flag[k]) {

		seg[k] = lazy[k];

		if (r - l > 1) {
			lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
			flag[k * 2 + 1] = flag[k * 2 + 2] = true;
		}
	}
	flag[k] = false;
}

void update(int a, int b, int v, int k, int l, int r) {

	eval(k, l, r);

	if (r <= a || b <= l)
		return;

	if (a <= l&&r <= b) {

		lazy[k] = v;

		flag[k] = true;

		eval(k, l, r);

		return;
	}

	update(a, b, v, k * 2 + 1, l, (l + r) / 2);

	update(a, b, v, k * 2 + 2, (l + r) / 2, r);

	seg[k] = std::min(seg[k * 2 + 1], seg[k * 2 + 2]);
}

int query(int a, int b, int k, int l, int r) {
	
	eval(k, l, r);

	if (r <= a || b <= l)
		return INF;

	if (a <= l&&r <= b)
		return seg[k];

	return std::min(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
}

int main() {

	std::cin >> n >> q;

	init(n);

	int com, s, t, x;

	for (int i = 0; i < q; ++i) {

		std::cin >> com >> s >> t;

		if (com == 0) {
			std::cin >> x;
			update(s, t + 1, x, 0, 0, n);
		}
		else
			std::cout << query(s, t + 1, 0, 0, n) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 5364
// Author - Sumit 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("avx")
 
#define ll long long 
#define int ll
#define ps push
#define pb emplace_back
#define INF 10000000000000LL
#define MOD 1000000007
#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 all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define lower(v,x) (lower_bound(all(v),x)-v.begin())
#define upper(v,x) (upper_bound(all(v),x)-v.begin())
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
 

void solve(){
	int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    debug3(a,b,c);
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

    clock_t clk=clock();
    
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    cerr<<((long double)(1.00*clock()-clk)/CLOCKS_PER_SEC)<<"\n";
}

Measured memory_bytes: 256
def power(x,y):
	res=1
	while y>0:
		if y&1:
			res=(res*x)
		y=y>>1
		x=x*x 
	return res
n,p=map(int,input().split())
fact=[]
xx=p
for i in range(2,int(p**(0.5))+1):
	if xx%i==0:
		c=0
		while xx%i==0: 
			xx=xx//i 
			c+=1
		fact.append([i,c])
if xx>1:
	fact.append([xx,1])
ans=1
for i in range(len(fact)):
	ans*=(power(fact[i][0],fact[i][1]//n))
print(ans)

Measured memory_bytes: 3064
n,x,y=map(int,input().split())
li=[0]*n
for i in range(1,n+1):
  for j in range(1,n+1):
    d=min(abs(i-j),abs(i-x)+abs(j-y)+1,1+abs(i-y)+abs(j-x))
    li[d]+=1
for k in range(1,n):
  print(li[k]//2)

Measured memory_bytes: 51932
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    ll x=(n-b+1)/b;
    ll y=n/b;

    ll answer=(n%b)*(a+y)/b;
    if(y>0) answer=max((b-1)*(a+x)/b,answer);

    cout<<answer;

    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        inp.close();
        if (a * b % 2 == 0) System.out.println("Even");
        else System.out.println("Odd");
    }
}


Measured memory_bytes: 23252
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var current []rune
	for _, r := range s {
		switch r {
		case '0', '1':
			current = append(current, r)
		case 'B':
			if len(current) > 0 {
				current = current[0 : len(current)-1]
			}
		}
	}
	for _, r := range current {
		fmt.Printf(string(r))
	}
	fmt.Printf("\n")
}


Measured memory_bytes: 512
import Data.Array
main=do
 [n,k]<-map read.words<$>getLine
 x<-map read.words<$>getLine
 print(f n k 1 (array (1,n) (zip [1..n] x)) 1000000000)
  where f n k i x a = if n<k+i-1 then a else (f n k (i+1) x (min a ((\s t->min ((abs (s-t))+(abs t)) ((abs (t-s))+(abs s))) (x!i) (x!(i+k-1)))))

Measured memory_bytes: 58748
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete

janken hs = case length us of
    2 -> map fs hs
    _ -> replicate 5 3
  where
    us = map head . group . sort $ hs
    fs
      | us == [1,2] = id
      | us == [2,3] = subtract 1
      | us == [1,3] = (`mod`3) . (+1)
    


main = splitRec 5 . takeWhile (/=0) . map readInt . lines <$> getContents >>= mapM_ (mapM_ print . janken)



Measured memory_bytes: 4072
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int x;
    cin >> x;
    int cur=1;
    for(int i=x;;i--){
        for(int b=1;b<32;b++){
            for(int p=2;p<10;p++){
                cur = 1;
                for(int j=0;j<p;j++) cur *= b;
                if(cur == i){
                    cout << i << endl;
                    return 0;
                }
            }
        }
    }
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X;
    cin >> X;
    if(X>=30) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 3636
object Main {
  def main(args : Array[String]) {
    val NK = readLine().split(' ').map(_.toLong)

    val ans1 = NK(0) % NK(1)
    val ans2 = (NK(1) - ans1) % NK(1)

    if(ans1 <= ans2) println(ans1)
    else println(ans2)
  }
}


Measured memory_bytes: 25556
// Karm Karta ja, Phal Ki Chinta na Kar:)
#include <bits/stdc++.h>
using namespace std;
#include<stdio.h>
typedef long long int ll;
#define INF 1e18+3
#define M 1000000007
#define PI 3.14159265358979323846
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
            return (((r%m)*(r%m))%m);
        else
            return (((((r%m)*a)%m)*r)%m);
    }
}
int main()
{
    int a,b;
    cin>>a>>b;
    int p=6;
    cout<<p-(a+b);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x,y;
  string a,b,c;
  cin >> a >> b >> c;
  x = a.length();
  y = b.length();
  if(a[x-1]==b[0] && b[y-1]==c[0]){
  	cout << "YES" << endl;
  }
  else{
  	cout << "NO" << endl;
  }
  return 0;
}
//int 整数
//char 文字
//string 文字列


Measured memory_bytes: 256
S = input()

S1 = S[0]
S2 = S[1]
S3 = S[2]
S4 = S[3]

flg = "Good"

if S1 == S2:
  flg = "Bad"
elif S2 == S3:
  flg = "Bad"
elif S3 == S4:
  flg = "Bad"

print(flg)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long L[1000],i;
    long n,l,S = 0,dem;
    cin >> n >> l;
    long minf = 99999999;
    for (i = 1; i <= n; i++)
    {
        L[i] = l + i - 1;
        S += L[i];
        minf = min(minf,abs(L[i]));
        if (minf == abs(L[i])) dem = i;
        
    }
    cout << S - L[dem];
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    --s[i];
  }

  int mn, mx;
  if (N == 1) {
    mn = 0;
    mx = 9;
  } else if (N == 2){
    mn = 10;
    mx = 99;
  } else {
    mn = 100;
    mx = 999;
  }
  
  for (int x = mn; x <= mx; ++x) {
    vector<int> digits;
    if (x == 0) {
      digits.push_back(0);
    } else {
      int tmp = x;
      while (tmp > 0) {
	digits.push_back(tmp % 10);
	tmp /= 10;
      }
      reverse(digits.begin(), digits.end());
    }
    bool happy = true;
    for (int i = 0; i < M; ++i) {
      if (s[i] >= digits.size() or digits[s[i]] != c[i]) {
	happy = false;
	break;
      }
    }
    if (happy) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
def nextX(x,a,b,c):
        return (a*x+b)%c
        
while 1:
    n,a,b,c,x=map(int,input().split())
    if n==0:
        break
    data=list(map(int,input().split()))
    for i in range(0,10001):
        if data[0]==x:
            del data[0]
        if(len(data)==0):
            print(i)
            break
        x=nextX(x,a,b,c)
    else:
        print(-1)


Measured memory_bytes: 5620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int cnt_num(int n, int k){
    int res = 0;
    while(n < k){
        res++;
        n *= 2;
    }
    return res;
}

int main() {
    int n, k; cin >> n >> k;
    double res = 0;
    for(int i=1; i<=n; i++){
        int cnt = cnt_num(i, k);
        double p = 1.0;
        rep(j, cnt){
            p /= 2;
        }
        res += p / n;
    }
    cout << fixed << setprecision(12);
    cout << res << ln;
}


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

int main(){
  int n,m,l;
  cin>>n>>m>>l;
  //vector<vector<int>> g(n,vector<int>(n));
  vector<vector<int>> dist(n,vector<int>(n,INF));
  vector<vector<int>> dist2(n,vector<int>(n,INF));
  rep(i,m){
    int a1,b1,c1;
    cin>>a1>>b1>>c1;
    a1--;b1--;
    dist[a1][b1]=c1;
    dist[b1][a1]=c1;
  }
  rep(i,n)dist[i][i]=0;
  rep(k,n)rep(i,n)rep(j,n){
    dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
  }
  rep(i,n)rep(j,n){
    if (dist[i][j]<=l)dist2[i][j]=1;
  }
  rep(k,n)rep(i,n)rep(j,n){
    dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }

//cout<<dist[0][2];
  int q;
  cin>>q;
  rep(i,q){
    int s,t;
    cin>>s>>t;
    s--;t--;
    if (dist2[s][t]==INF)cout<<-1<<endl;

    else{
      cout<<dist2[s][t]-1<<endl;
    }
  }



  }


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ll burger[51];

void set_burger(int n){
	burger[0]=1;
	for(int i=1; i<=n; i++){
		burger[i]=2*burger[i-1]+3;
	}
	return;
}

ll eat(ll n, ll k){
	if(n==0) return 1;
	if(k==1) return 0;
	else if(k<=1+burger[n-1]) return eat(n-1, k-1);
	else if(k==2+burger[n-1]) return eat(n-1, k-1)+1;
	else if(k<=2+2*burger[n-1]) return 1+eat(n-1, burger[n-1])+eat(n-1, k-burger[n-1]-2);
	else return 2*eat(n-1, burger[n-1])+1;
}

int main(){
	int n;
	ll x;
	cin >> n >> x;
	set_burger(n);
	cout << eat(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys
import math

N , M = map(int,input().split())
miti = [ [] for _ in range(N)]
for m in range(M):
    a , b = map(int , input().split())
    if b-1 != 0:
        miti[a-1].append(b-1)
    if a-1 != 0:
        miti[b-1].append(a-1)
visit = [0] * N
point = [ -1 for _ in range(N)]

def bfs():
    nextV = [0]
    visit[0] = 1
    total = 1
    while True:
        G = nextV
        # 次のloop用
        nextV = []
        for m in G:
            # m : 現在地
            # n : 目的地

            # mから到達可能な点nを調べる
            for n in miti[m]:
                if visit[n] == 0 :
                    # first visit
                    visit[n] = 1
                    point[n] = m
                    # 次の探索範囲を追加
                    nextV.append(n)
                    total += 1
                else:
                    continue
        if total == N :
            break

def solve():
    bfs()
    print("Yes")
    for a in point[1::]:
        print(a+1)

if __name__ == "__main__":
    solve()



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

int main(){
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  
  int min;
  min = (H2*60+M2) - (H1*60+M1);
  
  cout << min-K << endl;
}



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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }

lli d[9];

void func(long long N, std::vector<long long> a){

    lli dd[9]={400,800,1200,1600,2000,2400,2800,3200,INF};
    REP(i,0,N){
        for(lli j=0;j<=8;j++){
            if(a[i]<dd[j]){
                d[j]++;
                break;
            }
        }
    }
    lli sum=0;
    REP(i,0,8)if(d[i])sum++;
    cout<<max(sum,1LL)<<" "<<sum+d[8]<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    func(N, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

vector<ll>a;

int main() {

	int N;

	scanf("%d",&N);

	int i;

	for (i = 0; i < 3*N; i++) {
		ll b;
		scanf(" %lld",&b);
		a.push_back(b);
	}

	sort(a.begin(),a.end());

	int left = 0;
	int right = 3*N - 1;
	int cnt = 1;
	ll ans = a[right - 1];
	while (1) {
		if (cnt == N) { break; }
		left++;
		right -= 2;
		ans += a[right - 1];
		cnt++;
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
	
		
	string s[1000];
	int count = 0;
	int sum;
	for (int i = 0; i < 1000; i++) {
		cin >> s[i];
		count++;
		if (s[i] == "0")break;
	}

	for (int i = 0; i < count-1; i++) {
		sum = 0;
		for (int j = 0; j < s[i].size(); j++) {
			int num = atoi(s[i].substr(j, 1).c_str());
			sum += num;
		}
		cout << sum << endl;
	}

	return 0;

}



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

int n, a;
int main(){
    cin >> n >> a;
    if (n % 500 <= a){
        cout << "Yes" << endl;
} else {
        cout << "No" << endl;
}
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int cn[100005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		ll a[n],b=0;
		FOR(i,0,n)
		{
			cin>>a[i];
			b^=a[i];
		}
		FOR(i,0,n)
		{
			cout<<(b^a[i])<<' ';
		}
	}
	return 0;
}

Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	int N; cin >> N;

	if (N == 7 or N == 5 or N == 3) {
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const long double PI = 3.14159265358979323846;

// ****************************************CODE***************************************//







int main() {




    string s;
    cin >> s;

    int ans = 1;
    bool flag = false;

    for(int i = 1; i < s.size(); i++){
        if(flag == true){
            ans++;
            flag = false;
            continue;
        }
        if(s[i-1] == s[i] && i == s.size()-1) break;
        if(s[i-1] == s[i]){
            i++;
            ans++;
            flag = true;
            continue;
        }
        ans++;
    }


    cout << ans << endl;


    return 0;




}


































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

int main(){
  long long int n;
  int ans=10;
  cin>>n;
  for(long long int i=1;i<=sqrt(n);i++){
    if(n%i!=0) continue;
    string s=to_string(i);
    string t=to_string(n/i);
    int x=max(s.size(),t.size());
    ans=min(ans,x);
  }
  cout<<ans;

}


Measured memory_bytes: 3684
#include <stdio.h>

int main(void)
{
    int n, i, j;
    char buf[8];
    fgets(buf, 8, stdin);
    sscanf(buf, "%d", &n);

    for (i = 1; i <= n; ++i)
    {
        if (i % 3 == 0)
        {
            printf(" %d", i);
            continue;
        }
        j = i;
        while (j)
        {
            if (j % 10 == 3)
            {
                printf(" %d", i);
                break;
            }
            j /= 10;
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2048
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
EPS = 10 ** -10

class ModTools:
    """ 階乗・逆元用のテーブルを構築する """

    def __init__(self, MAX, MOD):
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        inverse = [1] * MAX
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, -1, -1):
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせ """

        if n < r: return 0
        r = min(r, n-r)
        numerator = self.fact[n]
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def nHr(self, n, r):
        """ 重複組み合わせ """

        return self.nCr(r+n-1, r)

    def nPr(self, n, r):
        """ 順列 """

        if n < r: return 0
        return self.fact[n] * self.inv[n-r] % self.MOD

    def div(self, x, y):
        """ MOD除算 """

        return x * pow(y, self.MOD-2, self.MOD) % self.MOD

N, K = MAP()

mt = ModTools(max(N, K)+1, MOD)
ans = mt.nPr(K, N) % MOD
print(ans)



Measured memory_bytes: 5744
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
        list.add(scanner.nextInt());
        list.add(scanner.nextInt());
        list.add(scanner.nextInt());
        List<Integer> newList = list.stream().distinct().collect(Collectors.toList());
        if (newList.size() == 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 28364
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  A.sort(reverse=True)
  ans = A[0]
  cnt = 1
  for i in range(1,N-1):
    ans += A[i]
    cnt += 1
    if cnt==N-1:
      break
    ans += A[i]
    cnt += 1
    if cnt==N-1:
      break
  return ans
print(solve())

Measured memory_bytes: 31576
<?php

$num = trim(fgets(STDIN));

list($days, $amari) = explode(' ', trim(fgets(STDIN)));

$choko = 0;
for ($i = 0; $i < $num; $i++) {
    $member = trim(fgets(STDIN));
    if (1 == $member) $choko += $days;
    else $choko += 0 == (int)($days%$member)? (int)($days/$member) : (int)($days/$member) + 1;
}

echo $choko + $amari . PHP_EOL;

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

int main() {
  vector<vector<int>> card(3, vector<int>(3));
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      cin >> card.at(i).at(j);
    }
  }
  
  int N;
  cin >> N;
  vector<int> num(N);
  for (int i=0; i<N; i++)
    cin >> num.at(i);
  
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      for (int k=0; k<N; k++){
        if (card.at(i).at(j)==num.at(k))
          card.at(i).at(j)=101;
      }
    }
  }
  if (card.at(0).at(0)==101 && card.at(0).at(1)==101 && card.at(0).at(2)==101)
    cout << "Yes" << endl;
  else if (card.at(1).at(0)==101 && card.at(1).at(1)==101 && card.at(1).at(2)==101)
    cout << "Yes" << endl;    
  else if (card.at(2).at(0)==101 && card.at(2).at(1)==101 && card.at(2).at(2)==101)
    cout << "Yes" << endl;
  else if (card.at(0).at(0)==101 && card.at(1).at(0)==101 && card.at(2).at(0)==101)
    cout << "Yes" << endl;  
  else if (card.at(0).at(1)==101 && card.at(1).at(1)==101 && card.at(2).at(1)==101)
    cout << "Yes" << endl;    
  else if (card.at(0).at(2)==101 && card.at(1).at(2)==101 && card.at(2).at(2)==101)
    cout << "Yes" << endl;    
  else if (card.at(0).at(0)==101 && card.at(1).at(1)==101 && card.at(2).at(2)==101)
    cout << "Yes" << endl;    
  else if (card.at(0).at(2)==101 && card.at(1).at(1)==101 && card.at(2).at(0)==101)
    cout << "Yes" << endl;    
  else
    cout << "No" << endl;
  
  
  
  
  

}

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

int main() {
  int n, a = 0, b = 0;
  long long h1, h2;
  cin >> n >> h1;
  for(int i = 0; i < n - 1; i++){
    cin >> h2;
    if(h1 >= h2) a++;
    else {
      if(b < a) b = a;
      a = 0;
    }
    h1 = h2;
  }
  if(b < a) b = a;
  cout << b << endl;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;

ll MOD = 1e9+7;


template <typename T>
class Rerooting{
public:
	vector<vector<int>> edge;
	vector<map<int,T>> memo;
	vector<map<int,T>> sumL;
	vector<map<int,T>> sumR;

	struct Solver {
		virtual T init() const = 0;
		virtual T merge(T, T) const = 0;
		virtual T add_me(T) const = 0;
	};
	const Solver *solver;

	const T init_value;

	Rerooting(
			int N,
			const Solver *solver
	) :
		edge(N),
		memo(N),
		sumL(N),
		sumR(N),
		solver(solver),
		init_value(solver->init())
	{ }

	void add_edge(int u, int v){
		edge[u].push_back(v);
		edge[v].push_back(u);
	}

	T solve(int n, int b = -1){
		if(memo[n].count(b)) return memo[n][b];

		if(b >= 0 && memo[b].count(n)){
			// b -> n が存在するとき、nが根のときの結果を使って高速化する
			solve(n, -1);  // sumL, sumR の計算がまだな場合は計算する
			auto ret = solver->merge(sumL[n][b], sumR[n][b]);
			return memo[n][b] = solver->add_me(ret);
		}

		T ret = init_value;
		for(auto t: edge[n]) if(t != b){
			ret = solver->merge(ret, solve(t, n));
		}

		if(b < 0){
			// nが根のときは、累積を計算しておく
			T sum = init_value;
			rep(i, edge[n].size()){
				int t = edge[n][i];
				sumL[n][t] = sum;
				sum = solver->merge(sum, solve(t,n));
			}
			sum = init_value;
			rrep(i, edge[n].size()){
				int t = edge[n][i];
				sumR[n][t] = sum;
				sum = solver->merge(sum, solve(t,n));
			}
		}

		return memo[n][b] = solver->add_me(ret);
	}
};

struct Solver: Rerooting<ll>::Solver {
	ll init() const override {
		return 1;
	}

	ll merge(ll a, ll b) const override {
		return a * b % MOD;
	}

	ll add_me(ll a) const override {
		return a + 1;
	}
};

int main(){
	ios_base::sync_with_stdio(false);

	int N;
	cin >> N >> MOD;
	Rerooting<ll> rr(N, new Solver());
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		rr.add_edge(a, b);
	}

	rep(i,N) cout << rr.solve(i) - 1 << "\n";

	return 0;
}

Measured memory_bytes: 75776
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) {return i / 2;}
int left(int i)   {return 2 * i;}
int right(int i)  {return 2 * i + 1;}

int main() {
    int H, i, A[MAX + 1];
    
    cin >> H;
    for(i = 1; i <= H; i++) cin >> A[i];
    
    for(i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088