akhauriyash/Code-Regression huggingface dataset:
// O(N^2 M)
#include <bits/stdc++.h>
using namespace std;

int n, m;
int a[100000];
int b[100000];
bool used[400];
bool sub(int s, int t) {
  for (int i = 0; i < n; ++i) used[i] = false;
  used[s] = true;
  used[t] = true;
  for (int j = m - 1; j >= 0; --j) {
    int x = a[j];
    int y = b[j];
    if (used[x] && used[y]) {
      return false;
    } else if (used[x]) {
      used[y] = true;
    } else if (used[y]) {
      used[x] = true;
    }
  }
  return true;
}

int main() {
  cin >> n >> m;
  for (int j = 0; j < m; ++j) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    a[j] = x;
    b[j] = y;
  }
  
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (sub(i, j)) ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut done: bool = false;

    while !done {
        let h = read();
        let w = read();
        if h == 0 && w == 0 {
            done = true;
        } else {
            for index_h in 0..h {
                for index_w in 0..w {
                    if index_h % 2 == 0 {
                        if index_w % 2 == 0 {
                            print!("#");
                        } else {
                            print!(".");
                        }
                    } else {
                        if index_w % 2 == 0 {
                            print!(".");
                        } else {
                            print!("#");
                        }
                    }
                }
                println!();
            }
            println!();
        }
    }
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
#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++)
using namespace std;
int main() {
  int n,a,b,c;
  cin>>n>>a>>b>>c;
  bool ex=true;
  vector<char>d;
  vector<string>s(n);
  rep(i,n){
    cin>>s.at(i);
  }
  rep(i,n-1){
    
    if(s.at(i)=="AB"){
      if(a>b){
        a--;
        b++;
        d.push_back('B');
      }
      else if(a<b){
        a++;
        b--;
        d.push_back('A');
      }
      else{
        if(s.at(i+1)=="BC"){
          a--;
          b++;
          d.push_back('B');
        }
        else if(s.at(i+1)=="AC"){
          a++;
          b--;
          d.push_back('A');
        }
        else{
          a++;
          b--;
          d.push_back('A');
        }
      }
    }
    else if(s.at(i)=="AC"){
      if(a>c){
        a--;
        c++;
        d.push_back('C');
      }
      else if(a<c){
        a++;
        c--;
        d.push_back('A');
      }
      else{
        if(s.at(i+1)=="BC"){
          a--;
          c++;
          d.push_back('C');
        }
        else if(s.at(i+1)=="AB"){
          a++;
          c--;
          d.push_back('A');
        }
        else{
          a++;
          c--;
          d.push_back('A');
        }
      }
    }
    else if(s.at(i)=="BC"){
      if(b>c){
        b--;
        c++;
        d.push_back('C');
      }
      else if(b<c){
        b++;
        c--;
        d.push_back('B');
      }
      else{
        if(s.at(i+1)=="AB"){
          c--;
          b++;
          d.push_back('B');
        }
        else if(s.at(i+1)=="AC"){
          c++;
          b--;
          d.push_back('C');
        }
        else{
          c++;
          b--;
          d.push_back('C');
        }
      }
    }
    if(a<0||b<0||c<0){
      ex=false;
      break;
    }
  }
  if(ex){
  if(s.at(n-1)=="AB"){
    if(a+b>0){
      if(a>b){
        a--;
        b++;
        d.push_back('B');
      }
      else{
        a++;
        b--;
        d.push_back('A');
      }
    }
    else{
      ex=false;
    }
  }
  else if(s.at(n-1)=="AC"){
    if(a+c>0){
      if(a>c){
        d.push_back('C');
        c++;
        a--;
      }
      else{
        d.push_back('A');
        a++;
        c--;
      }
    }
    else{
      ex=false;
    }
  }
  else if(s.at(n-1)=="BC"){
    if(b+c>0){
      if(b>c){
        d.push_back('C');
        b--;
        c++;
      }
      else{
        d.push_back('B');
        b++;
        c--;
      }
    }
    else{
      ex=false;
    }
  }
  }
  if(ex){
    cout<<"Yes"<<endl;
    rep(i,n){
      cout<<d.at(i)<<endl;
    }
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 6696
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M; cin >> N >> M;
	vector<ll> s(N+1), t(M+1);
	for (int i = 1; i <= N; i++) {
		cin >> s[i];
	}

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

	ll dp[2005][2005]={0};
	ll sum[2005][2005]={0};
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (s[i] == t[j])
				dp[i][j] = (sum[i - 1][j - 1] + 1) % DIV;
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
			sum[i][j] = (sum[i][j] + DIV) % DIV;
		}
	}

	cout << (sum[N][M] + 1 + DIV) % DIV << endl;
}


Measured memory_bytes: 66412
while True:
    N = int(input())
    if not N:
        break
    e = []
    for i in range(N):
        m, a, b = map(int, input().split())
        e.append((a, m))
        e.append((b, -m))

    M = 0
    ot = 0
    for t, m in sorted(e):
        if M > 150 and ot != t:
            print('NG')
            break
        M += m
        ot = t
    else:
        print('OK')

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

int sign(ll x){
    return (x > 0 ? 1 : (x < 0 ? -1 : 0));
}

signed main(){
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll x = t1 * (a1 - b1);
    ll y = t2 * (a2 - b2);

    ll z = x + y;
    if(z == 0){
        cout << "infinity" << endl;
        return 0;
    }

    y += x;
    //debug(x);debug(y);debug(z);

    ll ans = 0;
    if(sign(x) != sign(z)){
        ans += 2 * Div(llabs(x), llabs(z));
        ans -= (llabs(x) % z == 0 ? 0 : 1);
    }
    if(sign(y) != sign(z)){
        ans += 2 * Div(llabs(y), llabs(z));
        ans -= (llabs(y) % z == 0 ? 0 : 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    string s; cin >> s;
    ll n = s.size();
    if(n&1) {
        char c = s[n/2];
        ll i = 1;
        while(s[n/2 - i] == c && s[n/2 + i] == c) i++;
        cout << n - n/2 + i - 1<< endl;
    } else {
        char c = s[n/2];
        if(c != s[n/2-1]) {
            cout << n/2 << endl;
            return 0;
        }
        ll i = 1;
        while(s[n/2-1 - i] == c && s[n/2 + i] == c) i++;
        cout << n - n/2 + i << endl;
    }
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;
    vector<ll> A(n);
    REP(i, n)
    cin >> A[i];

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

    REP(i, n - 1)
    {
        if (A[i] == A[i + 1])
        {
            Cout("NO");
            return 0;
        }
    }
    Cout("YES");

    return 0;
}

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

#[fastout]
fn main() {
    input! {
        n: usize,
    }
    let ans = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => "erro",
    };

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


Measured memory_bytes: 2164
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	S, T := sc.Next(), sc.Next()

	for i := len(S) - len(T); i >= 0; i-- {
		count := 0
		for j := 0; j < len(T); j++ {
			if S[i+j] == T[j] || S[i+j] == '?' {
				count++
			}
		}
		if count == len(T) {
			ans := make([]byte, len(S))
			for p := 0; p < len(S); p++ {
				if i <= p && p < i+len(T) {
					ans[p] = T[p-i]
				} else {
					if S[p] == '?' {
						ans[p] = 'a'
					} else {
						ans[p] = S[p]
					}
				}
			}
			fmt.Println(string(ans))
			return
		}
	}

	fmt.Println("UNRESTORABLE")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
/* #define int long long */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



signed main(){
    int N, M;
    cin >> N >> M;
    set<int> a;
    rep(i, M){
        int tmp;
        cin >> tmp;
        a.insert(tmp);
    }

    vi dp(N+10);
    dp[0] = 1;
    if(!a.count(1)) dp[1] = 1;

    for(int i = 2; i <= N; i++){
        if(!a.count(i-1)) dp[i] += dp[i-1];
        if(!a.count(i-2)) dp[i] += dp[i-2];
        dp[i] %= MOD;
    }

    cout << dp[N] << endl;

}

Measured memory_bytes: 8304
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] arrN = new String[n];
		String[] arrM = new String[m];
		for (int i = 0; i < n; i++) {
			arrN[i] = sc.next();
		}
		for (int i = 0; i < m; i++) {
			arrM[i] = sc.next();
		}
		
		for (int i = 0; i + m <= n; i++) {
			for (int j = 0; j + m <= n; j++) {
				boolean flag = true;
				for (int k = 0; k < m; k++) {
					for (int l = 0; l < m; l++) {
						if (arrM[k].charAt(l) != arrN[i + k].charAt(j + l)) {
							flag = false;
							break;
						}
					}
					if (!flag) {
						break;
					}
				}
				if (flag) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 21332
n,m = (int(i) for i in input().split())
s = []
c = []
for i in range(m):
  a,b = (int(i) for i in input().split())
  s.append(a)
  c.append(b)
if n == 1:
  if m == 0:
    print(0)
    exit()
  else:
    ans = c[0]
    for i in range(1,m):
      if c[i] != ans:
        print(-1)
        exit()
    print(ans)
elif n == 2:
  if m == 0:
    print(10)
    exit()
  else:
    a = 1
    b = 0
    a1 = True
    b1 = True
    for i in range(m):
      if s[i] == 1 and c[i] == 0:
        print(-1)
        exit()
      if s[i] == 1:
        if a1 == True:
          a = c[i]
          a1 = False
        elif c[i] != a:
          print(-1)
          exit()
      else:
        if b1 == True:
          b = c[i]
          b1 = False
        elif c[i] != b:
          print(-1)
          exit()
    print(10*a+b)
else:
  if m == 0:
    print(100)
    exit()
  else:
    a = 1
    b = 0
    d = 0
    a1 = True
    b1 = True
    d1 = True
    for i in range(m):
      if s[i] == 1 and c[i] == 0:
        print(-1)
        exit()
      if s[i] == 1:
        if a1 == True:
          a = c[i]
          a1 = False
        elif c[i] != a:
          print(-1)
          exit()
      elif s[i] == 2:
        if b1 == True:
          b = c[i]
          b1 = False
        elif c[i] != b:
          print(-1)
          exit()
      else:
        if d1 == True:
          d = c[i]
          d1 = False
        elif c[i] != d:
          print(-1)
          exit()
    print(100*a+10*b+d)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

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

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<ll> A, B, C;
    REP(i, X) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    REP(i, Y) {
        ll a;
        cin >> a;
        B.push_back(a);
    }
    REP(i, Z) {
        ll a;
        cin >> a;
        C.push_back(a);
    }

    sort(ALL(A), greater<ll>());
    sort(ALL(B), greater<ll>());
    sort(ALL(C), greater<ll>());

    vector<ll> abc;
    REP(i, X) {
        REP(j, Y) {
            REP(k, Z) {
                if (i * j * k <= K) {
                    abc.push_back(A[i] + B[j] + C[k]);
                } else {
                    break;
                }
            }
        }
    }
    sort(ALL(abc), greater<ll>());
    REP(i, K) { cout << abc[i] << endl; }
    return 0;
}


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

int merge_sort(int S[], int left, int right) {
    int cnt = 0;
    if (left == right) return cnt;
    int mid = (left + right) / 2;
    cnt += merge_sort(S, left   , mid  );
    cnt += merge_sort(S, mid + 1, right);
    queue<int> A;
    queue<int> B;
    for (int i = left; i <= mid; i++) {
        A.push(S[i]);
    }
    A.push(1e9 + 1);
    for (int i = mid + 1; i <= right; i++) {
        B.push(S[i]);
    }
    B.push(1e9 + 1);

    for (int i = left; i <= right; i++) {
        cnt++;
        if (A.front() <= B.front()) {
            S[i] = A.front();
            A.pop();
        } else {
            S[i] = B.front();
            B.pop();
        }
    }
    return cnt;
}

int main(){
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int cnt = merge_sort(S, 0, n - 1);
    cout << S[0];
    for (int i = 1; i < n; i++) {
        cout << " " << S[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 7004
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;


void solve()
{
    int n,x; cin>>n>>x;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    sort(all(a));
    int ans = 0;
    rep(i,0,n)
    {
        x-=a[i];
        if(x<0) break;
        ans++;
    }
    if(x>0) ans--;
    cout<<max(ans,0);
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static long mod = 998244353;
	static int[] ans;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res="";
		int res = 0;


		int[] vals = parseAry(Console.ReadLine().Split(cs));

		res = vals[0] - vals[1];
		if ( vals[1] == 1 ) { res = 0; }

		Console.WriteLine(res);

		return;

	}




	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    ll ans = 0;
    for(auto it1 = l.begin(); it1 != l.end(); it1++) {
        for(auto it2 = it1; it2 != l.end(); it2++) {
            if (it1 == it2) continue;
            auto it3 = it2; it3++;
            auto it4 = upper_bound(it3, l.end(), *it2 - *it1);
            auto it5 = lower_bound(it4, l.end(), *it1 + *it2);
            ans += it5 - it4;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
v = LIST()
v.sort()
v = deque(v)
for i in range(n - 1):
    v1 = v.popleft()
    v2 = v.popleft()
    v.appendleft((v1 + v2) / 2)
print(v[0])

Measured memory_bytes: 59756
using System;
using System.Collections.Generic;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int max = int.MinValue;
			int sum = 0;
			string[] s = Console.ReadLine().Split(' ');
			int n = int.Parse(s[0]);
			int k = int.Parse(s[1]);
			int[] w = new int[n];
			for (int i = 0; i < n; i++)
			{
				w[i] = int.Parse(Console.ReadLine());
				sum += w[i];
				if (max < w[i])
					max = w[i];
			}
			int P = Math.Max(sum / k, max);
			int now;
			int remain;
			bool b = false;
			while (true)
			{
				now = 0;
				for (int i = 0; i < k; i++)
				{
					remain = P;
					for (int j = now; j < n; j++)
					{
						if (j == n - 1 && remain >= w[j])
						{
							b = true;
							break;
						}
						else if (remain >= w[j])
						{
							remain -= w[j];
						}
						else
						{
							now = j;
							break;
						}
					}
				}
				if (b)
				{
					Console.WriteLine(P);
					break;
				}
				else
					P++;
			}
		}
	}
}

Measured memory_bytes: 9980
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BC.readInteger) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

m = 1000000000000000000

main :: IO ()
main = do
  getLine
  as <- readIntegers
  if elem 0 as then
    putStrLn "0"
  else do
    let pd = foldl' (\b a -> do
                              a <- fmap (*a) b
                              guard $ a <= m
                              pure a
                    ) (Just 1) as
    print $ fromMaybe (negate 1) pd



Measured memory_bytes: 13500
#include<iostream>
using namespace std;
int main(void)
{
    int t,n,s,f,A;
    while(1){
        cin>>t;
        if(t==0)break;
        A=0;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>s>>f;
            A+=f-s;
        }
        if(t<=A)cout<<"OK\n";
        else cout<<t-A<<"\n";
    }
}

Measured memory_bytes: 1160
import sys
import numpy as np
# from numba import njit

# @njit(cache=True)
def calcCycle(N,K,P,C,cycleIDs,cycleItemCnts,cycleTotalScores):
	cycleID = 0

	for n in range(N):

		v = n
		currentCycleItemCnt = 0
		currentCycleTotal = 0

		if cycleIDs[v] != -1:
			continue
			# print(currentCycleItemCnt, currentCycleTotal)
		else:
			while True:
				# 全頂点について、属するサイクルを計算する
				currentCycleItemCnt += 1
				currentCycleTotal += C[v]

				v = P[v]
				if v == n:
					# サイクル発見
					cycleIDs[v] = cycleID
					cycleItemCnts[cycleID] = currentCycleItemCnt
					cycleTotalScores[cycleID] = currentCycleTotal
					cycleID += 1
					break

				# 一応、一度サイクルを計算した頂点については、
				# その頂点の属するサイクルの情報をメモっておく。。。
				cycleIDs[v] = cycleID

def upd(P,C,K,v,ans,currentCycleItemCnt,currentCycleTotal):

	# procCnt = 0
	currentCycleSumTmp = 0

	for k in range(min(K,currentCycleItemCnt)):

		# 頂点vにコマが置かれた時の最高スコアを計算し、
		# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する

		procCnt = k+1
		currentCycleSumTmp += C[v]

		cycleLoopCnt = 0
		if 0 < currentCycleTotal:
			cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt

		# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, "procCnt, cycleLoopCnt, currentCycleTotal=", procCnt, cycleLoopCnt, currentCycleTotal)
		ans = max( ans, currentCycleSumTmp + cycleLoopCnt * currentCycleTotal )
		v = P[v]

	return ans





def main(ans,N,K,P,C,cycleIDs,cycleItemCnts,cycleTotalScores):

	for n in range(N):

		v = n
		currentCycleItemCnt, currentCycleTotal = cycleItemCnts[ cycleIDs[v] ], cycleTotalScores[ cycleIDs[v] ]

		# ans=upd(P,C,K,v,ans,currentCycleItemCnt,currentCycleTotal)
		currentCycleSumTmp = 0
		for k in range(min(K,currentCycleItemCnt)):

			procCnt = k+1
			currentCycleSumTmp += C[v]

			cycleLoopCnt = 0
			if 0 < currentCycleTotal:
				cycleLoopCnt = ( K - procCnt ) // currentCycleItemCnt

			# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, "procCnt, cycleLoopCnt, currentCycleTotal=", procCnt, cycleLoopCnt, currentCycleTotal)
			ans = max( ans, currentCycleSumTmp + cycleLoopCnt * currentCycleTotal )
			v = P[v]


	print(int(ans))

if sys.argv[-1]=='ONLINE_JUDGE':
	# from numba import njit
	from numba.pycc import CC
	cc=CC('my_module')
	cc.export('calcCycle','void(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:])')(calcCycle)
	cc.export('main','void(i8,i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:])')(main)
	# cc.export('upd','i8(i8[:],i8[:],i8,i8,i8,i8,i8)')(upd)
	# cc.export('upd','UniTuple(i8,3)(i8[:],i8[:],i8,i8,i8,i8,i8)')(upd)
	# main=njit(main, cache=True)
	cc.compile()
	exit(0)
# from my_module import upd,calcCycle
from my_module import main,calcCycle
# from my_module import calcCycle



if __name__ == "__main__":
	N,K = map(int,input().split())
	P = np.array( input().split(), np.int64 )
	P -= 1
	C = np.array( input().split(), np.int64 )

	# 一度計算したサイクル情報を一応キャッシュしておく。。。
	# あんまり意味なさそう
	cycleIDs = np.full( N, -1, dtype=np.int64 )
	cycleItemCnts = np.full( N, -1, dtype=np.int64 )
	cycleTotalScores = np.full( N, -1, dtype=np.int64 )

	calcCycle(N,K,P,C,cycleIDs,cycleItemCnts,cycleTotalScores)

	# print(cycleItemCnts)

	ans = -1e18
	main(ans,N,K,P,C,cycleIDs,cycleItemCnts,cycleTotalScores)
	#print(ans)




Measured memory_bytes: 27928
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ld long double
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define INFINITE 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	#define precision(a) cout<<fixed<<setprecision(a);
	#define INF (1e18+5)
	#define inf (1e9+5)
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	// 8-directions
	//int dx[]={1,1,1,0,0,-1,-1,-1};
	//int dy[]={-1,0,1,-1,1,-1,0,1};
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	int begtime = clock();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	ll fpow(ll base, ll power, ll MOD) {
    ll result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	ll modinv(ll x,ll MOD) {return fpow(x, MOD - 2, MOD);}
	void solve()
	{
		ll k;
		cin>>k;
		string A="ACL";
		forn(i,k)
		cout<<A;
		cout<<endl;		
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		#ifndef ONLINE_JUDGE
    		cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    		#endif
		return 0;
	}

	
	
	
	

Measured memory_bytes: 3680
package main

import (
  "fmt"
)

func main() {
  var n int
  var sum float64

  fmt.Scan(&n)
  x := make([]float64 ,n)
  u := make([]string ,n)
  for i := 0; i < n; i++ {
    fmt.Scan(&x[i])
    fmt.Scan(&u[i])
  }

  for i := 0; i < n; i++ {
    if u[i] == "BTC" {
      sum += x[i] * 380000
    } else {
      sum += x[i]
    }
  }
  fmt.Println(sum)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int n; cin >> n;
  int p[n],q[n];
  FOR(i,0,n-1) cin >> p[i];
  FOR(i,0,n-1) cin >> q[i];

  int snuke[n];
  FOR(i,0,n-1) snuke[i] = i+1;

  int ansa,ansb;
  int ref = 0;

  do{
    ++ref;
    bool allp,allq;
    allp = allq = true;

    if(equal(p, p + n, snuke)) ansa = ref;
    if(equal(q, q + n, snuke)) ansb = ref;
  } while (next_permutation(snuke,snuke+n));

  cout << abs(ansa-ansb) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n;
Pll p[200];
int c(ll x,ll y)
{
	if(x>=0 && y>=0)return 1;
	if(x<=0 && y>=0)return 2;
	if(x<=0 && y<=0)return 3;
	return 4;
}
int main(){
	scanf("%d",&n);
	fup(i,0,n-1,1)
		scanf("%lld%lld",&p[i].X,&p[i].Y);
	sort(p,p+n,[&](Pll p1,Pll p2){
		int c1=c(p1.X,p1.Y),c2=c(p2.X,p2.Y);
		if(c1!=c2)return c1<c2;
		ll x1=(ll)abs(p1.X),y1=(ll)abs(p1.Y),x2=(ll)abs(p2.X),y2=(ll)abs(p2.Y);
		if(c1==1 || c1==3) return x2*y1<x1*y2;
		else return x2*y1>x1*y2;
	});
	fup(i,n,n+n-1,1)p[i]=p[i-n];
	ll ans=0;
	fup(i,0,n-1,1)
	{
		ll x=0,y=0;
		fup(j,i,i+n-1,1)
		{
			x+=p[j].X,y+=p[j].Y;
			ans=max(ans,x*x+y*y);
		}
	}
	printf("%.15f",sqrt(ans));
}

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

double to_deg(double r) {
    return r * 180.0 / (atan(1.0) * 4.0);
}

int main() {
    int a, b, x;
    std::cin >> a >> b >> x;

    double th = 0.5 * a * b * a;
    
    if (th <= x) {
        double r = (2 * a * a * b - 2.0 * x) / (a * a * a);
        std::printf("%lf\n", to_deg(atan(r)));
    } else {
        double r = (a * b * b) / (2.0 * x);
        std::printf("%.10lf\n", to_deg(atan(r)));
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
カロリーの累積和？
向きを変えるのか

x*2とC-xが移動距離
全部のパターンで調べるとか
時計、班時計、方向転換
N^2になっちゃうな
時計と班時計の累積和だけで組み合わせとか
N^2

往復した場合の累積和
普通の累積和
最大和だけ用意しとくとか、DP
*/
int main(){
  ll N,C,ans=0,cal=0; cin>>N>>C;
  vector<ll> X(N+1,0), V(N+1,0),DPR(N+1,0),DPL(N+1,0),DPRR(N+1,0),DPLL(N+1,0);
  for(ll i=1; i<=N; i++) cin>>X[i]>>V[i];
  //DPR
  for(ll i=1; i<=N; i++){
    cal+=V[i];
    DPR[i]=max(DPR[i-1],cal-X[i]);
  }
  //DPL
  cal=0;
  for(ll j=N; j>0; j--){
    cal+=V[j];
    DPL[N-j+1]=max(DPL[N-j],cal-(C-X[j]));
  }  
  //DPRR
  cal=0;
  for(ll i=1; i<=N; i++){
    cal+=V[i];
    DPRR[i]=max(DPRR[i-1],cal-X[i]*2);
  }
  //DPLL
  cal=0;
  for(ll j=N; j>0; j--){
    cal+=V[j];
    DPLL[N-j+1]=max(DPLL[N-j],cal-(C-X[j])*2);
  }
  //時計反時計
  ans=max(DPR[N],DPL[N]);
  //ひきかえし
  for(ll i=1; i<=N; i++) ans=max(ans,DPRR[i]+DPL[N-i]);
  for(ll i=1; i<=N; i++) ans=max(ans,DPLL[i]+DPR[N-i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 4992
n, k = map(int,input().split())
dic = [0 for i in range(n + 1)]
for i in range(k):
  a, b = map(int,input().split())
  dic[a] = b

dp = [[0] * 3 for i in range(3)]
temp = [[0] * 3 for i in range(3)]
first = dic[1]
second = dic[2]

if not first and not second:
  for i in range(3):
    for j in range(3):
      dp[i][j] = 1

elif not first:
  for i in range(3):
    dp[i][second - 1] = 1

elif not second:
  for i in range(3):
    dp[first - 1][i] = 1

else:
  dp[first - 1][second - 1] = 1

for i in range(3, n + 1):
  past = dic[i]
  if not past:
    for y in range(3):
      for x in range(3):
        temp[x][y] = sum(dp[j][x] for j in range(3) if not (x == y and x == j))
  else:
    for y in range(3):
      for x in range(3):
        if y == past - 1:
          temp[x][y] = sum(dp[j][x] for j in range(3) if not (x == y and x == j))
        else:
          temp[x][y] = 0
  
  for x in range(3):
    for y in range(3):
      dp[x][y] = temp[x][y]
print(sum([dp[i][j] for i in range(3) for j in range(3)]) % 10000)


Measured memory_bytes: 5616
MOD = 1_000_000_007

FACT = [1]
(1..1000).each do |k|
  FACT << FACT[-1] * k % MOD
end

def exp(n, k)
  x = 1
  r = n
  while k > 0
    x *= r if k & 1 == 1
    r *= r
    x %= MOD
    r %= MOD
    k >>= 1
  end
  x
end

def inv(n)
  exp(n, MOD - 2)
end

def perm(n, k)
  n >= k ? FACT[n] * inv(FACT[n - k]) % MOD : 0
end

n, k = gets.split.map(&:to_i)
p perm(k, n)



Measured memory_bytes: 6880
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
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)*}
    };
}
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)*}
    };
}
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        N: usize,
        S: chars,
    }
    let mut ans = true;

    if N % 2 == 0 {
        for i in 0..S.len()/2 {
            if S[i] != S[i+N/2] {
                ans = false;
            }
        }
    } else {
        ans = false;
    }

    println!("{}", if ans {"Yes"} else {"No"});
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int res = 0;
  for (int i = A; i <= B; i++) {
    if (i/10000 == i%10  && i/1000%10 == i%100/10) {
      res += 1;
      i += 9;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3608
// C - Candies
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int A[N+1],B[N+1],ans=0; A[0]=0, B[0]=0;
	rp(i, 1, N+1){ scanf("%d",A+i); A[i] += A[i-1]; }
	rp(i, 1, N+1){ scanf("%d",B+i); B[i] += B[i-1]; }
	rp(i, 1, N+1) ans = max(ans, A[i]+B[N]-B[i-1]);
	cout<< ans <<endl;
}

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

int main(){
  ll n,x,res=0;
  cin>>n>>x;
  vector<ll> a(n);
  for(int i=0; i<n; i++) cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=0; i<n; i++) {
    if(x>=a[i]) {
      if(i==n-1 && x>a[i]) break;
      else {
        x -= a[i];
      	res++;
           }
    }
    else break;
  }
  cout<<res;
}

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

using ll = long long;

int main() {
	int h, w;
	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			string s;
			cin >> s;
			if (s == "snuke") {
				cout << (char)('A' + j);
				cout << i + 1 << endl;	
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int n;
long long x, px, s, f, z;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &x, &s);
		f = max(f + px - x + s, s);
		z = max(z, f);
		px = x;
	}
	printf("%lld\n", z);
	return 0;
}

Measured memory_bytes: 256
def is_count_k(count,n):
    count +=1
    if count == k :
        print(n)
        exit()
    
    return count
def make_tree(G,keta,count):
    num_list = G[keta-2]
    new_list =[]
    for num in num_list:
        r = num%10
        if r != 0 :
            count = is_count_k(count,num*10 + (r-1))
            new_list.append(num*10 + r-1)
        count = is_count_k(count,num*10+r)
        new_list.append(num*10 + r)
        if r != 9:
            count = is_count_k(count,num*10+(r +1))
            new_list.append(num*10+(r +1))
    G.append(new_list)
    make_tree(G,keta+1,count)
k = int(input())
G=[]
if k < 10:
    print(k)
    exit()
G.append([1,2,3,4,5,6,7,8,9])
make_tree(G,2,9)


Measured memory_bytes: 7172
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const firstLine = input[0].split(" ").map((v) => parseInt(v));

const N = firstLine[0];
const K = firstLine[1];
const S = input[1];

let ans = "";
for (let i = 0; i < N; i++) {
  ans += (K === i + 1) ? S.charAt(i).toLowerCase() : S.charAt(i);
}

console.log(ans);


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define pb push_back
#define ff first;
#define ss second;
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define endl '\n'
const double pi = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
	
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string a,b;
	cin >> a >> b;
	int c = 0;
	int p = a.size();
	for(int i=0;i<p;i++){
		if(a[i]!=b[i]){
			c++;
		}
	}
	cout << c << endl;
	return 0;
}



Measured memory_bytes: 3792