akhauriyash/Code-Regression huggingface dataset:
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	const MOD: i64 = 1000000007;
	let n: usize = s.next().unwrap().parse().unwrap();
	let a = pow_mod(9, n, MOD);
	let b = pow_mod(8, n, MOD);
	let all = pow_mod(10, n, MOD);
	let c = (2 * a + MOD - b) % MOD;
	println!("{}", (all + MOD - c) % MOD);
}

pub fn pow_mod<T, U>(a: T, mut b: U, modulus: T) -> T
where
	T: num::PrimInt,
	U: num::PrimInt + num::Integer + num::Unsigned,
{
	let mut r = T::one();
	let mut a = a % modulus;
	while b > U::zero() {
		if b.is_odd() {
			r = r * a % modulus;
		}
		a = a * a % modulus;
		b = b / (U::one() + U::one());
	}
	r
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(void){
    int S[99],N,i,m,l,n,flag=1;
    
    for(i = 0;;i++){
        S[i] = getchar();
        N = i;
        if(S[i] == '\n')
            break;
        
    }
    m = (N-1)/2-1;
    l = (N+3)/2-1;
    n = N-1;
    
    for(i = 0;i < N;i++,n--){
        if(S[i] != S[n])
            flag = 0;
    }
    
    for(i = 0;i < (N-1)/2;i++,m--){
        if(S[i] != S[m]){
            flag = 0;
        }
    }
    n = N-1;
    for(i = N;i > (N+3)/2;i--,l++,n--){
        if(S[l] != S[n]){
            flag = 0;
        }
    }
    if(flag == 0)
        printf("No\n");
    else
        printf("Yes\n");
        
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 2010;
const long double PI = acos(-1);

bool f(ll n){
    ll l = n%10;
    while(n){
        if (abs(n%10 - l) > 1) return false;
        n/=10;
    }
    return true;
}

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a;
    cin >> a;

    cout << a + a*a + a*a*a << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std;
int main()
{
   set<int > m;
   int n,i,x;
   cin>>n;
   for(i = 0;i < n;i++)
   {
       cin>>x;
       m.insert(x);
   }
   if(m.size()==n)
    cout<<"YES"<<endl;
   else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 9600
// include headers{{{
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*}}}*/
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


int n, k;


long double calc_prob(int coin) {
    int current_score = coin;
    long double prob = 1.0;

    while (true) {
        if (current_score >= k) break;
        current_score *= 2;
        prob *= 0.5;
    }
    return prob;
}



int main() {
    cin >> n >> k;
    long double prob_lose = 0.0;

    rep (i, n) {
        prob_lose += calc_prob(i+1)/n;
    }

    cout.precision(10);
    cout << prob_lose << endl;
    return 0;
}



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

string s;
int n, ans;

int check(int n, string s){
	if(s.compare(0,n/2, s.substr(n/2, n/2))==0){
		return n;
	}

	return check(n-2, s);
}

int main() {
	cin >> s;
	n = s.size();
	ans = check(n, s.substr(0, n-2));
	cout << ans << endl;
}

Measured memory_bytes: 256
abc=[int(i) for i in input().split(" ")]
abc=sorted(abc)
a,b,c=abc[0],abc[1],abc[2]
if a==b:
    print(str(c-a))
else:
    if (a-b)%2==0:
        print(str(int((b-a)/2+c-b)))
    else:
        print(str(int((b-a-1)/2+1+c+1-b)))


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <ctime>
#include <queue>
#include <vector>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <assert.h>  
#include <unordered_map>  
#include <string.h>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
 
#define y1 needtrainharder
#define f first
#define s second
#define gg exit(0)
#define sz() size()
#define pb push_back
#define mp make_pair
#define skip continue
#define all(x) x.begin(), x.end()
#define alln(x, y) x, x + y
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define file(s) if(fopen(task".in", "r"))freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define task "sorting"    
 
const int inf = 1e9 + 5;  
const ll infll = 1e18 + 5ll;  
const long double eps = 1e-9;
const long double pi = acos(-1);
const int maxn = 3e5;
const ll maxlog = 21;
const int P = 97;
const int mod = 1e9 + 7;   
const int block = 707;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int n, a[maxn], b[maxn], c[maxn], dp1[maxn], dp2[maxn], dp3[maxn];

int main() {
  file(task); 
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
    dp1[i] = inf;
    dp2[i] = inf;
    dp3[i] = inf;
  }
  dp1[1] = a[1];
  dp2[1] = b[1];
  dp3[1] = c[1];
  for (int i = 2; i <= n; ++i) {
    dp1[i] = max({dp2[i - 1], dp3[i - 1]}) + a[i];
    dp2[i] = max({dp1[i - 1], dp3[i - 1]}) + b[i];
    dp3[i] = max({dp1[i - 1], dp2[i - 1]}) + c[i];
  }
  cout << max({dp1[n], dp2[n], dp3[n]});
  return 0;
}
/*





*/

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

const ll MOD = 998244353;

int main() {
    ll n,s;
    std::cin >> n>>s;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    // iまでみてjとなる組み合わせ数
    vector<vector<ll>> dp(n+1,vector<ll>(s+1,0));
    dp[0][0] = 1;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < s+1; j++) {
            dp[i+1][j] += dp[i][j]*2;
            if(j-a[i]>=0)dp[i+1][j] += dp[i][j-a[i]]; 
            dp[i+1][j] %= MOD;
        }
    }
    
    std::cout << dp[n][s] << std::endl;
}


Measured memory_bytes: 73660
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a;
  if(a<1200) co("ABC");
  else co("ARC");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
const int MOD = 2019;

int main(){
    string s;
    cin >> s;
    vector<int> memo(s.length()+10, 0);
    int base10 = 1;
    for(int i = s.length()-1; i >= 0; i--){
        memo[i] = memo[i+1];
        memo[i] += (s[i]-'0')*base10;
        memo[i] %= MOD;
        base10 *= 10;
        base10 %= MOD;
    }

    vector<int> bucket(MOD, 0);
    for(int i = 0; i <= s.length(); i++) bucket[memo[i]]++;
    int ans = 0;
    for(int i = 0; i < MOD; i++) ans += bucket[i] * (bucket[i]-1) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

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


int main(void) {
  ll sum1[200], sum2[200];
  ll n, a1, a2;
  ll b[200];

  cin >> n;

  cin >> a1;
  sum1[0] = a1;

  FOR(i, 1, n) {
	cin >> a1 ;
	sum1[i] = sum1[i - 1] + a1;
  }

  cin >> a2;
  b[0] = a2;

  FOR(i, 1, n) {
	cin >> a2;
	b[i] = a2;
  }

  sum2[n] = 0;

  RFOR(i, 0, n) {
	sum2[i] = sum2[i + 1] + b[i];
  }

  FOR(i, 0, n) {
	ans = max(ans, sum1[i] + sum2[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N, K = list(map(int,input().split()))

mod = 10**9 + 7
array = []

for k in range(1, K+1):
    array.append(pow((K // k), N, mod))
    
for k in range(K, 0, -1):
    for i in range(2*k, K+1, k):
        array[k-1] -= array[i-1]

sum = 0
for k in range(1, K+1):
    array[k-1] *= k
    array[k-1] %= mod
    sum += array[k-1]
    
sum %= mod

print(sum)

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

#define IO          ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int         long long
#define double      long double
#define vi          vector <int>
#define vvi         vector <vi>
#define pii         pair <int,int>
#define vii         vector <pii>
#define nl          '\n'
#define yy          "YES\n"
#define nn          "NO\n"
#define pb          emplace_back
#define all(v)      (v).begin(), (v).end()
#define rall(v)     (v).rbegin(), (v).rend()
#define mod         1000000007

signed main()
{
        int n;
        string s;
        cin >> n;
        cin >> s;
        int red = 0;
        for (char &c : s) {
            if (c == 'R') {
                red++;
            }
        }
        int ans = 0;
        for (int i = 0; i < n && red; i++) {
            if (s[i] == 'W') {
                ans++;
            }
            red--;
        }
        cout << ans;
}


Measured memory_bytes: 3724
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

#include<unistd.h>
char buff[1 << 22];
template <int size>
struct Buffer{
    int idx = 0;
    Buffer(){ read(0, buff, size); }
    void next(int& ret){
        // int ret = 0;
        ret = 0;
        while(!(buff[idx] & 0x10)){ idx++; }
        while(buff[idx] & 0x10){ ret = ret * 10 + buff[idx++] - '0'; }
        // while(!isdigit(buff[idx])){ idx++; }
        // while(isdigit(buff[idx])){ ret = ret * 10 + buff[idx++] - '0'; }
        // return ret;
    }
};
struct FastInput {
    Buffer<1 << 22> buf;
    template <class T>
    FastInput& operator >> (T& num) { buf.next(num); return *this; }
    // FastInput& operator >> (T& num) { num = buf.next(); return *this; }
    void tie(int){ }
    template <class S, class T>
    friend FastInput& operator >> (FastInput& in, pair<S, T>& p){ return in >> p.first >> p.second; }
    template <class T>
    friend FastInput& operator >> (FastInput& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
};
FastInput fin;
#define cin fin

enum { SIZE = 1 << 20 };
char buf[SIZE];
int accs[512][512];
pair<int, int> pqs[100000];
int main(){
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        accs[0][r]++;
        accs[l + 1][r]--;
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            accs[i + 1][j] += accs[i][j];
            accs[i][j] += accs[i][j - 1];
        }
    }
    int idx = SIZE;
    for(int i = 0; i < q; i++){
        cin >> pqs[i].first >> pqs[i].second;
    }
    for(int i = q - 1; i >= 0; i--){
        int p = pqs[i].first, q = pqs[i].second;
        buf[--idx] = '\n';
        div_t num2;
        num2.quot = accs[p][q];
        do{
            num2 = div(num2.quot, 10);
            buf[--idx] = num2.rem + '0';
        }while(num2.quot);
    }
    write(1, buf + idx, SIZE - idx);
}


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

class Dice{
    public:
    int f[6];
    Dice(){}
        void roll_x(){roll(1,4,6,3);} // to E
        void roll_y(){roll(1,2,6,5);} // to N
        void roll(int a, int b, int c, int d){
            int t=f[a]; f[a]=f[b]; f[b]=f[c]; f[c]=f[d]; f[d]=t;
        }
        void move(char ch){
            if(ch=='E') roll_x();
            if(ch=='S') for(int i=0;i<3;i++) roll_y();
            if(ch=='W') for(int i=0;i<3;i++) roll_x();
            if(ch=='N') roll_y();
        }
};

int main(){
    Dice d;
    string name;
    
    for(int i=1;i<=6;i++) cin >> d.f[i];
    cin >> name;
    for(int i=0;i<name.size();i++){
        d.move(name[i]);
    }
    
    cout << d.f[1] << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    int res = 0;
    for (int i = 0; i < N; i++) {
        int cnt = 0, x;
        for (int j = 0; j < M; j++) {
            cin >> x;
            if (x == 1) ++cnt;
        }
        res = max(res, cnt);
    }
    cout << res << endl;
    return 0;
}

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

long int n,l,s,e,c,ans;
int main() 
{ 

	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>l;
    s = l;
    e = l+n-1;

    if(e<=0)
    	c = e;
    else if(s>=0)
    	c = s;
    else
    	c = 0;
    ans = (((s+e)*(e-s+1))/2)-c;
    cout<<ans;

} 


Measured memory_bytes: 3624
const lines=readlines()
input()=shift!(lines)
int(x)=parse(Int,x)
intLine()=map(int,split(input()))
function inE(e)
    u,v=intLine()
    push!(e[u],v)
end
function bfs(e,f,s,t)
    q=Array{Pair{Int,Int}}([s=>1])
    while !isempty(q)
        v,m=shift!(q)
        u=m>2?1:m+1
        for w=e[v]
            if f[w,u]<0
                f[w,u]=f[v,m]+1
                push!(q,w=>u)
            end
        end
    end
end
function main()
    n,m=intLine()
    e=Array{Int,1}[[]for i=1:n]
    for i=1:m;inE(e);end
    s,t=intLine()
    f=ones(Int,(n,3))*-3
    f[s,1]=0
    bfs(e,f,s,t)
    show(f[t,1]÷3)
end
main()

Measured memory_bytes: 165636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f;
}
const int maxn = 1e5 + 5; 
int n;
int f[maxn];
int head[maxn];
struct edge {
	int to, nex;
	edge(int to=0,int nex=0):to(to),nex(nex){} 
};
vector<edge> G;
inline void addedge(int u, int v) {
	G.push_back(edge(v, head[u])), head[u] = G.size() - 1;
	G.push_back(edge(u, head[v])), head[v] = G.size() - 1;
}
bool dfs(int u, int fa) {
	for(int i = head[u]; ~i; i = G[i].nex) {
		int v = G[i].to; if(v == fa) continue;
		if(dfs(v, u)) return 1; 
		f[u] += f[v];
	}
	if(f[u] > 1) return 1;
	f[u] ^= 1;
	return 0;
}
bool solve() {
	return dfs(1, 0) || f[1];
}
int main() {
	read(n);
	memset(head, -1, sizeof(head));
	for(int i = 1; i < n; ++i) {
		int u, v; read(u), read(v);
		addedge(u, v);
	}
	puts(solve() ? "First" : "Second");
	return 0;
} 

Measured memory_bytes: 2804
N, M = map(int, input().split())
S = [0] + list(map(int, input().split()))
T = [0] + list(map(int, input().split()))
mod = 10**9 + 7

dp = [[0] * (M+1) for i in range(N+1)]
dp_sum = [[0] * (M+1) for i in range(N+1)]

for i in range(1, N+1):
    for j in range(1, M+1):
        if S[i] == T[j]:
            dp_sum[i][j] = dp_sum[i][j-1] + dp_sum[i-1][j] + 1
        else:
            dp_sum[i][j] = dp_sum[i][j-1] + dp_sum[i-1][j] - dp_sum[i-1][j-1]
        dp_sum[i][j] %= mod

print((dp_sum[N][M]+1) % mod)


Measured memory_bytes: 104284
// Problem : Virus Tree 2
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc133_e
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testc   \
    int tcc;    \
    cin >> tcc; \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//#define int ll

int n,k;
vector<int> adj[(int)1e5+10];
ll ans=0;

void dfs(int cur,int p){
	int avail=p==-1?k-1:k-2;
	for(int nxt:adj[cur]){
		if(nxt==p) continue;
		if(avail==0){
			ans=0; return;
		}
		(ans*=avail--)%=MOD;
		dfs(nxt,cur);
	}
}

signed main() {
	fast_io;
	cin>>n>>k;
	lp(i,0,n-1){
		int x,y; cin>>x>>y;
		x--,y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	//k for root
	//dfs func will give answer for all children
	ans=k;
	dfs(0,-1);
	cout<<ans;
}
// code!=think
// least efficient code to get ac


Measured memory_bytes: 13700
<?php
//error_reporting(0);
$N = (int)trim(fgets(STDIN));
//$R = trim(fgets(STDIN));
//list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
$val = array_count_values($A);
for($i=1;$i<=$N;$i++) {
  if (isset($val[$i])) {
    printf("%d\n",$val[$i]);
  }
  else {
    printf("%d\n",0);
  }
}


Measured memory_bytes: 35956
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}



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

    ll n,m;
    cin>>n>>m;
    if(n%2==0)n--;
    array<ll,2> ans[m]={};
    set<int> st;
    for(int i=0;i<n;i++)st.insert(i);
    int now = 0;
    int dif = n/2;
    for(int i=0;i<m;i++){
        int r = (now+dif)%n;
        dif--;
        ans[i] = {now, r};
        st.erase(now);
        st.erase(r);
        if(st.lower_bound(r) == st.end()){
            now = *st.begin();
        }
        else now = *st.lower_bound(r);
    }
    for(int i=0;i<m;i++){
        cout << ans[i][0]+1 << " " << ans[i][1] +1 << "\n";
    }
}

Measured memory_bytes: 13488
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

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

	ll t, i, x, j, y, 	z, k, n;
	string s;
	cin >> s;
	debug(s);
	if (s == "RRR")	return cout << 3, 0;
	if (s[1] == 'R') {
		if (s[0] == 'R' or s[2] == 'R')	return cout << 2, 0;
		return cout << 1, 0;
	}
	// if (find(all(s), "RR") != s.end())	return cout << 2, 0;
	if (s[0] == 'R' or s[2] == 'R')	return cout << 1, 0;
	// if (find(all(s), 'R') != s.end())	return cout << 1, 0;
	cout << 0;
}



Measured memory_bytes: 3644
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
	public Main() {
		FastScanner scanner = new FastScanner();
		int N = scanner.nextInt();
		
		int Z = 0;
		for (int i = 0; i < N; i++) {
			int D1 = scanner.nextInt();
			int D2 = scanner.nextInt();
			
			if (D1 == D2) {
				Z++;
				
				if (Z == 3) {
					System.out.println("Yes");
					return;
				}
			} else {
				Z = 0;
			}
		}
		
		System.out.println("No");
	}
	
	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}
	
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main() {
    int n,m,ans;
    cin>>n>>m;
    vector<ll> a(n),b(n),c(m),d(m);
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];
    for(int i=0; i<m; i++) cin>>c[i]>>d[i];
    
    for(int i=0; i<n; i++) {
        ll dis, tmp = 2e9;
        for(int j=0; j<m; j++) {
            dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(dis < tmp) {
                tmp = dis;
                ans = j+1;
            }
        }
        cout<<ans<<"\n";
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

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

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

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

    rep(i,3)cin>>tmp[i];
    sort(tmp,tmp+3);
    if(tmp[0]==tmp[1])Cout(tmp[2]);
    else Cout(tmp[0]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <functional>
using namespace std;

typedef pair<int, int> P;
const int INF = 1e+9;

int R, C, sen[11][10001], ans;
bool f[11]; // i行目を回転させるか

int cnt(){
	int res = 0;
	for(int j = 0; j < C; ++j){
		int cc = 0;
		for(int i = 0; i < R; ++i){
			if((!sen[i][j] && !f[i]) || (sen[i][j] && f[i]))
				cc++;
		}
		if(cc > R - cc)
				res += cc;
		else
			res += R - cc;
			
	}
	return res;
}

void rec(int n){
	if(n == R){
		ans = max(ans, cnt());
	}	
	else{
		f[n] = false; // 裏返さない
		rec(n + 1);
		f[n] = true; // 裏返す
		rec(n + 1);
	}
}

int main() {
	while(cin >> R >> C && (R || C)){
		ans = 0;
		for(int i = 0; i < R; ++i){
			for(int j = 0; j < C; ++j){
				scanf("%d", &sen[i][j]);
			}
		}
		rec(0);
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1632
#include<stdio.h>
int main(){
  int a, b;
  while(1) {
    scanf("%d %d",&a,&b);
    if(a==0||b==0) break;
    for(int i = 0; i<a; i++) {
      for(int j = 0; j<b; j++) {
        printf("#");
      }  
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2532
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10 ** 6)


def main():
	s = sys.stdin.readline().rstrip()
	n = len(s)
	front = s[:(n-1)//2]
	end = s[(n+3)//2-1:]
	if len(front) % 2 == 0:
		ff = front[:len(front)//2]
		fe = front[len(front)//2:]
	else:
		ff = front[:len(front)//2]
		fe = front[len(front)//2+1:]
	if len(end) % 2 == 0:
		ef = end[:len(end)//2]
		ee = end[len(end)//2:]
	else:
		ef = end[:len(end)//2]
		ee = end[len(end)//2+1:]
	if front == end[::-1] and ff == fe[::-1] and ef == ee[::-1]:
		print("Yes")
	else:
		print("No")

main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N+1);
  for (int i = 1; i <= N; i++)
    cin >> a[i];

  for (int i = K + 1; i <= N; i++)
    cout << (a[i] > a[i-K] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 4824
#include<iostream>
using namespace std;
int n, w[7], b;
double a;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		b = (a - 155.0) / 5;
		if (b < 1) { b = 1; }
		if (b > 6) { b = 6; }
		w[b]++;
	}
	for (int i = 1; i <= 6; i++) {
		cout << i << ':';
		for (int j = 0; j < w[i]; j++) {
			cout << '*';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a=700;
  string s;
  std::cin >> s;
  if(s[0]=='o') a+=100;
  if(s[1]=='o') a+=100;
  if(s[2]=='o') a+=100;
  std::cout << a << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[4],t[4],ch1,ch2;

    gets(s);
    gets(t);
    int i,c;
    c=0;
    for(i=0; s[i]!='\0'; i++)
    {
        if(s[i]==t[i])
            c++;
    }

    printf("%d\n",c);

    return 0;
}


Measured memory_bytes: 128
N,C = map(int,input().split())
D = [list(map(int,input().split())) for _ in range(C)]
c = [list(map(int,input().split())) for _ in range(N)]

cst = [[0,0,0] for i in range(C)]

for i in range(N):
    for j in range(N):
        cst[c[i][j]-1][(i+j)%3] += 1

ans = 10**10

for i in range(C):
    for j in range(C):
        for k in range(C):
            if i == j or i == k or j == k:
                continue
            x = [i,j,k]
            a = 0
            for l in range(3):
                for m in range(C):
                    a += D[m][x[l]]*cst[m][l]
            ans = min(ans,a)

print(ans)


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

long N,n;
vector<long> A;

main(){
    for(cin>>N;cin>>n;n=1LL<<50)A.push_back(n);
    auto a=A.begin(),t=a+1,d=A.end(),b=t+1;
    partial_sum(a,d,a);
    for(--d;t+1!=d;++t){
        while(a+1!=t)
            if(*a<*t-*(a+1))++a;
            else break;
        if(b==t)++b;
        for(;b+1!=d&&*b-*t<*d-*(b+1);++b);
        n=min(n,max({*a,*t-*a,*b-*t,*d-*b})-min({*a,*t-*a,*b-*t,*d-*b}));
    }
    cout<<n<<" ";
}


Measured memory_bytes: 2420
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline

def solve(n,x,t):
    print (((n-1)//x+1) * t)

            

def main():
    n,x,t = map(int,input().split())
    solve(n,x,t)


if __name__ == "__main__":
    main()

Measured memory_bytes: 64848
time = int(input())

while time > 0 :
    a,b,c = (int(x) for x in input().split())
    
    if (a**2 == b**2 + c **2) or (b**2 == c**2 + a**2) or (c**2 == a**2 + b**2) :
        print("YES")
        
    else :
        print("NO")
    
    time -= 1
    



Measured memory_bytes: 5600
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
using namespace std;
int main(){
 long long n;
 scanf("%lld",&n);
 long long b[20000001]={0};
 long long i,j,jmax,p;
 vector<long long>a;
 for(i=0;i<n;i++){
  scanf(" %lld",&p);
  b[p]++;
  a.push_back(p);
 }
 sort(a.begin(),a.end());
 long long ans=0,max=a[n-1];
 for(i=0;i<=max;i++){
  if(b[i]==1)ans++;
  if(i!=0)jmax=max/i;
  if(i==0)jmax=1;
  if(b[i]!=0){
   for(j=0;j<=jmax;j++)
    b[i*j]=0;
   }
 }
  
 printf("%lld\n",ans);
return 0;}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long
void codeforces()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    #endif
}

int32_t main()
{
    //codeforces();
    // int t;cin>>t;
    // while(t--) {
        
    // }
    int n,k;cin>>n>>k;
    vi a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vi dp(n,INT_MAX);
    dp[0]=0;
    if(n==1){
        cout<<dp[0]<<endl;return 0;
    }
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            int x=a[i];
            if(i+j<n){
                int y=a[i+j];
                y=abs(y-x);
                dp[i+j]=min(dp[i+j],y+dp[i]);
            }
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.*;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		final int B_TOTAL = 4;
		final int F_TOTAL = 3;
		final int R_TOTAL = 10;
		Room[][][] univ_rooms = new Room[B_TOTAL][F_TOTAL][R_TOTAL];
		
		for (int i = 0; i < B_TOTAL; i++) {	
			for (int j = 0; j < F_TOTAL; j++) {
				for (int k = 0; k < R_TOTAL; k++) {
					univ_rooms[i][j][k] = new Room(0);
				}
			}
		}
		
		int n = Integer.parseInt(br.readLine());
		String[] str = new String[4];
		int b, f, r, v;
		for (int i = 0; i < n; i++) {
			str = br.readLine().split("\\s+");
			b = Integer.parseInt(str[0]);
			f = Integer.parseInt(str[1]);
			r = Integer.parseInt(str[2]);
			v = Integer.parseInt(str[3]);
			univ_rooms[b - 1][f - 1][r - 1].setResidents(v);
		}
		
		for (int i = 0; i < univ_rooms.length; i++) {
			for (int j = 0; j < univ_rooms[i].length; j++) {
				for (int k = 0; k < univ_rooms[i][j].length; k++) {
					System.out.print(" " + univ_rooms[i][j][k].getResidents());
				}
				System.out.println();
			}
			if (i < univ_rooms.length - 1) System.out.println("####################");
		}
		
	}
}

class Room {
	
	private int residents;
	
	Room(int residents) {	
		this.residents	= residents;
	}
	
	public int getResidents() {
		return this.residents;
	}
	
	public void setResidents(int n) {
		this.residents += n;
		if (this.residents > 9) this.residents = 9;
		if (this.residents < 0) this.residents = 0;
	}
}

Measured memory_bytes: 25312
#include <stdio.h>

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2],R[MAX / 2 + 2];

llong merge(int A[], int n, int left, int mid, int right){
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i = 0; i < n1; i++){ L[i] = A[left + i];}
	for(i = 0; i < n2; i++){ R[i] = A[mid + i];}
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for(k = left; k < right; k++){
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

llong mergeSort(int A[], int n, int left, int right){
	int mid;
	llong v1, v2, v3;
	if(left + 1 < right){
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else{ return 0;}
	
}
	
int main(){
	int A[MAX], n, i;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", & A[i]);
	}
	
	llong ans = mergeSort(A, n, 0, n);
	printf("%ld\n", ans);
	
	return 0;
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main()
{
    long long n,k,ans=0;
    cin>>n>>k;
    for(long long i=k;i<=n+1;i++)
    {
        long long z=(i-1)*i/2;
        long long z2=(2*n-i+1)*i/2;
        //cout<<z<<" "<<z2<<endl;
        ans+=(z2-z+1)%mod;
        ans%=mod;
       // cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    print(N-K+1)

if __name__ == '__main__':
    main()


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

int main(){
	int n, a[101];
	int ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n; i += 2){
		if (a[i] % 2 == 1){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // float operations
#include <stack> // stack
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <regex> // regular expressions

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << std::setprecision(10) << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
#define ld long double
/* libraries */

signed main() {
	ld a,b,x;
	std::cin >> a >> b >> x;
	ld s = x/a;
	ld fix = 180;
	fix/=M_PI;
	ld c = (ld)2*s/b;
	if(c<=a) print(std::atan2(b,c)*fix);
	else {
		ld d = (ld)2*s/a-b;
		print(std::atan2((b-d),a)*fix);
	}
	return 0;
}


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

using namespace std;


int main() {

  long long h; cin >> h;
  
  long long c = 0;
  long long ans = 0;
  while(h>0){
    h = h/2;
    ans += pow(2,c);
    c++;
  }
  
  cout << ans << endl;  

}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] S = sc.next().split("");
        String ret = "Yes";
        if (S[0].equals(S[1]) && S[1].equals(S[2])) {
            ret = "No";
        }
        System.out.println(ret);
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min((min((a+b),(b+c))),(a+c))<<endl;
}

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

int main() {
  int n,ans = 0;
  cin >> n;
  rep(i,0,n){
    int a;
    cin >> a;
    if(i%2 == 0 && a%2 == 1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what
 
using namespace std;
 
const int N = (int) 1e6 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;
 
int n;
int a[N], b[N];
 
int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        b[i] = a[(i + 1) % n] - a[i];
    }
    ll sum1 = 0, sum2 = (n * 1ll * (n + 1)) / 2;
    for (int i = 0; i < n; i++) {
        sum1 += a[i];
    }
    if (sum1 % sum2) {
        cout << "NO";
        return 0;
    }
    ll cnt = sum1 / sum2;
    sum1 = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] > cnt || (cnt - b[i]) % n) {
            sum1 = -1;
            break;
        }
        sum1 += (cnt - b[i]) / n;
    }
    if (sum1 == cnt) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 5244
#include <queue>
#include <iostream>
#include <cstdio>
using namespace std;
char map[25][25];
int mov[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int vis[25][25] = {0}, d[25][25];
int n, m;
struct node
{
	int x, y;
}now, tmp;
int solve(int x, int y)
{
	queue <struct node> q;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			vis[i][j] = 0; d[i][j] = 1e9;
		}
	d[x][y] = 0;
	vis[x][y] = 1;
	now.x = x; now.y = y;
	q.push(now);
	while(!q.empty())
	{
		now = q.front(); q.pop();
		for(int i = 0; i < 4; i++)
		{
			tmp.x = now.x + mov[i][0];
			tmp.y = now.y + mov[i][1];
			if(tmp.x<=0||tmp.x>n||tmp.y<=0||tmp.y>m) continue;
			if(map[tmp.x][tmp.y]=='#') continue;
			if(vis[tmp.x][tmp.y]) continue;
			d[tmp.x][tmp.y] = 1 + d[now.x][now.y];
			vis[tmp.x][tmp.y] = 1;
			q.push(tmp);
		}
	}
	int res = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			if(vis[i][j] && res < d[i][j]) res = d[i][j];
		}
	return res;
}
int main()
{
	int res = 0;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%s", map[i]+1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
		if(map[i][j]=='.')
		{
			res = max(res, solve(i, j));
		}
	printf("%d\n", res);
}

Measured memory_bytes: 256
from itertools import count

n = int(input())

dp = [0]*(n+1)

#[1,6,36,9,81]などのn以下で使える数字を出力してくれる。
def it(n):
  yield 1
  m = 6
  while m <= n:
    yield m
    m *= 6
  m = 9
  while m <= n:
    yield m
    m *= 9

#1~nまでの数をループで回す
for i in range(1,n+1):
  #print(list(t for t in it(i)))
  #使える数字全部使ってそこまでのdpを
  dp[i] = min(dp[i-t] for t in it(i))+1
  
print(dp[n])



Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n,m;
  cin>>n>>m;
  int h[n];
  rep(i,n) cin>>h[i];
  int a,b;
  int v[n];
  rep(i,n) v[i]=0;
  rep(i,m){
    cin>>a>>b;
    a--;
    b--;
    if(h[a]==h[b]){
      v[a]++;
      v[b]++;
    }
    if(h[a]>h[b]) v[b]++;
    if(h[a]<h[b]) v[a]++;
  }
  
  int ans=0;
  rep(i,n){
    if(v[i]==0){
      ans++;
      
    }
    //cout<<v[i]<<endl;
  }
  
  cout<<ans<<endl;
}
  

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;

int n,k;
int x[60],y[60];
vector<int > xnary, ynary;

int main(){
  //  freopen("test.txt","r",stdin);
    cin >> n >> k;
    for (int i = 0 ; i<n ; i++) {
        cin >> x[i] >> y[i];
        xnary.pb(x[i]);
        ynary.pb(y[i]);
    }
    sort(xnary.begin(), xnary.end());
    sort(ynary.begin(), ynary.end());

    long long ans = 1LL*(xnary[n-1] - xnary[0] ) * ( ynary[n-1] - ynary[0]);

    for (int xi = 0 ; xi < n ; xi++) {
        for (int xj = xi + 1 ; xj < n ; xj++) {
            for (int yi = 0 ; yi < n ; yi++) {
                for (int yj = yi + 1; yj < n ; yj++) {
                    int num = 0;
                    long long sx = xnary[xi], lx = xnary[xj];
                    long long sy = ynary[yi], ly = ynary[yj];
                    for (int c =0 ; c <  n ; c++) {
                        if ( x[c] <= lx && x[c] >= sx && y[c] <= ly && y[c] >= sy) {
                            num++;
                        }
                    }
                    if ( num >= k ) {
                        ans = min(ans, 1LL* ( lx - sx) * (ly - sy));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    int K, X;
    cin >> K >> X;
    for(int i = X-K+1; i < X+K; i++){
        cout << i << " ";
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main()
{
    int a, b; cin>>a>>b;
    if(a>=13) cout<<b<<endl;
    else if(a>=6) cout<<b/2<<endl;
    else cout<<0<<endl;
    return 0;
}

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

using namespace std;
int main() {
    int n;
    cin >> n;
    int x, a, b, cnt;
    int max = 0;
    rep(i, n) {
        cin >> x;
        if(x == 1 || x == 2) {
            cnt++;
            continue;
        }
        
        a = sqrt(x);
        

        bool noprime = 0;
        for(int i = 2; i <= a; i++) {
            if(x % i == 0) {
                noprime = 1;
                break;
            }
        }
        
        if(!noprime) {
            cnt++;
        }
    }
    
    cout << cnt << endl;
   
}
    



Measured memory_bytes: 3040
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	string S;
	stack<char> check;

	cin >> N >> S;

	rep(i, N) {
		if (check.empty() || S[i] == '(') {
			check.push(S[i]);
		}
		else {
			if (check.top() == '(') check.pop();
			else check.push(S[i]);
		}
	}

	while (!check.empty()) {
		if (check.top() == '(') S.push_back(')');
		else S.insert(S.begin(), '(');
		check.pop();
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  map<int,int> m;
  rep(i,0,n){
    int a;
    cin>>a;
    m[a]++;
  }
  int ans=0;
  for(auto p:m){
    if(p.second>=p.first){
      ans+=p.second-p.first;
    }
    else{
      ans+=p.second;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4736