akhauriyash/Code-Regression huggingface dataset:
//
//AtCoder Beginner Contest 172
//D
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    ll ans=0;
    vector<int> fk(n+1, 0);
    FOR(i, 1, n){
        for(int j=i; j<=n; j+=i){
            fk[j]++;
        }
    }
    //REP(i,n+1) MSG(fk[i]);

    FOR(i, 1, n){
        ans+=(i*fk[i]);
    }

    cout << ans << endl;
    return 0;
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
            string S = Input.ScanStr();
            for(int i = 0; i < 3; i++)
            {
                if(S[i] == S[i + 1])
                {
                    Console.WriteLine("Bad");
                    return;
                }
            }
            Console.WriteLine("Good");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N, M; cin >> N >> M;
  vector<int> x(M), y(M);
  rep(i, M) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<bool> k(N, false);
  vector<int> n(N, 1);
  k[0] = true;
  
  rep(i, M) {
    if(n[x[i]] == 1) {
      if(k[x[i]]) {
        k[x[i]] = false;
        k[y[i]] = true;
        n[x[i]]--;
        n[y[i]]++;
      } else {
        n[x[i]]--;
        n[y[i]]++;
      }
    } else {
      if(k[x[i]]) {
        k[y[i]] = true;
        n[x[i]]--;
        n[y[i]]++;
      } else {
        n[x[i]]--;
        n[y[i]]++;
      }
    }
  }
  
  int ans = 0;
  rep(i, N) if(k[i]) ans++;
  cout << ans << endl;

}

Measured memory_bytes: 5448
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    string S;
    bool flag=true;
    cin >> N;
    cin >> S;
    if(N%2==1)
	flag=false;

    for(int i=0; i<N/2; i++){
	if(S[i]!=S[N/2+i])
	    flag = false;
    }

    cout << (flag ? "Yes": "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli A[200000] = {};
lli F[200000] = {};

int main(void) {
	lli N, K;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> F[i];
	}

	sort(A, A + N);
	sort(F, F + N, std::greater<int>());

	//0より小さくなるを誤読しない

	//K回だけ引けるときは、どのように引けるかを考えるのではなく、
	//2分探索して答えの条件を満たせるか考えると良い

	//最大値は10^12

	double maxi = 1000'000'000'001LL;
	double mini = -1;
	lli ans = 1000'000'000'000LL;

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

		lli midi = maxi / 2 + mini / 2;
		lli sumK = 0;

		for (int j = 0; j < N; j++) {
			//midi >= A'[i] * F[i]
			//B  = ceil(A[i] - midi / F[i]);
			sumK += max(0.0,ceil(A[j] - midi / F[j]));
		}

		if (sumK <= K) {
			//条件を満たす練習の仕方が存在する
			maxi = midi;
			ans = std::min(ans,(lli)ceil(midi));
		}
		else {
			//条件を満たさない
			mini = midi;
		}
	}

	COUT(ans);

	//2分探索で苦労しました。doubleでやるなら答えの範囲＋１とっておくといいかもしれない。


	return 0;
}

Measured memory_bytes: 3328
n = gets.to_i
ary = []

n.times{ary << gets}
ary = ary.map{|a| a.chomp.chars.sort.join}.sort

cnt = 1; ans = 0
(1 .. n - 1).each{|i| if ary[i] == ary[i - 1] then ans += cnt; cnt += 1 else cnt = 1 end}
puts ans


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

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int n = a.back();
    int x = a.front();
    double z = abs(double(n) / 2 - x);
    for(int i = 0; i < N - 1; i++) {
        double y = abs(double(n) / 2 - a[i]);
        if (z > y) {
            z = y;
            x = a[i];
        }
    }
    cout << n << " " << x << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int r; cin >> r;
  cout << 3*r*r << endl;
}

Measured memory_bytes: 256
n=int(input())
r=[]
a=[]
for i in range(n):
  b,c=(int(j) for j in input().split())
  for k in range(i):
    d=a[k][0]-b
    e=a[k][1]-c
    if d<0:
      d=-d
      e=-e
    elif d==0:
      if e<0:
        e=-e
    r.append([d,e])
  a.append([b,c])
r.sort()
if n>1:
  p=r[0]
x=1
z=0
t=0
q=[]
for i in range(len(r)-1):
  if r[i]==r[i+1]:
    x=x+1
    if x>z:
      p=r[i]
      z=x
  else:
    x=1
for j in range(n-1):
  for i in range(n-1):
    if a[i][0]>a[i+1][0]:
      w=a[i]
      a[i]=a[i+1]
      a[i+1]=w
    elif a[i][0]==a[i+1][0]:
      if (a[i][1]-a[i+1][1])*p[1]>0:
        w=a[i]
        a[i]=a[i+1]
        a[i+1]=w
if n==1:
  print(1)
else:
  for i in range(n):
    if a[i] not in q:
      t=t+1
    q.append([a[i][0]+p[0],a[i][1]+p[1]])
  print(t)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		long cura = 0;
		long curb = 0;
		for(int i = 0; i < n; i++)
		{
			long a = sc.nextLong();
			long b = sc.nextLong();
			
			long mul = 1;
			if(i>0)
			{
				if(a<cura)
				{
					long curmul = cura/a;
					if(cura%a!=0)curmul++;
					mul = Math.max(mul, curmul);
				}
				if(b<curb)
				{
					long curmul = curb/b;
					if(curb%b!=0)curmul++;
					mul = Math.max(mul, curmul);
				}
				
			}
			cura=a*mul;
			curb=b*mul;
			
		}
		System.out.println(cura+curb);

	}

}


Measured memory_bytes: 23764
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int main(){
  int d,i,j;
  cin >> d;
  vector<int> c(26);
  vector<vector<int> > s(d);
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    printf("%d\n",randxor()%26+1);
  }
  return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

int main() {
    string str;
    cin >> str;

    int n = (int)str.size();
    int ans = 0;
    for (int x = 0, y = n - 1; x < y; ++x, --y) {
        ans += (str[x] != str[y]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable.ArrayBuffer

object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val x, y = sc.nextInt
	
	pw.println(if (x == y) "Yes" else "No")
	pw.flush()
}

Measured memory_bytes: 25544
import numpy as np

h, n = map(int, input().split())
ab = np.array([list(map(int, input().split())) for _ in range(n)])

a = ab[:, 0]
b = ab[:, 1]

dp = np.zeros(10**5, dtype=np.int)

for i in range(1, h+1):
    dp[i] = min(dp[i-a]+b)

print(dp[h])

Measured memory_bytes: 12608
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, D, A; 
  cin >> N >> D >> A;

  vector<pair<int, int>> vec(N);
  REP(i, N) cin >> vec[i].first >> vec[i].second;

  sort(ALL(vec));

  vector<int> X(N), H(N);
  REP(i, N) tie(X[i], H[i]) = vec[i];
  X.emplace_back(INF); H.emplace_back(0);

  int ans = 0;
  vector<int> cnt(N+1, 0);
  REP(i, N){
    if(i != 0) cnt[i] += cnt[i-1];
    H[i] -= cnt[i]*A;
    if(H[i] <= 0) continue;

    int now = (H[i]+A-1)/A;
    ans += now;
    cnt[i] += now;
    // x[i]+Dより上
    int t = upper_bound(ALL(X), X[i]+2*D)-X.begin();
    cnt[t] -= now;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9572
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double prob = 0;
        for(int i = 1; i <= n; i++){
            int cnt = 0;
            int num = i;
            while(num < k){
                num *= 2;
                cnt++;
            }
            prob += 1.0 / Math.pow(2.0, cnt);
        }
        System.out.println(prob / n);
    }
    
}

Measured memory_bytes: 22096
//include
 //------------------------------------------
 #include <vector>
 #include <list>
 #include <map>
 #include <unordered_map>
 #include <climits>
 #include <set>
 #include <unordered_set>
 #include <deque>
 #include <stack>
 #include <bitset>
 #include <algorithm>
 #include <functional>
 #include <numeric>
 #include <utility>
 #include <sstream>
 #include <iostream>
 #include <iomanip>
 #include <cstdio>
 #include <cmath>
 #include <cstdlib>
 #include <cctype>
 #include <string>
 #include <cstring>
 #include <ctime>
 #include <queue>
 #include <random>
 #include <complex>
 #include <regex>
 #include <locale>
 #include <random>
 #include <type_traits>
 
 using namespace std;
 
 #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
 #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}
 
 using LL = long long;
 
 //------------------------------------------
 //------------------------------------------
 
 constexpr LL mod = 1e9 + 7;
 
 int main() {
 
     string S;
     cin >> S;
 
     int N = 13;
 
     string T = S;
     reverse(T.begin(), T.end());
 
     vector<LL> dp(N, 0);
     dp[0] = 1;
 
     LL base = 1;
     for (int i = 0; i < T.size(); i++) {
         vector<LL> next(N, 0);
         if (T[i] == '?') {
             for (int k = 0; k <= 9; k++) {
                 LL d = (k * base);
                 for (int j = 0; j < N; j++) {
                     next[(d + j) % N] += dp[j];
                     next[(d + j) % N] %= mod;
                 }
             }
         } else {
             for (int j = 0; j < N; j++) {
                 LL d = ((T[i] - '0') * base);
                 next[(d + j) % N] += dp[j];
                 next[(d + j) % N] %= mod;
             }
         }
         dp = next;
         base *= 10;
         base %= 13;
     }
 
     cout << dp[5] << endl;
 
 }
 

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

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

    auto grid = vector<string>(N);
    for (auto& row : grid) cin >> row;

    auto all_white = true;
    for (auto row = 0; row < N; row++) for (auto column = 0; column < N; column++)
        if (grid[row][column] == '#') all_white = false;

    if (all_white)
    {
        cout << -1 << endl;
        return 0;
    }

    auto moves_to_black_row = numeric_limits<int>::max();
    for (auto row = 0; row < N; row++)
    {
        auto extra_needed = true;
        for (auto row2 = 0; row2 < N; row2++)
            if (grid[row2][row] == '#')
                extra_needed = false;
        const auto whites = int(count(begin(grid[row]), end(grid[row]), '.'));
        moves_to_black_row = min(moves_to_black_row, whites + extra_needed);
    }

    auto bad_columns = 0;
    for (auto column = 0; column < N; column++)
    {
        auto bad = false;
        for (auto row = 0; row < N; row++)
            if (grid[row][column] == '.')
                bad = true;
        bad_columns += bad;
    }

    cout << moves_to_black_row + bad_columns << endl;
}


Measured memory_bytes: 512
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN(s);
  if((s[0]!=s[1])&&(s[1]!=s[2])&&(s[2]!=s[3])) OUT("Good");
  else OUT("Bad");
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <tuple>
#include <set>

template <class Tp>
Tp gcd(Tp a, Tp b, Tp& x, Tp& y) {
  x = Tp(0);
  y = Tp(1);
  for (Tp u = y, v = x; a;) {
    Tp q = b/a;
    std::swap(x -= q*u, u);
    std::swap(y -= q*v, v);
    std::swap(b -= q*a, a);
  }
  return b;
}

template <class Tp>
Tp modinv(Tp a, Tp mod) {
  Tp x, y;
  gcd(a, mod, x, y);
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

template <class Tp>
Tp modadd(Tp a, Tp b, Tp mod) {
  a += b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <class Tp>
Tp modadd(const std::initializer_list<Tp>& adds, Tp mod) {
  Tp res = 0;
  for (const auto& add: adds) {
    res += add % mod;
    if (res < 0) res += mod;
    if (res >= mod) res -= mod;
  }
  return res;
}

template <class Tp>
Tp modsub(Tp a, Tp b, Tp mod) {
  a -= b % mod;
  if (a < 0) a += mod;
  if (a >= mod) a -= mod;
  return a;
}

template <class Tp>
Tp modmul(const std::initializer_list<Tp>& muls, Tp mod) {
  Tp res = 1;
  for (const auto& mul: muls) (res *= mul) %= mod;
  return res;
}

template <class Tp>
Tp modpow(Tp base, intmax_t iexp, Tp mod) {
  Tp res = 1;
  for (Tp dbl = base; iexp; iexp >>= 1) {
    if (iexp & 1) res = res * dbl % mod;
    dbl = dbl * dbl % mod;
  }
  return res;
}

class modchoose {
  std::vector<intmax_t> fact, fact_inv;
  intmax_t mod;

public:
  modchoose(intmax_t N, intmax_t mod): mod(mod) {
    fact.resize(N+1);
    fact_inv.resize(N+1);
    fact[0] = 1;
    for (intmax_t i = 1; i <= N; ++i)
      fact[i] = fact[i-1] * i % mod;

    fact_inv[N] = modinv(fact[N], mod);
    for (intmax_t i = N; i--;)
      fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
  }

  intmax_t operator ()(intmax_t n, intmax_t r) const {
    if (!(0 <= r && r <= n)) return 0;
    intmax_t res = fact[n] * fact_inv[r] % mod;
    (res *= fact_inv[n-r]) %= mod;
    return res;
  }
};

constexpr intmax_t mod = 1e9+7;

int main() {
  intmax_t N, K;
  scanf("%jd %jd", &N, &K);

  modchoose ncr(N, mod);
  intmax_t B = K;
  intmax_t R = N-K;

  for (intmax_t i = 1; i <= K; ++i) {
    intmax_t res = 0;
    if (B-i+(i-1) >= 0 && R-(i-1)+i >= 0)
      res = modmul({ncr(B-i+(i-1), i-1), ncr(R-(i-1)+i, i)}, mod);

    printf("%jd\n", res);
  }
}


Measured memory_bytes: 256
def main():
    import sys
    import heapq
    input=sys.stdin.readline
    N,M=map(int,input().split())
    A=list(map(lambda x:-1*int(x),input().split()))
    heapq.heapify(A)
    for i in range(M):
        if i==0:
            temp = -(heapq.heappop(A))//2
        else:
            heapq.heappush(A,-temp)
            temp = -(heapq.heappop(A))//2
    print(-sum(A)+temp)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 67992
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}


int pow(int a,int b){
    if(b == 0)return 1;
    int res = pow(a,b/2);
    res = res*res;
    if(b&1)res *= a;
    return res;
}

int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){
 // }
int s,w;
cin >> s >> w;
if(w >= s)cout << "unsafe" << endl;
else cout << "safe" <<endl;


   
return 0;
	
	}




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

string s[110],t[110];
int main(){
 int n,m;
 cin >> n;
 for (int i=0;i<n;i++) cin >> s[i];
 cin >> m;
 for (int i=0;i<m;i++) cin >> t[i];
 
 int ans=0;
 for (int i=0;i<n;i++){
   int score = 0;
   for (int j=0;j<n;j++) if(s[j]==s[i]) score++;
   for (int j=0;j<m;j++) if(t[j]==s[i]) score--;
   ans = max(ans, score);
 }
  cout << ans << endl;
}
  


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int n,p[55],t[55];
int dp[55][5];
int const inf = 1e8;

int main(){
    while(cin>>n,n){
        rep(i,n) cin >> p[i+1] >> t[i+1];
        rep(i,n+1)rep(k,4) dp[i][k] = inf;
        dp[0][0]=0;
        rep(i,n)rep(k,4){
            if(k<3 && abs(p[i+1]-p[i])*(k+1) + t[i] <= t[i+1]){
                dp[i+1][k+1] = min(dp[i+1][k+1] , dp[i][k]+abs(p[i+1]-p[i]));
            }
            if(p[i]*(k+1) + p[i+1] + t[i] <=t[i+1]){
                dp[i+1][1] = min(dp[i+1][1] , dp[i][k]+p[i]+p[i+1]);
            }
        }
        int ans=inf;
        rep(k,4)ans=min(ans,dp[n][k]+p[n]);

        if(ans >= inf){
            int x;
            rep(i,n) rep(k,4) if(dp[i][k] < inf) x = i;
            cout << "NG " << x+1 << endl;
        } else {
            cout << "OK " << ans << endl;
        }
    }
}

Measured memory_bytes: 1160
#include <stdio.h>

int gcd(int x, int y);
int swap(int x, int y);
  
int main(){
  int x, y;
  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x, y));  
}

int gcd(int x, int y){
  if(x > y)
    return swap(x, y);
  else return swap(x, y);
}
int swap(int p, int q){
  int r;
  while(q > 0){
    r = p % q;
    p = q;
    q = r;
  }
  return p;
}



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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, c = map(int, input().split())

if c - a - b <= 0:
    ans = 'No'
elif 4 * a * b < pow((c - a - b), 2):
    ans = 'Yes'
else:
    ans = 'No'

print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        int m = Math.max(a, b);
        List<Integer> candidates = new ArrayList<>();
        for (int i = 1; i <= m; ++i) {
            int a_out = a % i;
            int b_out = b % i;
            if (a_out == 0 && b_out == 0) candidates.add(i);
        }
        System.out.println(candidates.get(candidates.size() - c));
    }
}


Measured memory_bytes: 22740
a, b = map(int, input().split())

a_div = []
b_div = []

i = 1
while i * i < a + 1:
    if a % i == 0:
        a_div.append(i)
        a_div.append(a // i)
    i += 1
i = 1
while i * i < b + 1:
    if b % i == 0:
        b_div.append(i)
        b_div.append(b // i)
    i += 1

common = set(a_div) & set(b_div)

disjoint = set()
for num in sorted(list(common)):
    if num == 1:
        disjoint.add(num)
    else:
        for disnum in sorted(list(disjoint)):
            if disnum == 1:
                continue
            elif num % disnum == 0:
                break
        else:
            disjoint.add(num)

print(len(disjoint))

Measured memory_bytes: 5172
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        if (K > ((N-1)*(N-2))/2) {
            System.out.println(-1);
            return;
        }
        ArrayList<Integer>[] graph = new ArrayList[N];
        for(int i = 0 ;i < N; i++) {
            graph[i] = new ArrayList<>();
            for(int j = 0; j < N; j++) {
                if (i == j) continue;
                graph[i].add(j);
            }
        }
        int nedges = ((N-1)*N)/2;
        int curK = 0;
        int curNode = 1;
        while(curK < K) {
            if (graph[curNode].size() == 1) curNode++;
            int nextRem = graph[curNode].get(graph[curNode].size()-1);
            graph[curNode].remove(graph[curNode].size()-1);
            graph[nextRem].remove(Integer.valueOf(curNode));
            nedges--;
            curK++;
        }
        out.println(nedges);
        for(int i = 0; i < N; i++) {
            for(int edge: graph[i]) {
                if (edge > i) out.println((i+1) + " " + (edge+1));
            }
        }
        out.flush();
    }
    
    static class Pair implements Comparable<Pair> {
        int a, b;
        public Pair(int aa, int bb) {
            a = aa; b = bb;
        }
        public int compareTo(Pair o) {
            if (b == o.b) return a - o.a;
            return b - o.b;
        }
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 23124
def main_1_11_A():
    values = list(map(int, input().split()))
    query = input()

    dice = Dice(values)
    for d in query:
        dice.roll(d)


def main_1_11_B():
    values = list(map(int, input().split()))
    n = int(input())

    for _ in range(n):
        t_value, s_value = map(int, input().split())

        print(_B(values, t_value, s_value))


def _B(values, t_value, s_value):
    """
    ????????¢?????????????????¨??????
    ??´??¢???????????¢?????????????????§???????????????????????¨?????????
    ??????????????????????????¢???????¢??????????
    """
    def rot_n(dice, n):
        for _ in range(n):
            dice.roll("N").roll("E").roll("S")
        return dice

    def make_dices():
        # ?????¢???TOP?????????
        return [
            Dice(values),
            Dice(values).roll("N"),
            Dice(values).roll("N").roll("N"),
            Dice(values).roll("N").roll("N").roll("N"),
            Dice(values).roll("E"),
            Dice(values).roll("W"),
        ]

    dices = (
        make_dices() +
        list(map(lambda dice: rot_n(dice, 1), make_dices())) +
        list(map(lambda dice: rot_n(dice, 2), make_dices())) +
        list(map(lambda dice: rot_n(dice, 3), make_dices()))
    )
    for dice in dices:
        # print(dice)
        for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
            dice.roll(d)
            #print(d, (dice.top_value, dice.south_value), (t_value, s_value))
            if (dice.top_value, dice.south_value) == (t_value, s_value):
                return dice.east_value


class Dice:

    def __init__(self, values):
        self.values = values
        # top, bottom, direction 4
        self.t = 1
        self.b = 6
        self.w = 4
        self.e = 3
        self.n = 5
        self.s = 2

    def __repr__(self):
        labels = {
            "t": self.t,
            "b": self.b,
            "w": self.w,
            "e": self.e,
            "n": self.n,
            "s": self.s,
        }
        return "<%s (%s, %s)>" % (self.__class__, self.values, labels)

    def roll(self, direction):
        if direction == "E":
            after_lables = self.t, self.b, self.e, self.w
            self.e, self.w, self.b, self.t = after_lables
        elif direction == "W":
            after_lables = self.t, self.b, self.e, self.w
            self.w, self.e, self.t, self.b = after_lables
        elif direction == "S":
            after_lables = self.t, self.b, self.n, self.s
            self.s, self.n, self.t, self.b = after_lables
        elif direction == "N":
            after_lables = self.t, self.b, self.n, self.s
            self.n, self.s, self.b, self.t = after_lables

        return self

    @property
    def top_value(self):
        return self.values[self.t - 1]

    @property
    def south_value(self):
        return self.values[self.s - 1]

    @property
    def east_value(self):
        return self.values[self.e - 1]

if __name__ == "__main__":
    # main_1_11_A()
    main_1_11_B()

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp[3010][3010][4];
ll cell[3010][3010];

void solve() {
    ll R, C, K;
    cin >> R >> C >> K;
    for (ll i = 0; i < K; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        cell[a][b] = c;
    }

    for (ll i = 0; i <= R; i++) {
        for (ll j = 0; j <= C; j++) {
            for (ll k = 0; k <= 3; k++) {
                dp[i][j][k] = -L_INF;
            }
        }
    }
    dp[0][1][0] = dp[1][0][0] = 0;

    for (ll i = 1; i <= R; i++) {
        for (ll j = 1; j <= C; j++) {
            for (ll k = 0; k <= 3; k++) {
                if (k > 0) {
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k - 1]);
                }
                dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                if (k > 0) {
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1] + cell[i - 1][j - 1]);
                }
                if (k == 1) {
                    dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][3] + cell[i - 1][j - 1]);
                }
            }
        }
    }

    prints()(dp[R][C][3]);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 356376
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
string qq;
  cin>>qq;
  ll k=qq.size();
  ll q;
  cin>>q;
  
  string s=qq;
  
  ll k1=0;
  ll k2=0;
  ll k3=0;
 for(int i=1;i<=k-1;i++){
    if(s[i]==s[i-1]){
      s[i]='1';
      k1++;
   }
   
  }


string ss=qq+qq;
    for(int i=1;i<=2*k-1;i++){
    if(ss[i]==ss[i-1]){
      ss[i]='1';
      k2++;}
  }
  
  string sss=qq+qq+qq;
    for(int i=1;i<=3*k-1;i++){
    if(sss[i]==sss[i-1]){
      sss[i]='1';
      k3++;}
  }
  
  ll kou=k3-k2;
  
  if(k==1){
    cout<<q/2<<endl;
    return 0;}
  
  for(int i=1;i<=k-1;i++){
      
  if(qq[0]!=qq[i]){
    break;}
    if(i==k-1){
      cout<<k*q/2<<endl;
    
      return 0;}
  }
  
  if(q==1){
    cout<<k1<<endl;
    return 0;}
  if(q==2){
    cout<<k2<<endl;
    return 0;}
  if(q==3){
    cout<<k3<<endl;
    return 0;}
  
  ll ans=0;
  ans=k2+kou*(q-2);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
# 解説AC
include Math

def conv_bnum(b, n)
  return "error" if b < 2
  res = 0
  while n > 0
    res += n % b
    n /= b
  end
  return res
end

n = gets.to_i
s = gets.to_i

if n == s
  puts n + 1
  exit
end

sqrt_n = sqrt(n).floor

2.upto(sqrt_n) do |i|
  if conv_bnum(i, n) == s
    puts i
    exit
  end
end

sqrt_n.downto(1) do |i|
  j = s - i
  next if (n - j) % i != 0

  b = (n - j) / i
  next if b < 2

  str = conv_bnum(b, n)
  if s == str
    puts b
    exit
  end
end

puts -1


Measured memory_bytes: 3836
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long ans = 1;
        
        for(int i=1; i<=N-1; i++){
            ans *= K-1; 
        }
        
        ans = K*ans;
        
        System.out.println(ans);
        
    }
}


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

using namespace std;

const int maxn=1e5+5;
int par[maxn];

int find(int x){
    if(par[x]==-1){
        return x;
    }
    else{
        return par[x]=find(par[x]);
    }
}

void Union(int u,int v){
    u=find(u),v=find(v);
    if(u!=v){
        par[u]=v;
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    int p[n+1];
    for(int i=1;i<=n;i++){
        cin>>p[i];
        par[i]=-1;
    }
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        Union(u,v);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(find(i)==find(p[i])){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define _shwv(v) for (auto _t1 : v) cerr << _t1 << " "; cerr << endl;
#define dbg(x) cerr << #x << ": " << (x) << endl;
#define dbgv(v) cerr << #v << ": "; _shwv(v);
#define dbgm(m) cerr << #m << ":" << endl; for (auto _t2 : m) { _shwv(_t2); }

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

template<typename T> inline void prt(T x) { cout << x << endl; }
template<typename T> inline void getv(T& v) { for (auto& t : v) cin >> t; }
template<typename T> inline int siz(T& x) { return x.size(); }
template<typename T> inline ll pow2(T n) { return 1ll << n; }
template<typename T, typename U> inline int bit(T x, U n) { return x >> n & 1; }
template<typename T, typename U>
inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }


int main() {
    vi n;
    int m = 0;
    while (true) {
        int a; cin >> a;
        if (a == 0) break;
        umax(m, a);
        n.pb(a);
    }
    vi dp(m + 1, 0);
    vi dp2(m + 1, 0);
    repp(i, m) {
        dp[i] = INF;
        dp2[i] = INF;
        repp(j, INF) {
            ll num = j * (j + 1) * (j + 2) / 6;
            if (i < num) break;
            umin(dp[i], dp[i - num] + 1);
            if (num % 2 == 1)
                umin(dp2[i], dp2[i - num] + 1);
        }
    }
    for (auto t : n) {
        cout << dp[t] << " " << dp2[t] << endl;
    }

    return 0;
}



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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int F(int x){
    int n = 0;
    for(int i = 1; i <= x; ++i){
        if (x % i == 0) n++;
    }
    return n;
}

int main(){
    int N;
    cin >> N;
    int a = 1;
    int count = 0;
    while(a <= N){
        if(F(a) == 8) count++;
        a += 2;
    } 
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
lint powint(lint x,lint y){
	if(y==0)return 1;
	if(y%2)return x*powint(x,y-1);
	lint a = powint(x,y/2);
	return a*a;
}
int main(){
	lint n,k;
	cin>>n>>k;
	cout<<k*powint(k-1,n-1)<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)

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

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(i, n) a[i] = a[i] - (i + 1);

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

    int b;
    if (n % 2 == 0) {
        b = a[n / 2 - 1];
    } else {
        b = a[(n +1) / 2-1];
    }

    long long int sum = 0;
    rep(i, n) sum += abs(a[i] - b);

    cout << sum << endl;
}


Measured memory_bytes: 1024
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

main = do
  [n] <- getInts
  print =<< sum <$> map (\[x,y]->y-x+1) <$> replicateM n getInts

-- util
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine


Measured memory_bytes: 1148
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner in = new Scanner(System.in);
        int num1 = in.nextInt();
        int num2 = in.nextInt();
        int ans;
        for (int i = 1;i < num1 * 2 ;i++){
            System.out.print(num2 - (num1 - i));
            if (i != num1 * 2 - 1){
                System.out.print(" ");
            }else{
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

template<class graph>
vector<int> two_colorize(graph g) {
  const int n = g.size();
  vector<int> res(n, -1);
  for (int i = 0; i < n; i++) {
    if (res[i] != -1) continue;
    res[i] = 0;
    queue<int> q;
    q.push(i);
    while (not q.empty()) {
      int u = q.front(); q.pop();
      for (int v : g[u]) {
        if (res[v] == -1) {
          res[v] = 1 - res[u];
          q.push(v);
        } else if (res[v] != 1 - res[u]) {
          return {};
        }
      }
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<vector<int>> G(N);
  rep(i, N - 1) {
    int u, v; cin >> u >> v; u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  auto color = two_colorize(G);
  vector<int> cnt(3);
  vector<vector<int>> v(3);
  for (int i = 1; i <= N; i++) {
    cnt[i % 3]++;
    v[i % 3].push_back(i);
  }
  vector<int> f(2);
  rep(i, N) f[color[i]]++;
  if (f[0] < f[1]) {
    swap(f[0], f[1]);
    rep(i, N) color[i] ^= 1;
  }
  vector<int> ans(N);
  if (f[1] < cnt[2]) {
    cerr << "I" << endl;
    rep(i, N) {
      if (color[i] == 0) {
        if (!v[1].empty()) {
          ans[i] = v[1].back(); v[1].pop_back();
        } else if (!v[2].empty()) {
          ans[i] = v[2].back(); v[2].pop_back();
        } else {
          ans[i] = v[0].back(); v[0].pop_back();
        }
      } else {
        ans[i] = v[0].back(); v[0].pop_back();
      }
    }
  } else {
    cerr << "II" << endl;
    rep(i, N) {
      if (color[i] == 0) {
        if (!v[1].empty()) {
          ans[i] = v[1].back(); v[1].pop_back();
        } else {
          ans[i] = v[0].back(); v[0].pop_back();
        }
      } else {
        if (!v[2].empty()) {
          ans[i] = v[2].back(); v[2].pop_back();
        } else {
          ans[i] = v[0].back(); v[0].pop_back();
        }
      }
    }
  }
  rep(i, N) cout << ans[i] << " \n"[i == N - 1];
}

Measured memory_bytes: 24816
import sys
import numpy as np
input = sys.stdin.readline
N,K = tuple(map(int,input().split()))
h = np.array(input().split(),dtype=np.int32)

dp = np.zeros(N,dtype=np.int32)
for i in range(1,N):
	dp[i] = np.min(np.abs(h[i]-h[max(0,i-K):i]) + dp[max(0,i-K):i])
print(dp[-1])

Measured memory_bytes: 21012