akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using i64 = long long;
using T = std::pair<i64, int>;

class UF {
    int *par;

    public:
    UF(int n) : par(new int[n]) {
        for (int i = 0; i < n; i++) par[i] = i;
    }
    ~UF() { delete[] par; }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) par[x] = y;
    }
};

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<i64> cost(n);
    for (int i = 0; i < n; i++) std::cin >> cost[i];
    UF uft(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        std::cin >> x >> y;
        uft.unite(x, y);
    }

    if (m == n - 1) {
        std::cout << 0 << std::endl;
        return 0;
    }
    if (n < 2 * (n - m - 1)) {
        std::cout << "Impossible" << std::endl;
        return 0;
    }

    std::map<int, std::set<T>> gg;
    std::set<T> cc;
    for (int i = 0; i < n; i++) {
        gg[uft.root(i)].emplace(cost[i], i);
        cc.emplace(cost[i], i);
    }
    i64 ret = 0;
    std::vector<bool> picked(n, false);
    for (auto& ss : gg) {
        ret += ss.second.begin()->first;
        picked[ss.second.begin()->second] = true;
    }

    for (int i = gg.size(); i < 2 * (n - m - 1);) {
        auto el = cc.begin();
        if (!picked[el->second]) {
            ret += el->first;
            i++;
        }
        cc.erase(el);
    }

    std::cout << ret << std::endl;

    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

ll a, b, c, d, e, n, m, k;
string s, t, r;
char c1, c2, c3;

int A[200005];
int B[200005];
int C[200005];

int main() {
	cin >>n;
  	cin >>d;
  	int cnt = 0;
  	while (n--) {
      ll x, y;
      cin >>x>>y;
      if (x*x+y*y<=d*d) cnt++;
      
    }
  	cout <<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

constexpr int CITY_COUNT = 4;
constexpr int ROAD_COUNT = 3;

int main()
{
	array<int, CITY_COUNT> road_per_city;
	road_per_city.fill(0);
	for (int i = 0; i < ROAD_COUNT; ++i)
	{
		int a, b;
		cin >> a >> b;
		++road_per_city[a - 1];
		++road_per_city[b - 1];
	}
	cout << ((*max_element(road_per_city.begin(), road_per_city.end()) < CITY_COUNT - 1) ? "YES" : "NO");
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    int a,b,c;
    cin >> a >> b >> c;
    
//    long long int
    bool flag = false;
    for (int i=1; i<=100; i++) {
        if(a*i % b == c){
            cout << "YES";
            flag = true;
            break;
        }
    }
    if(!flag){
        cout << "NO";
    }
    return 0;
}


Measured memory_bytes: 256
(defun choose2 (n)
  (/ (* n (1- n)) 2))


(defun main ()
  (let* ((n (read))
         (a (make-array n :initial-element 0))
         (cnt (make-array n :initial-element 0))
         (tot 0))
    (dotimes (i n)
      (setf (aref a i) (read))
      (decf (aref a i)))
    (dotimes (i n)
      (incf (aref cnt (aref a i))))
    (dotimes (i n)
      (setf tot (+ tot (choose2 (aref cnt i)))))
    (let ((ans))
      (dotimes (i n)
        (setf ans tot)
        (setf ans (- ans (choose2 (aref cnt (aref a i)))))
        (setf ans (+ ans (choose2 (1- (aref cnt (aref a i))))))
        (format t "~d~%" ans)))))

(main)


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int compress(vector<int> &x)
{
    vector<int> tmp = x;
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
 
    rep(i, x.size()) {
        x[i] = lower_bound(tmp.begin(), tmp.end(), x[i]) - tmp.begin();
    }
 
    return tmp.size();
}

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

    int N; cin >> N;
    vector<int> A(N), B;
    rep(i, N) {
        cin >> A[i];
        A[i]--;
    }
    compress(A);

    B = A;
    sort(ALL(A));

    vector<bool> odd(N);
    rep(i, N) {
        odd[A[i]] = (i&1);
    }

    int ans = 0;
    rep(i, N) {
        if (odd[B[i]] != (i&1)) ans++;
    }
    cout << ans/2 << endl;
}

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

int main(){
   int h, a;
   cin >> h >> a;
   if(h%a != 0) cout << h/a +  1 << endl;
   else if(h%a == 0) cout << h/a << endl;
}

Measured memory_bytes: 3616
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
// using usize = std::size_t;
using usize = isize;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

namespace n91 {

void main_() {
  static constexpr isize INF = std::numeric_limits<isize>::max() / 2_z;
  const std::string s = scan<std::string>();
  const usize n = s.size();

  std::vector<isize> dp1(n + 1_z, -INF), dp2(n + 1_z, -INF);
  dp1[0_z] = 0_z;
  dp2[0_z] = 0_z;

  for (const auto i : rep(0_z, n)) {
    dp1[i + 1_z] = dp2[i] + 1_z;
    if (i >= 1_z && s[i] != s[i - 1_z]) {
      dp1[i + 1_z] = std::max(dp1[i + 1_z], dp1[i] + 1_z);
    }
    if (i >= 1_z) {
      dp2[i + 1_z] = dp1[i - 1_z] + 1_z;
      if (i >= 3_z && s.substr(i - 3_z, 2_z) != s.substr(i - 1_z, 2_z)) {
        dp2[i + 1_z] = std::max(dp2[i + 1_z], dp2[i - 1_z] + 1_z);
      }
    }
  }

  std::cout << std::max(dp1[n], dp2[n]) << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 3716
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int a, b, c, d; cin >> a >> b >> c >> d;
	int turn = 0;
	while (a > 0 and c > 0) {
		if (turn == 0) c -= b;
		else a -= d;
		turn ^= 1;
	}

	if (a <= 0) cout << "No";
	else cout << "Yes";

	return 0;
}

Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main(){
    int A,B,C;
  	cin >> A >> B >> C;
  	
  	if(A+B+C == 17 && A*B*C == 175){
      	cout << "YES" << endl;
    }else{
      	cout << "NO" << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r,g,b,n;
    cin >> r >> g >> b >> n;

    int cnt=0;
    for(int i = 0; r*i <= n; i++) {
        for(int j = 0; r*i+g*j <=n ; j++) {
            if((n-r*i-g*j)%b==0) cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>
using namespace std;

const ll maxn=4e5+500;
const ll inf=1e17+7;
const ll mod=998244353;

ll l[maxn];
ll r[maxn];
multiset<pii> s;
multiset<pii> t;
multiset<pii> :: iterator it,itt;

void ers(ll a){
    s.erase(s.find(mp(l[a],a)));
    t.erase(t.find(mp(r[a],a)));
}
ll fac(ll p,ll a){
    if(l[a]<=p && p<=r[a]){
        return 0;
    }
    if(p<l[a]){
        return l[a]-p;
    }
    return p-r[a];
}
ll beres(ll p,ll a){
    if(l[a]<=p && p<=r[a]){
        return p;
    }
    if(p<l[a]){
        return l[a];
    }
    return r[a];
}
ll find_best(ll p,bool b){
    if(s.size()==0){
        return abs(p);
    }
    if(b){
        it=s.end();
        it--;
        ll v=(*it).S;
        ers(v);
        ll ans=fac(p,v);
        p=beres(p,v);
        return ans+find_best(p,!b);
    }else{
        itt=t.begin();
        ll tt=fac(p,(*itt).S);
        ll v=(*itt).S;
        ers(v);
        ll ans=fac(p,v);
        p=beres(p,v);
        return ans+find_best(p,!b);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>l[i]>>r[i];
        s.insert(mp(l[i],i));
        t.insert(mp(r[i],i));
    }
    ll ans=find_best(0,0);
    for(ll i=0;i<n;i++){
        s.insert(mp(l[i],i));
        t.insert(mp(r[i],i));
    }
    ans=max(ans,find_best(0,1));
    cout<<ans;
}


Measured memory_bytes: 20736
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll dp[h+1][w+1];
  ll line[w+1][w+1];
  for(int i=0;i<=h;i++) for(int j=0;j<=w;j++) dp[i][j]=0;
  dp[0][1]=1;
  for(int i=0;i<=w;i++) for(int j=0;j<=w;j++) line[i][j]=0;

  for(int i=0;i<pow(2,w-1);i++){
    if((i&(i<<1))!=0) continue;

    ll tmp=i;
    for(int j=1;j<=w;j++){
      if(tmp%2){
        line[j][j+1]++;
        line[j+1][j]++;
        tmp/=2;
        j++;
      }else{
        line[j][j]++;
      }
      tmp/=2;
    }
  }

  //for(int i=0;i<=w;i++) for(int j=0;j<=w;j++) cout<<i<<" "<<j<<" "<<line[i][j]<<endl;

  for(int i=0;i<h;i++){
    for(int j=1;j<=w;j++){
      dp[i+1][j]=(dp[i+1][j]+dp[i][j]*line[j][j]%MOD)%MOD;
      if(j>1) dp[i+1][j-1]=(dp[i+1][j-1]+dp[i][j]*line[j][j-1]%MOD)%MOD;
      if(j<w) dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j]*line[j][j+1]%MOD)%MOD;
    }
  }

  //for(int i=0;i<=h;i++) for(int j=0;j<=w;j++) cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;


  cout<<dp[h][k]%MOD<<endl;

  return 0;
}


Measured memory_bytes: 384
$xs = {}

$xs["a"] = gets.chomp
$xs["b"] = gets.chomp
$xs["c"] = gets.chomp

def pull_card(s)
    if $xs[s].size > 0
        atama = $xs[s][0]
        $xs[s].slice!(0)
        pull_card(atama)
    else
        puts s.upcase
        return
    end

end

pull_card("a")



Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

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

		vector<PII> data(n);
		rep(i, n) {
			int id; cin >> id;
			int sec = 0;
			rep(i, 4) {
				int m, s; cin >> m >> s; sec += m * 60 + s;
			}
			data[i] = mp(sec, id);
		}

		sort(all(data));
		cout << data[0].second << endl << data[1].second << endl << data[sz(data) - 2].second << endl;
	}
}


Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {
	
	public static int gcd(int x, int y) {
		if(y == 0 ) {
			return x;
		}
		else {
			return gcd(y, x % y);
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int firstNum = in.nextInt();
		int secondNum = in.nextInt();
		System.out.println(gcd(firstNum, secondNum));
		in.close();
	}
}



Measured memory_bytes: 26116
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>

int solve(int n, std::vector<int>& positions)
{
  std::sort(positions.begin(), positions.end());
  int result = INT_MAX;
  for (int p = positions.front(); p <= positions.back(); ++p) {
    result = std::min(
        result,
        std::accumulate(
            positions.begin(),
            positions.end(),
            0,
            [p](int r, int i) { return r + (i - p) * (i - p);}));
  }
  return result;
}

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> positions(n);
  for (auto& p : positions) {
    std::cin >> p;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, positions) << std::endl;
}


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

const ll INF = 1e10;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	cin >> N >> K;
	vector<int> C(N), G(N);
	for (int i = 0; i < N; i++) {
		cin >> C[i] >> G[i]; G[i]--;
	}
	vector<vector<ll>> dp1(10, vector<ll>(K + 1, -INF));
	for (int i = 0; i < 10; i++) {
		dp1[i][0] = 0;
		for (int j = 0; j < N; j++) if (G[j] == i) {
			for (int k = K - 1; k >= 0; k--) {
				dp1[i][k + 1] = max(dp1[i][k + 1], dp1[i][k] + C[j]);
			}
		}
	}
	vector<vector<ll>> dp2(11, vector<ll>(K + 1, -INF));
	dp2[0][0] = 0;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k + j <= K; k++) {
				dp2[i + 1][k + j] = max(dp2[i + 1][k + j], dp2[i][k] + dp1[i][j] + (j - 1) * j);
			}
		}
	}
	cout << dp2[10][K] << endl;
	return 0;
}



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

string s;
ll n;

int main()
{
	cin>>n;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		s[i]=int(s[i]);
		s[i]+=n;
		if(s[i]>90) s[i]-=26;
		s[i]=char(s[i]);
		cout<<s[i];
	}
	cout<<'\n';
}

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

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

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

    int count = 1;
    int min = P[0];
    for (int i = 1; i < N; i++) {
        if (min > P[i-1]) {
            min = P[i-1];
        }
        if (P[i] <= min) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
bool gao(const int &l, const int &r, const int &t)
{
	if(l == r)
		return ~(a[l] - t) & 1;
	int len = r - l + 1;
	for(int i = l; i < r; i ++)
		if(a[i] != t + 1)
			return gao(i, r - 1, t + 1);
	return (~len & 1) || (~(a[r] - t) & 1);
}
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	cout << (gao(1, n, 0) ? "First" : "Second") << endl;
	
	return 0;
}

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

#define pb push_back
#define lli long long int

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

    int n , k ;
    cin >> n >> k ;

    if (n < 10)
    {
        int ans = 100 * (10 - n) ;
        ans += k ;
        cout << ans << endl ;
    }
    else 
    {
        cout << k << endl ;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//???a?????????
		int a = sc.nextInt();
		//?¨?b?????????
		int b = sc.nextInt();
		//??¢???
		int Area = a * b;
		//??¨????????? ???+?¨?*2
		int periphery = (a + b) * 2; 
		//??¨???
		System.out.println(Area + " " + periphery);
	}
}

Measured memory_bytes: 26140
#C問題　解説
MOD = 10**9 + 7
N = int(input())

#考え方はあってた
#a^N mod p はpow(a,N,p)で高速実装可能
ans = pow(10,N,MOD)
ans -= 2*pow(9,N,MOD)
ans += pow(8,N,MOD)
ans %= MOD

print(ans)

Measured memory_bytes: 61668
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 12;
const int M = 1002;
int h, w, k;
bool white[M][N];
int cur[N];
int add[N];

// cut cols [cuts[i] to cuts[i+1])
int solve(const vector<int>& cuts) {
  memset(cur, 0, sizeof cur);
  int cnt = 0;
  for (int j = 1; j <= w; ++j) {
    memset(add, 0, sizeof add);
    for (int i = 0; i < cuts.size()-1; ++i) {
      const int l = cuts[i];
      const int r = cuts[i+1];
      for (int x = l; x < r; ++x) {
        add[i] += white[j][x];
      }
      if (add[i] > k) return INF;
      if (cur[i] + add[i] > k) {
        memset(cur, 0, sizeof cur);
        cnt++;
      }
    }
    for (int i = 0; i < cuts.size()-1; ++i) {
      cur[i] += add[i];
    }
  }
  return cnt;
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> h >> w >> k;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      char c; cin >> c;
      white[j][i] = c == '1';
    }
  }
  int ans = INF;
  for (int b = 0; b < (1 << (h-1)); ++b) {
    VI cuts = {1};
    for (int i = 0; i < h-1; ++i) {
      if (b & (1 << i)) {
        cuts.push_back(i+2);
      }
    }
    cuts.push_back(h+1);
    ans = min(ans, solve(cuts) + (int)cuts.size() - 2);
  }
  cout << ans << nl;

  return 0;
}



Measured memory_bytes: 256
///参考）https://atcoder.jp/contests/abc126/submissions/5463745
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
// main()
// {
//     vector<int> ans;
//     int n,k;
//     cin>>n>>k;
//     if(k>=1<<n){puts("-1");return 0;}
//     if(n==1)
//     {
//         if(k==0)
//         {
//             puts("0 0 1 1");
//             return 0;
//         }
//         puts("-1");
//         return 0;
//     }
//     for(int i=1;i<1<<n;i++)
//     {
//         if(i==k)continue;
//         ans.emplace_back(i);
//     }
//     int m=ans.size();
//     for(int i=0;i<m;i++)cout<<ans[i]<<' ';
//     cout<<k<<' ';
//     for(int i=m-1;i>=0;i--)cout<<ans[i]<<' ';
//     cout<<k<<endl;
//     return 0;
// }

bool solve(int m, int k, vector<int>& v)
{
    if(m == 1){
        if(k == 0){
            v = vector<int>{0, 0, 1, 1};
            return true;
        }
        else{
            return false;
        }
    }
 
    int n = 1 << m;
    if(n <= k)
        return false;
 
    v.assign(2*n, 0);
    for(int i=0; i<n; ++i)
        v[n-1-i] = v[n-1+i] = i;
 
    replace(v.begin(), v.end(), 0, -1);
    replace(v.begin(), v.end(), k, 0);
    replace(v.begin(), v.end(), -1, k);
 
    return true;
}
 
int main()
{
    int m, k;
    cin >> m >> k;
 
    vector<int> v;
    if(solve(m, k, v)){
        int n = v.size();
        for(int i=0; i<n; ++i)
            cout << v[i] << endl;
    }
    else{
        cout << -1 << endl;
    }
 
    return 0;
}

Measured memory_bytes: 2816
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e5+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/

int main(){
    fast();per(0);
    //get_fact();
    int n;cin>>n;
    cout<<(1<<int(log2(n)));
}



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

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

fn main() {
    let a = read::<usize>();
    let s = read::<String>();

    if a >= 3200 {
        println!("{}", s);
    } else {
        println!("red");
    }
}


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

int main()
{
	string s;
	getline(cin ,s);
	string ans(s);
    transform( s.begin(), s.end(), ans.begin(), ::toupper );

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == ans[i])
		{
			ans[i] = tolower(ans[i]);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3140
/* Filename: ABC049B.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		while (input.hasNext()) {
			int H = input.nextInt();
			int W = input.nextInt();
			String[] C = new String[H];
			
			for(int i = 0; i < H; ++i){
				C[i] = input.next();
				
				System.out.println(C[i]);
				System.out.println(C[i]);
			}
		}
	}

}


Measured memory_bytes: 10452
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t,a;
  long tnow,anow;
  cin >> n >> tnow >> anow;
  for (int i=0;i < n-1;i++) {
    cin >> t >> a;
    if ((tnow-1)/t > (anow-1)/a){
      tnow = ((tnow+t-1)/t)*t;
      anow = ((tnow+t-1)/t)*a;
    }
    else {
      tnow = ((anow+a-1)/a)*t;
      anow = ((anow+a-1)/a)*a;
    }
  }
  cout << tnow + anow <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a=1, b=1;
	while (b < 10) {
		printf("%dx%d=%d\n", b, a, a*b);
		a++;
	if (a > 9) {
			a = 1;
			b++;
		}

	}
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<long, long, greater<long> >::iterator;

// 最大公約数
long GreatestCommonDivisor(long a, long b) {
	/* 自然数 a > b を確認・入替 */
	if (a < b) {
		long tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	/* 最大公約数を出力 */
	return b;
}

//1730
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// long long?
	long long N;
	cin >> N;

	vector<int> vA(N, 0);
	rep(i, N) cin >> vA[i];

//	sort(vA.begin(), vA.end());

	ll gcd = vA[0];
	for (int i = 1; i != vA.size(); ++i) {
		gcd = GreatestCommonDivisor(gcd, vA[i]);
	}

	cout << gcd << endl;
	return 0;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<int>height(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> height[i];
	}
	vector<int>dp(n + 1, 1e9);
	dp[1] = 0;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 1) {
				dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j]));
			}
		}
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int BIG = 2e9 + 55;
const int maxN = 1e5 + 55;

char s[maxN], t[maxN];
int psums[maxN], psumt[maxN];

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

    cin >> (s + 1);
    cin >> (t + 1);

    int n = strlen(s + 1);
    int m = strlen(t + 1);

    for(int i = 1; i <= n; i++){
        //cerr << ((s[i] == 'B') ? 1 : 2) << ' ';
        psums[i] = psums[i - 1] + ((s[i] == 'B') ? 1 : 2);
    }
    //cerr << '\n';

    for(int i = 1; i <= m; i++){
        //cerr << ((t[i] == 'B') ? 1 : 2) << ' ';
        psumt[i] = psumt[i - 1] + ((t[i] == 'B') ? 1 : 2);
    }
    //cerr << '\n';

    int q;  cin >> q;
    while(q--){
        int a, b, x, y; cin >> a >> b >> x >> y;
        int s1 = psums[b] - psums[a - 1];
        int s2 = psumt[y] - psumt[x - 1];
        //cerr << s1 << ' ' << s2 << '\n';
        if((s1 - s2) % 3 == 0){
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }

    return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();
  int K;
  cin >> K;

  for(int i=0;i<N;i++){
    if(s[i] == 'a') continue;
    int n = (int)('z' - s[i] + 1);
    if(n <= K){
      s[i] = 'a';
      K -= n;
    }
  }

  s[N-1] = (char)(s[N-1] + K % 26);

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define INF 1000000000
#define mod 1000000007
#define MAX5 100001

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

// cout << setfill('0') << setw(5) << number < endl;
// while(getline(cin, s)) { .. } | `s` is a string


const int N = 10000000;
// int lp[N+1];
// vector<int> pr;

// void si() {
// 	for (int i=2; i<=N; ++i) {
// 	    if (lp[i] == 0) {
// 	        lp[i] = i;
// 	        pr.push_back (i);
// 	    }
// 	    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
// 	        lp[i * pr[j]] = pr[j];
// 	}
// }

// bool notPrime(int n) {
// 	auto iter = lower_bound(pr.begin(), pr.end(), n);
// 	return !(iter != pr.end() && *iter == n);
// }

// vector<int> pr;

// void sivOld() {
// 	std::vector<bool> primes(N, true);
// 	vector<char> is_prime(N+1, true);
// 	is_prime[0] = is_prime[1] = false;
// 	for (int i = 2; i <= N; i++) {
// 	    if (is_prime[i] && (long long)i * i <= N) {
// 	    	pr.push_back(i);
// 	        for (int j = i * i; j <= N; j += i)
// 	            is_prime[j] = false;
// 	    }
// 	}
// }

// int gcd(int a, int b) {
// 	while (b != 0) {
// 		int old_a = a;
// 		int old_b = b;

// 		a = old_b;
// 		b = old_a % old_b;
// 	}

// 	return a;
// }

// int returnPrime(int num, int a) {
// 	// cout << "?" << endl;
// 	for (int i = 0; i < pr.size(); ++i) {
// 		if (gcd(num, pr[i]) == 1 && gcd(a, pr[i]) == 1)
// 			return pr[i];
// 	}
// 	return -1;
// }


void solve() {
	int n;
	cin >> n;
	n %= 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
		cout << "hon" << endl;
	else if (n == 0 || n == 1 || n == 6 || n == 8 )
		cout << "pon" << endl;
	else
		cout << "bon" << endl;
}

int main(){
	IOS;
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	    // return 0;
	    // cout << "gcd(10, 15) : " << gcd(1, 1) << endl;
	
	int t;
	solve();
}

/*
11 
4 4 
-2 -2 
-3 -4 
-1 3 
2 3 
-4 0 
1 1 
-1 -1 
3 -1 
-4 2 
-2 4
*/

















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

using namespace std;

int a, b, ans, cnt;

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b;
	if(b == 1){
		cout << 0;
		return 0;
	}
	while(ans < b) {
		if(ans == 0) {		
			ans+=a;
		}
		else {		
			ans+=a-1;
		}
		cnt++;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i, 0, n) cin >> v[i];
    ll ans = -INF;
    rep(l, 0, k+1) rep(r, 0, k+1) {
        if (l + r > n) continue;
        if (l + r > k) continue;
        priority_queue<ll, vector<ll>, greater<ll>> pq;
        ll tmp = 0;
        rep(i, 0, l) pq.push(v[i]), tmp += v[i];
        rep(i, 0, r) pq.push(v[n-1-i]), tmp += v[n-1-i];
        rep(i, 0, k-(l+r)) {
            if(!pq.empty() && pq.top() < 0) tmp -= pq.top(), pq.pop();
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

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

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

Measured memory_bytes: 764
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int h, w, n; cin >> h >> w >> n;
  vector<int> line(h, INF);
  REP(i, n) {
    int y, x; cin >> y >> x; --y; --x;
    line[y] = min(line[y], x);
  }
  int right = 1;
  FOR(i, 1, h) {
    if (line[i] < right) {
      cout << i << '\n';
      return 0;
    } else if (line[i] > right) {
      ++right;
    }
  }
  cout << h << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

//ll num[ten52];
//ll num[10][10];
//set<ll> sll;

int main(void)
{
    long long int sum=0,range=0,ceiling;
    double ans=0.0,d;
    long long int m,n,o,i,j,k=0,money;
    long long int a,a1=0,a2=0,a3=0,ar,as,at1;
    char c;
    a=a1=a2=a3=0;
    //vector <int> v;
    //float f,g,h;
    //int c,d,big=0;
    cin>>a1>>a2>>a3;
    if((a1==a2&&a1!=a3)||(a1==a3&&a1!=a2)||(a3==a2&&a3!=a1))
    {
        cout<<"Yes";
    }
    else cout<<"No";
    return 0;
}





Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

def group(num):
    return sum([26**i for i in range(num)])

N = int(input())

group_num = 1
while group(group_num + 1) <= N:
    group_num += 1

kth_place = N - (group(group_num) - 1)
kth_place -= 1
ans = []
for i in range(group_num):
    ans.append(chr(ord('a') + (kth_place % 26)))
    kth_place //= 26
    if not kth_place > 0:
        break

if len(ans) < group_num:
    ans.extend(['a' for i in range(group_num - len(ans))])

ans.reverse()
print(''.join(ans))

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main(){

	ll a, b;
	cin >> a >> b;

	ll maxi = (ll)(sqrt(max(a, b)) + 1);

	vector<ll> prime;
	vector<bool> used(maxi+1, false);
	for(ll i = 2; i < maxi; ++i){
		if(!used[i]) prime.push_back(i);
		for(ll j = 1; i * j < maxi; ++j){
			used[i * j] = true;
		}
	}
	ll ans = 1;
	rep(i, prime.size()){
		if(a % prime[i] == 0 && b % prime[i] == 0) ans++;
		while(a % prime[i] == 0) a /= prime[i];
		while(b % prime[i] == 0) b /= prime[i];
	}
	if(a != 1 && a == b) ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1528
N = int(input())
S = input()

ans = 0

for i in range(10):
    a = S.find(str(i))
    if -1 == a:
        continue
    for j in range(10):
        b = S.find(str(j), a + 1)
        if -1 == b:
            continue
        for k in range(10):
            c = S.find(str(k), b + 1)
            if -1 == c:
                continue
            ans += 1
            # print(''.join(map(str, [i, j, k])))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using vll = vector<ll>;
    using vvll = vector<vll>;
    using vvvll = vector<vvll>;
    using vs = vector<string>;
    #define rep(i, n) for (int i = 0; i < (n); i++)
    #define repb(i, a, b) for (int i = (a); i < (b); i++)
    #define ALL(a) (a).begin(),(a).end()
    #define PRINT(V) for(auto v:(V))cout<<v<<" "<<endl
    inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
    const ll MOD = 1000000007;
     
    int main()
    {
        int N, Q;
        cin >> N >> Q;
        string S;
        cin >> S;
        vi acpos;
        rep(i, N-1)
        {
            if(S[i] == 'A' && S[i+1] == 'C')
            {
                acpos.push_back(i);
            }
        }
        acpos.push_back(1000000);
        vi l(Q), r(Q);
        rep(i, Q)
        {
            cin >> l[i] >> r[i];
        }
        rep(i, Q)
        {
            vi::iterator lc = lower_bound(ALL(acpos), l[i]-1);
            vi::iterator rc = lower_bound(ALL(acpos), r[i]-2);
            size_t lin = distance(acpos.begin(), lc);
            size_t rin = distance(acpos.begin(), rc);
            if(*rc == r[i]-2)
            {
                cout << rin - lin + 1 << endl;
            }
            else
            {
                cout << rin - lin << endl;
            }
        }
    }

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int n;
  cin >> n;
  if(n == 1)
    cout <<"Hello World";
  else {
    int a, b;
    cin >> a >> b;
    cout << a + b;
  }
}


Measured memory_bytes: 256
// #pragma GCC target ("arch=ivybridge")
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, m, n) for (int i = (m); i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repr2(i, m, n) for (int i = (n)-1; i >= (m); i--)
#define all(x) x.beign(), x.end()

#define MaxH 10005
int dp[MaxH][5];
int no[MaxH];
int h, n;

signed main() {
  cin.tie(0); ios_base::sync_with_stdio(0);

  cin >> h >> n;
  rep(_, n) {
    int x, y; cin >> x >> y;
    no[y] |= 1 << x;
  }

  int on[] = {0, 3, 6, 12, 15};
  int v[] = {0, 1, 1, 1, 2};
  rep(r, h-1) {
    rep(i, 5) {
      int ng = on[i] | no[r];
      rep(j, 5)
        if ((ng & on[j]) == 0 && (no[r+1] & on[j]) == 0)
          dp[r+1][j] = max(dp[r+1][j], dp[r][i] + v[j]);
    }
  }

  cout << *max_element(dp[h-1], dp[h]) << "\n";
}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N,M,C;
    cin >> N >> M>>C;
    vector<ll> num(M);
    rep(i,M)cin >> num[i];
    vector<vector<ll>> sause(N,vector<ll>(M));
    ll ans = 0;
    rep(i,N)
    rep(j,M)cin >> sause[i][j];
    rep(i,N){
        ll cnt = 0;
        rep(j,M){
            cnt += sause[i][j] * num[j];
        }
        if(cnt + C > 0)ans++;
    }
    cout << ans << endl;
}

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

int main(){
    int A;
    int B;
    int C;
    int X;

    cin >> A >> B >> C >> X;

    int counter = 0;
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                int sum = 500*i + 100*j + 50*k;
                if(sum == X)
                    ++counter;
            }
        }
    }

    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 256
N,K,Q=map(int,input().split())
A=[int(input()) for i in range(Q)]

points_list=[K-Q for j in range(N)]

for k in range(Q):
    points_list[A[k]-1]+=1

for l in range(N):
    if points_list[l]>0:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 11792
#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(){
  ll n;
  int k;
  cin>>n>>k;
  int ans=0;
  while(n>0){
    n/=k;
    ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n, c = gets.split.map(&:to_i)

d = c.times.map {gets.split.map(&:to_i)}
cc = n.times.map {gets.split.map(&:to_i)}

ary = Array.new(3) {Array.new(c, 0)}
(0...n).to_a.repeated_permutation(2) {|i,j| ary[(i+j) % 3][cc[i][j]-1] += 1}

ans = 1 << 40
(0...c).to_a.permutation(3) do |s,t,u|
    sum = 0
    c.times {|i| sum += d[i][s] * ary[0][i] + d[i][t] * ary[1][i] + d[i][u] * ary[2][i]}
    ans = sum if ans > sum
end

p ans

Measured memory_bytes: 4348
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int a,b,c;cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES"<<endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  vector<int> a(5);
  rep(i,5){
    cin >> a.at(i);
  }
  int k;
  bool flag = false;
  cin >> k;
  if(a.at(4) - a.at(0) > k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  
    
  
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int total =0;
    for(int i=1; i<=N; i++){
      int n=i;
      int sum =0;
      while(n>0){
        sum += n%10;
        n = n/10;
      }
      if(A <=sum && sum <=B){
        total +=i;
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(a>=k)cout<<k<<endl;
    else if(a+b>=k)cout<<a<<endl;
    else{
        ll buf=k-a-b;
        cout<<a-buf<<endl;
    }
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e9;
const int Bmax=2e5;
const int Nd=61;

struct Edge {int to, id;};
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1){
  int k=1;
  rep(i,g[v].size()){
    int u =g[v][i].to, ei=g[v][i].id;
    if(u==p) continue;
    if(k==c) k++;
    ans[ei]=k; k++;
    dfs(u,ans[ei],v);
  }
}

int main(){
  int n ;cin>>n;
  g.resize(n);
  ans.resize(n-1);
  rep(i,n-1){
    int a,b; cin>>a>>b; a--; b--;
    g[a].push_back((Edge){b,i});
    g[b].push_back((Edge){a,i});
  }

  dfs(0);
  int mx=0;
  rep(i,n) mx=max(mx,int(g[i].size()));
  cout<<mx<<endl;

  rep(i,n-1) cout<<ans[i]<<endl;

}


Measured memory_bytes: 10984