akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};


vector<pair<ll,ll>> prime_factorize(ll N){
    vector<pair<ll,ll>> ret;
    for(ll a = 2; a * a <= N; a++){
        if(N % a != 0) continue;
        ll ex = 0;
        while(N % a == 0){
            ex++;
            N /= a;
        }
        ret.push_back({a, ex});
    }
    if(N != 1) ret.push_back({N, 1});
    return ret;
}

constexpr ll mod = 1e9+7;
#define NMAX 1000010
ll fac[NMAX];
ll inv[NMAX];

ll mod_pow(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}

ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod-2, mod);
}

int main(){
    ll N;
    cin >> N;
    VL A(N);
    rep(i, 0, N) cin >> A[i];

    map<ll,ll> primes;
    VVP rec(N);
    rep(i, 0, N){
        auto t = prime_factorize(A[i]);
        rec[i] = t;
        for(auto r : t){
            if(primes.count(r.first) == 0) primes[r.first] = r.second;
            else primes[r.first] = max(primes[r.first], r.second);
        }
    }

    ll lcm = 1;
    for(auto p : primes){
        lcm *= mod_pow(p.first, p.second, mod);
        lcm %= mod;
    }

    ll ans = 0;
    rep(i, 0, N){
        ans += lcm * mod_inv(A[i], mod);
        ans %= mod;
    }

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

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    // Your code here!
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ll dp[n][n];
    for(ll i=0;i<n;i++)
    {
        dp[i][i]=a[i];
    }
    for(ll i=0;i<n-1;i++)
    {
        dp[i][i+1]=max(a[i],a[i+1]);
    }
    for(ll len=3;len<=n;len++)
    {
        for(ll i=0;i<=n-len;i++)
        {
            ll j=i+len-1;
            ll q1=a[i]+min(dp[i+2][j],dp[i+1][j-1]);
            ll q2=a[j]+min(dp[i][j-2],dp[i+1][j-1]);
            dp[i][j]=max(q1,q2);
        }
    }
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        sum+=a[i];
    }
    cout<<2*dp[0][n-1]-sum;
    return 0;
}


Measured memory_bytes: 70400
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string s; int w;
	cin>>s>>w;
	string ans;
	rep(i,s.size()){
		if(i%w == 0)ans.push_back(s[i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll N;
vector<ll> G[201010];
vector<ll> H[201010];

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

ll dfs(ll now, ll par){
	ll res = 1;
	REP(i, G[now].size()){
		ll next = G[now][i];
		if(next == par) continue;
		ll tmp =  dfs(next, now);
		res += tmp;
		H[now].push_back(tmp);
		H[next].push_back(N-tmp);
	}
	//dump(now)
	//dump(res)
	return res;
}

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

    cin >> N;

    REP(i, N-1){
    	ll A, B;
    	cin >> A >> B;
    	A--, B--;
    	G[A].push_back(B);
    	G[B].push_back(A);
    }

    dfs(0, -1);
    /*
    REP(i, N){
    	REP(j, H[i].size()){
    		cout << H[i][j] << " "; 
    	}
    	cout << endl;
    }
    */

    ll res = 0;

    ll i2 = modinv(2, mod);
    REP(i, N){
    	ll M = H[i].size();
    	ll tmp = 1;
    	tmp *= i2;
    	tmp %= mod;
    	vector<ll> p(M);
    	REP(j, M){
    		p[j] = 1 - powLL(i2, H[i][j]);
    		p[j] += mod;
    		p[j] %= mod;
    	}
    	ll kake = 1;

    	ll prod = 1;
    	REP(j, H[i].size()){
    		prod *= (1-p[j]+mod)%mod;
    		prod %= mod;
    	}

    	ll one = 0;
    	REP(j, H[i].size()){
    		ll kore = prod * modinv((1-p[j]+mod)%mod, mod);
    		kore %= mod;
    		kore *= p[j];
    		one += kore;
    		one %= mod;
    	}

    	kake -= prod;
    	kake += mod;
    	kake %= mod;
    	kake -= one;
    	kake += mod;
    	kake %= mod;

    	tmp *= kake;
    	tmp %= mod;

    	if(M == 1) tmp = 0;
    	res += tmp;
    	res %= mod;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 38272
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool graph[101][101];
bool visit[101];
vector<ll> to[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = modpow(2, n, MOD) - 1;
	ll res = 1;
	COMinit();
	for (ll i = n - a + 1;i <= n;++i) {
		res *= i;
		res = res % MOD;
	}
	res *= finv[a];
	res = res % MOD;
	ll res2 = 1;
	COMinit();
	for (ll i = n - b + 1;i <= n;++i) {
		res2 *= i;
		res2 = res2 % MOD;
	}
	res2 *= finv[b];
	res2 = res2 % MOD;
	res += res2;
	res = res % MOD;
	ans -= res;
	ans = ans % MOD;
	if (ans < 0)ans += MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 122240
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int a, b, h; cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  cin >> n;
  ll aa[n];
  ll ans = INF;
  rep(i,n) cin >> aa[i];
  rep(i,n){
    if(aa[i]%2 != 0) ans = 0;
    ll j = aa[i];
    ll ok = 1;
    while(j){
      j/=2;
      if(j%2!=0)break;
      ok++;
    }
    chmin(ans,ok);
  }
  pri(ans);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */
int compare4(const void *a, const void *b) {
	int aa = *((int *)a);
	int bb = *((int *)b);
	if (aa > bb) return 1;
	if (aa < bb) return -1;
	return 0;
}
/* int型配列の昇順sort */
void qsort4(int *base, int count) {
	/* void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); */
	qsort((void *)base, count, sizeof(int), compare4);
}

int d[100000];
int main()
{
	int		i, n, l,h,ans = 0;
	
	scanf("%d", &n);
	for(i=1;i<=n;i++) {
		scanf("%d", &d[i]);
	}
	qsort4( (int *)&d[1], n);
	l = d[n/2];
	h = d[n/2+1];
	ans = h-l;
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 892
from collections import defaultdict

MOD = 1000000007

def primes(x):
    n = x
    for i in range(2, n + 1):
        if x == 1:
            return
        while x % i == 0:
            x //= i
            counter[i] += 1


if __name__ == '__main__':
    n = int(input())
    counter = defaultdict(int)
    for i in range(2, n + 1):
        primes(i)

    ans = 1
    for x in counter.values():
        ans *= x + 1
        ans %= MOD

    print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;cin >>n>>k;
    n--;k--;
    V a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    int ans=(n-1)/k+1;
    cout <<ans <<"\n";
}


Measured memory_bytes: 3660
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))

i = 0
length = []
while(i < n):
    if(i == (n-1)):
        length.append(abs((k-a[i]) + a[0]))
    else:
        length.append(abs(a[i+1]-a[i]))
    i += 1

length_sort = sorted(length)
min = sum(length_sort[:n-1])

print(min)

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;
	int n; cin >> n;
	vector<int> a(n); cin >> a;

	int ans = 0;
	for(int i=0; i<n; i++){
		if(i%2==0&&a[i]%2==1) ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int M, N, P[10000], C, E, DP[10001], ans = 0;

int main(){
	cin >> M >> N;
	for (int i = 0; i != M; ++i)
		cin >> P[i];
	sort(P, P + M, greater<int>());
	for (int i = 1; i != M; ++i)
		P[i] += P[i - 1];
	for (int i = 0; i != M + 1; ++i)
		DP[i] = -0xe869120;
	DP[0] = 0;
	for (int i = 0; i != N; ++i) {
		cin >> C >> E;
		for (int j = M; j != -1; --j) {
			DP[min(M, j + C)] = max(DP[min(M, j + C)], DP[j] - E);
		}
	}
	for (int i = 1; i != M + 1; ++i) {
		ans = max(ans, P[i - 1] + DP[i]);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3244
#include <iostream>

#define MAX_SIZE (3000)

using namespace std;

void swap (int* x, int* y);

int main()
{   
    int* x = new int[MAX_SIZE + 1];
    int* y = new int[MAX_SIZE + 1];
    int  size;

    for (int i = 0; i < MAX_SIZE + 1; i++) {
         do {
             cin >> x[i] >> y[i];
         } while ((x[i] < 0 || x[i] > 10000) || (y[i] < 0 || y[i] > 10000));

         if (x[i] == 0 && y[i] == 0) {
             size = i;
	     break;
         }        
    }
       
    for (int i = 0; i < size; i++) {
         if (x[i] > y[i]) {
             swap(&x[i], &y[i]);
         }

         cout << x[i] << " " << y[i] << endl;
    }

    delete[] x;
    delete[] y;

    return (0);
}

void swap(int* x, int* y)
{
     int temp = *x;
     *x = *y;
     *y = temp;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

struct Edge {
	int to;

	Edge() {}
	Edge(int to):to(to) {}
};

struct Graph : vector< vector<Edge> > {
	int numV;
	vector<bool> visited;
	vector<int> match;

	Graph(){}

	void init(int numV_) {
		numV = numV_;
		assign(numV, vector<Edge>());
	}

	void init() {
		assign(numV, vector<Edge>());
	}

	void addUndirectedEdge(int from, int to) {
		at(from).push_back(Edge(to));
		at(to).push_back(Edge(from));
	}
};

Graph G;

bool augment(Graph& graph, int v) {
	graph.visited[v] = true;
	for (int i = 0; i < (int)graph[v].size(); ++i) {
		int u = graph[v][i].to, w = graph.match[u];
		if (w < 0 || (!graph.visited[w] && augment(graph, w))) {
			graph.match[v] = u;
			graph.match[u] = v;
			return true;
		}
	}
	return false;
}

int calcBipartiteMatching(Graph& graph) {
	graph.match.assign(graph.numV, -1);
	graph.visited.resize(graph.numV);
	for (int v = 0; v < graph.numV; ++v) if (graph.match[v] < 0) {
		fill(graph.visited.begin(), graph.visited.end(), false);
		augment(graph, v);
	}
	return (graph.numV - count(graph.match.begin(), graph.match.end(), -1)) / 2;
}

const int MAX_N = 100;
const int MAX_Q = 1000;
const int INF = (int)(1.05e9); 

int N, M, L;
int mat[MAX_N][MAX_N];
int ps[MAX_Q], ts[MAX_Q];

template<typename numType>
inline bool updateMin(numType& old, const numType& test) {
	if (old > test) {
		old = test;
		return true;
	}
	return false;
}

bool init() {
	scanf("%d%d%d", &N, &M, &L);
	for (int i = 0; i < N; ++i) {
		fill(mat[i], mat[i] + N, INF);
	}

	for (int _ = 0; _ < M; ++_) {
		int from, to, cost;
		scanf("%d%d%d", &from, &to, &cost);
		updateMin(mat[from][to], cost);
		updateMin(mat[to][from], cost);
	}

	for (int i = 0; i < L; ++i) {
		scanf("%d%d", ps + i, ts + i);
	}

	return N > 0;
}

int solve() {
	G.init(2*L);
	for (int k = 0; k < N; ++k) {
		mat[k][k] = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				updateMin(mat[i][j], mat[i][k] + mat[k][j]);
			}
		}
	}

	for (int i = 0; i < L; ++i) {
		for (int j = 0; j < L; ++j) if (i != j) {
			if (ts[i] + mat[ps[i]][ps[j]] <= ts[j]) {
				G.addUndirectedEdge(2*i, 2*j+1);
			}
		}
	}

	return L - calcBipartiteMatching(G);
}

int main() {
	for (;init();) {
		printf("%d\n", solve());
	}
	return 0;
}

Measured memory_bytes: 6568
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  rep(i, N) {
    cin >> T[i];
  }

  sort(all(T));
  int ans = 0;
  rep(i, N) {
    ans++;
    int lim = T[i] + K;
    int cnt = 1;
    while (cnt < C && i + 1 < N && T[i + 1] <= lim) {
      cnt++;
      i++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
/*
	Author: Hamza Hasbi
	Copyrights: "h.hamza" ==> "www.hamzahasbi.me"
	Date: 20/08/2017 12:55:20
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define uld unsigned long double
#define ui unsigned int
#define ud unsigned double
#define uf unsigned float
#define pi 2*acos(0.0)
#define module cin.ignore()
#define rep(i,l,r) for(auto i=l;i<=r;i++)
#define range(x,y) for(auto x:y)
//inline long longlcm(ll a,ll b) {return a*b/__gcd(a,b);}
//inline long long gcd(ll a,ll b) {return 1LL*b == 0 ? a : gcd(1LL*b, a*1LL % b*1LL);}
using namespace std;

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(abs(x-a)>=abs(x-b)) puts("B");
	else puts("A");
	
	
	return 0;
}


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

int findSumOfDigits(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans =0;
    for(int i=1;i<=n;i++){
        if(findSumOfDigits(i)>=a && findSumOfDigits(i)<=b)ans+= i;
    }
    cout << ans << endl;
    return 0;
}

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

const int INF = 100000;
int main()
{
  int dp[1005][1005];
  int h, w;
  cin >> h >> w;

  for (int i = 0; i < 1005; i++)
  {
    for (int j = 0; j < 1005; j++)
    {
      dp[i][j] = INF;
    }
  }

  queue<pair<int, int>> que;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      char ch;
      cin >> ch;
      if (ch == '#')
      {
        dp[i][j] = 0;
        que.push(pair<int, int>(i, j));
      }
    }
  }

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

  int res = 0;
  while (que.size())
  {
    pair<int, int> p = que.front();
    que.pop();

    for (int i = 0; i < 4; i++)
    {
      int x = p.first + dx[i];
      int y = p.second + dy[i];

      if (0 <= x && x < h && 0 <= y && y < w && dp[x][y] == INF)
      {
        dp[x][y] = dp[p.first][p.second] + 1;
        res = dp[x][y];
        que.push(pair<int, int>(x, y));
      }
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 12432
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,c;
    cin>>n>>c;
    ll d[c][c],a[n][n];
    for(int i=0;i<c;i++)for(int j=0;j<c;j++)cin>>d[i][j];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
            a[i][j]--;
        }
    }
    ll b[3][c];
    for(int i=0;i<3;i++){
        for(int j=0;j<c;j++){
            b[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            b[(i+j)%3][a[i][j]]++;
        }
    }
    ll ans=1e18,sum;
    for(int i=0;i<c;i++){
        for(int j=0;j<c;j++){
            if(i==j)continue;
            for(int k=0;k<c;k++){
                if(k==i||k==j)continue;
                sum=0;
                for(int m=0;m<c;m++){
                    sum+=b[0][m]*d[m][i]+b[1][m]*d[m][j]+b[2][m]*d[m][k];
                }
                ans=min(ans,sum);
            }
        }
    }
    cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pl;


int main(){
  int n,k,q;
  cin>>n>>k>>q;

  vector<int> s(n,k-q);
  int i;
  for(i=0;i<q;i++){
    int a;
    cin>>a;
    s[a-1]++;
  }

  for(i=0;i<n;i++){
    if(s[i]>0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
  }


}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	int res=0;
	for(int i=0;i<n;i++) res+=a[i];
	if(res%10==0){
		for(int i=0;i<n;i++) if(a[i]%10!=0){
			cout<<res-a[i]<<endl;
			return 0;
		}
		cout<<0<<endl;
	}
	else cout<<res<<endl;
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}

int n,m;
int max_val = 20;
vector<int> p(max_val);
vector<int> k_val(max_val);
vector<vector<int>> s(max_val, vector<int>(max_val));
vector<int> swit(max_val, 0);
int ans;

void dfs(int now){
  if (n == now){
    // check whether all right is ligtend
    int on_light_num = 0;
    REP(i, m){
      int on_swi = 0;
      int k = k_val[i];
      REP(j, k){
        int index = s[i][j];
        if (swit[index] == 1) on_swi++;
      }
      if (on_swi % 2 == p[i]) on_light_num++;
    }
    if (on_light_num == m) ans++;
  return;
  }

  else{
    for (int i=0; i<=1; i++){
      swit[now+1] = i;
    dfs(now+1);
    }}
}


int main(void){
  ios::sync_with_stdio(false);
  cin >> n >> m;
  REP(i, m){
    cin >> k_val[i];
    REP(j, k_val[i]){
      cin >> s[i][j];
    }
  }
  REP(i, m) cin >> p[i];
  dfs(0);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 888
#include<iostream>
#include<queue>
#include<ctype.h>
#include<cstdio>
using namespace std;
int H,W,sum,count;
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
struct node
{
	int x,y;
	int step;
	int color;
	char data;
}*map,now,next;
void BFS(int x,int y)
{
	queue<node>q;
	q.push(map[x*W+y]);
	while(!q.empty())
	{
		now=q.front();
		q.pop();
		for(int i=0;i<4;i++)
		{
			next.x=now.x+dir[i][0];
			next.y=now.y+dir[i][1];
			if(next.x>=0&&next.y>=0&&next.x<H&&next.y<W&&map[next.x*W+next.y].data!='X'&&map[next.x*W+next.y].color<count)
			{
				map[next.x*W+next.y].step=now.step+1;
				if(int(map[next.x*W+next.y].data-'0')==count)
				{
					count++;
					map[next.x*W+next.y].data='.';
					if(count>sum)
					{
						cout<<map[next.x*W+next.y].step<<endl;
						return;
					}
					map[next.x*W+next.y].color=count;
					BFS(next.x,next.y);
				}
				else
				{
					map[next.x*W+next.y].color=count;
					q.push(map[next.x*W+next.y]);
				}
				if(count>sum)return;
			}
		}
	}
}
int main()
{
	//freopen("01.txt","r",stdin);
	while(cin>>H>>W>>sum)
	{
		map=new node[H*W];
		for(int i=0;i<H;i++)
		{
			for(int j=0;j<W;j++)
			{
				cin>>map[i*W+j].data;
				map[i*W+j].x=i;
				map[i*W+j].y=j;
				map[i*W+j].color=0;
				if(map[i*W+j].data=='S')
				{
					now.x=i;
					now.y=j;
				}
			}
		}
		count=1;
		map[now.x*W+now.y].step=0;
		map[now.x*W+now.y].color=1;
		map[now.x*W+now.y].data='.';
		BFS(now.x,now.y);
	}
	return 0;
}

Measured memory_bytes: 20752
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int num = 0;
		try (Scanner sc = new Scanner(System.in)) {
			num = sc.nextInt();
		}
		System.out.println(calcCubic(num));
	}

	/**
	 * @param num
	 * @return
	 */
	private static int calcCubic(int num) {
		return (int) Math.pow(num, 3);
	}

}

Measured memory_bytes: 26048
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  vector<int> prime;
  set<int> primeset;
  prime.push_back(2);
  prime.push_back(3);
  primeset.insert(2);
  primeset.insert(3);
  for(int n=5;n<=100000;n+=2){
    double root = sqrt(n);
    int size = prime.size();
    bool is_prime = true;
    for(int i=1;i<size;i++){
      if(prime.at(i) > root) break;
      if(n % prime.at(i) == 0){
        is_prime = false;
        break;
      }
    }
    if(is_prime){
      prime.push_back(n);
      primeset.insert(n);
    }
  }
  vector<int> like2017;
  int s = prime.size();
  for(int i=1;i<s;i++){
    int tmp = (prime.at(i)+1)/2;
    if(primeset.count(tmp)){
      like2017.push_back(prime.at(i));
    }
  }
  s = like2017.size();
  int id = 0;
  vector<int> num(100000,s);
  for(int i=0;i<100000;i++){
    if(id >= s) break;
    if(i == like2017.at(id)){
      id++;
      num.at(i) = id;
    }else{
      num.at(i) = id;
    }
  }
  int q;
  cin >> q;
  int l,r;
  rep(i,q){
    cin >> l >> r;
    cout << num.at(r) - num.at(l-1) << endl;
  }
}


Measured memory_bytes: 1536
d={}
def addT(d,a,b):
    if a in d:
        d[a].add(b)
    else:
        d[a]={b}
for _ in range(3):
    a,b = input().split()
    a,b=int(a),int(b)

    addT(d,a,b)
    addT(d,b,a)

for a in d:
    if len(d[a]) == 3:
        print("NO")
        exit()
print("YES")


Measured memory_bytes: 3064
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,X=rl()

p = [0]*(N+1)
l = [0]*(N+1)
p[0]=1
l[0]=1

for i in range(1,N+1):
    p[i]=2*p[i-1]+1
    l[i]=2*l[i-1]+3


ans = 0

for i in range(N-1,-1,-1):
    if X==1:
        X -= 1
        break
    elif X <= 1+l[i]:
        X -= 1
        if i == 0:
            ans += 1
            break
    elif X == 1+l[i]+1:
        X -= 1+l[i]+1
        ans += p[i]+1
        break
    elif X <= 2+2*l[i]:
        X -= 2+l[i]
        ans += p[i]+1
        if i == 0:
            ans += 1
            break
    else:
        X -= 3+2*l[i]
        ans += 2*p[i]+1
        break
print(ans)

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

int vecx[4]={0,1,0,-1},vecy[4]={1,0,-1,0};

void explore(string atlas[12],int vstd[12][12],int i,int j){
    queue<pair<int,int> > bfs;
    bfs.push(make_pair(i,j));
    while(!bfs.empty()){
        int x=bfs.front().first,y=bfs.front().second;
        vstd[x][y]=1;
        for(int k=0; k<4; k++){
            int nextx=x+vecx[k],nexty=y+vecy[k];
            if(nextx<0||nextx>11||nexty<0||nexty>11)continue;
            if(atlas[x+vecx[k]][y+vecy[k]]=='1'&&vstd[x+vecx[k]][y+vecy[k]]==0){
                bfs.push(make_pair(x+vecx[k],y+vecy[k]));
            }
        }
        bfs.pop();
        //cout<<x<<' '<<y<<endl;
    }
}

int main(){
    string atlas[12];
    int vstd[12][12],cnt;
    while(cin>>atlas[0],!cin.eof()){
        cnt=0;
        for(int i=1; i<12; i++){
            cin>>atlas[i];
        }
        fill(vstd[0],vstd[12],0);
        for(int i=0; i<12; i++){
            for(int j=0; j<12; j++){
                if(vstd[i][j]==0&&atlas[i][j]=='1'){
                    explore(atlas,vstd,i,j);
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 8764
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//WATLEPIYO
vector<vector<int>>go;
pair<llint,llint> solve(int ter,int per){
	llint w=1,b=1;
	for(auto it:go[ter]){
		if(it==per){continue;}
		auto r=solve(it,ter);
		w*=r.fir;b*=r.sec;w%=mod;b%=mod;
	}
	return mp((w+b)%mod,w);
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i,n;cin>>n;go.res(n);
	for(i=0;i<n-1;i++){
		int x,y;cin>>x>>y;x--;y--;
		go[x].pub(y);
		go[y].pub(x);
	}
	cout<<solve(0,-1).fir<<endl;
	return 0;
}


Measured memory_bytes: 11264
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    ll N,K;
    cin>>N>>K;
    vector<int> A(N);
    REP(i,N){
        cin>>A[i];
    }
    //入力部
    ll count=0;
    ll backcount=0;
    REP(i,N-1){
        REPi(j,i+1,N){
            if(A[i]>A[j]){
                count+=1;
            }else if(A[i]<A[j]){
                backcount+=1;
            }
        }
    }
    ll ans1,ans2,ans3;
    ans1=(K*(K-1)/2)%int(1e9+7);
    ans2=(count+backcount)%int(1e9+7);
    ans3=(count*K)%int(1e9+7);
    ll ans;
    ans=(ans1*ans2+ans3)%int(1e9+7);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int count = 0;
    for (int i = a; i <= b; i++) {
      int[] array = new int[5];
      array[0] = i % 10;
      array[1] = i / 10 % 10;
      array[2] = i / 100 % 10;
      array[3] = i / 1000 % 10;
      array[4] = i / 10000 % 10;
      if (array[0] == array[4] && array[1] == array[3]) {
        count++;
      }
    }
    System.out.println(count);
  }
}

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

int main () {
  int N;
  cin >> N;
  vector<int> d(N);

  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }

  sort(d.begin(), d.end());
  int before = 0, stage = 0;
  for (int i = 0; i < N; i++) {
    if (before < d.at(i)) {
      stage++;
      before = d.at(i);
    }
  }
  cout << stage << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;



ll k, q;

int main(){
	cin >> k >> q;
	
	vector<ll> d(k);
	for ( int i = 0; i < k; i++ ){
		cin >> d[i];
	}
	
	/*
		数列 ai は単調非減少、aiの差分の周期はk
		
		for ( qi ){
			数列 d' = Σd%mi  を計算する
			  この数列は1歩でmiの整数倍を2回またぐことはない
			
			result = n - (d%mi=0 となる個数) - (d'がmiをまたぐ回数)
		}
		
	*/
	
	{
		vector<ll> acc(k+1);
		vector<ll> acc0(k+1);
		for ( int i = 0; i < q; i++ ){
			ll n, x, m;
			cin >> n >> x >> m;
			
			ll dsum = 0;
			ll zsum = 0;
			for ( int j = 0; j < k; j++ ){
				acc[j] = dsum;
				acc0[j] = zsum;
				dsum = dsum + d[j]%m;
				zsum = zsum + (d[j]%m==0 ? 1 : 0);
			}
			acc[k] = dsum;
			acc0[k] = zsum;
			
			
			ll repeated = (n-1)/k;
			ll remain = (n-1)%k;
			ll zero_count = repeated*acc0[k] + acc0[remain];
			ll amax = x + repeated*acc[k] + acc[remain];
			
			//cout << endl;
			//cout << "n=" << n << endl;
			//cout << "zero count = " << repeated*acc0[k] << "+" << acc0[remain] << endl;
			//cout << "amax=" << (x+repeated*acc[k]+acc[remain])  << endl;
			
			cout << (n-1) - zero_count - (amax/m - x/m) << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef pair<lint, pii> plp;
typedef complex<double> xy_t;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

const lint mod = 1e9+7;
const lint INF = mod*mod;
const int MAX = 100010;

int n, m;
vector<int> G[MAX];
vector<pii> ans;
int ord[MAX], deg[MAX];

void dfs1(int v, int pv, int &idx){
    ord[v]=idx++;
    for(int nv: G[v])if(nv!=pv){
        if(ord[nv]>=0 && ord[nv]<ord[v]){
            ans.emplace_back(v, nv);
            deg[v]^=1;
        }
        else if(ord[nv]<0) dfs1(nv, v, idx);
    }
}

void dfs2(int v, int pv){
    ord[v]=0;
    for(int nv: G[v])if(ord[nv]<0) dfs2(nv, v);
    if(pv<0) return;
    if(deg[v]){
        ans.emplace_back(v, pv);
        deg[v]^=1;
    }
    else{
        ans.emplace_back(pv, v);
        deg[pv]^=1;
    }
}

int main(){
    scanf("%d%d", &n, &m);
    if(m%2){
        printf("-1\n");
        return 0;
    }
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, n){
        ord[i]=-1;
        deg[i]=0;
    }
    int idx=0;
    dfs1(0, -1, idx);
    rep(i, n) ord[i]=-1;
    dfs2(0, -1);
    for(pii e: ans) printf("%d %d\n", e.fi+1, e.se+1);
}

Measured memory_bytes: 16372
N=int(input())
A=list(map(int, input().split()))

flag = 1
for i in range(len(A)):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 and A[i] % 5 != 0:
      flag = 0
      break
print(['DENIED', 'APPROVED'][flag])

Measured memory_bytes: 8988
#include <iostream>
using namespace std;
#define ll long long
#define rep(i, end) for(ll i=0; i<(ll)(end); i++)

int main(){
  ll a, b, count=0, total=1;
  cin >> a >> b;
  while(total < b){
    total += a - 1;
    count++;
  }
  cout << count << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  map<int,int> ma;
  for(int i = 0;i < n;i++){
    int num = 0;
    cin >> num;
    ma[num - 1]++;
    ma[num]++;
    ma[num + 1]++;
  }
  int res = 0;
  for(auto item:ma){
    int a = item.second;
    res = max(res,a);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;

int main(){
	int n,k;
	std::cin >> n>>k;
	std::vector<int> a(n),ans(n,0);
	rep(i,n)std::cin >> a[i];
	ans[0]=0;
	
	for (int i = 1; i < n; i++) {
		/* code */
		ans[i]=INF;
		for(int j=1;j<=min(k,i);j++){
			ans[i]=min(ans[i],ans[i-j]+abs(a[i]-a[i-j]));
		}
	}
	std::cout << ans[n-1] << std::endl;
}







Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e18 + 8;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9;

const int maxn = 1e5 + 7;

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int r;
    cin >> r;
    double ans = 2 * PI * r;
    cout << setprecision(10) << fixed;
    cout << ans;
    return 0;
}


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

int main(){
    vector <int> ans(10001,0);
    int n;
    cin >> n;
    rep(x,200){
        rep(y,200){
            rep(z,200){
                if((pow((x+1)+(y+1),2)+pow((y+1)+(z+1),2)+pow((x+1)+(z+1),2))>20000){
                    continue;
                }
                else if(int((pow((x+1)+(y+1),2)+pow((y+1)+(z+1),2)+pow((x+1)+(z+1),2)))%2!=0){
                    continue;
                }
                else{
                    ++ans[(pow((x+1)+(y+1),2)+pow((y+1)+(z+1),2)+pow((x+1)+(z+1),2))/2];
                }
            }
        }
    }

    rep(i,n){
        cout << ans[i+1] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3632
# encoding:utf-8
n = int(input())
ary = input().split()

if n % 2 == 0:
	out = [i for i in range(2, n+1, 2)]
	out.reverse()
	out.extend([i for i in range(1, n, 2)])
	out_str = [str(ary[i-1]) for i in out]
else:
	out = [i for i in range(1, n + 1, 2)]
	out.reverse()
	out.extend([i for i in range(2, n, 2)])
	out_str = [str(ary[i-1]) for i in out]

print(" ".join(out_str))




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

using namespace std;

int main(){
    string s;
    cin>>s;
    
    if(s=="Sunny") cout<<"Cloudy"<<endl;
    else if(s=="Cloudy") cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
    
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

void solve() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n)cin >> a[i];
	rep(i, n) {
		Rep(j, i + 1, n) {
			int dif = abs(a[i] - a[j]);
			if (dif % (n - 1) == 0) {
				cout << a[i] << " " << a[j] << endl; return;
			}
		}
	}
}

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


Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
//naive : O(n^2)
int findLCP(const std::string& s){
  int ret = 0;
  int n = s.length();
  std::vector<int> z(n, 0);

  for(int i=1; i<n; i++){
    for(int j=0; i+j<n; j++){
      if(s[j] == s[i+j]) z[i]++;
      else break;
    }
    ret = std::max(ret, z[i]);
  }
  return ret;
}

//Z algorithm : O(n)
int Zalgorithm(const std::string& s, const int n){
  int ret = 0;
  std::vector<int> z(n, 0);

  int L = 0, R = 0;
  for(int i=1; i<n; i++){
    if(i>R){
      L = R = i;
      while(R<n && s[R-L] == s[R]) R++;
      z[i] = R-L;
      R--;
    }else{
      int k = i-L;
      if(z[k] < R-i+1){
        z[i] = z[k];
      }else{
        L = i;
        while(R<n && s[R-L] == s[R]) R++;
        z[i] = R-L;
        R--;
      }
    }
    // cerr << i << " " << z[i] << endl;
    ret = std::max(ret, std::min(z[i], i));
  }
  return ret;
}

//exact search by Z algorithm
std::vector<int> Zsearch(const std::string& T, const std::string& P){
  std::string S = P + "$" + T;
  std::vector<int> z(S.length(), 0);

  int L = 0, R = 0;
  for(int i=1; i<S.length(); i++){
    if(i>R){
      L = R = i;
      while(R<S.length() && S[R-L] == S[R]) R++;
      z[i] = R-L;
      R--;
    }else{
      int k = i-L;
      if(z[k] < R-i+1){
        z[i] = z[k];
      }else{
        L = i;
        while(R<S.length() && S[R-L] == S[R]) R++;
        z[i] = R-L;
        R--;
      }
    }
  }
  
  std::vector<int> ret;
  for(int i=P.length()+1; i<S.length(); i++){
    if(z[i] == P.length()){
      ret.push_back( i-(P.length()+1) );
    }
  }
  return ret;
}


int main(){
  
  int n;
  std::cin >> n;
  std::string str;
  std::cin >> str;

  int ans = 0;
  for (int i=0; i<n-1; i++) {
      std::string s = str.substr(i, n-i);
      // int res = Zalgorithm(s, n-i);
      // cerr << s << " " << res << endl;
      ans = std::max(ans, Zalgorithm(s, n-i));
  }

  //最長共通接頭辞の長さを返す
  // std::cout << findLCP(str) << std::endl;
  std::cout << ans << std::endl;

  // std::cout << "----" << std::endl;

  // 文字列strからパターン文字列patをすべて探す
  // std::string pat = "aab";
  // std::vector<int> ret = Zsearch(str, pat);
  // for(int i=0; i<ret.size(); i++){
  //   std::cout << ret[i] << std::endl;
  // }

  return 0;
}


Measured memory_bytes: 384
s = input()
S = [int(s[i]) for i in range(len(s))]
N = len(S)
 
dis1 = 0
dis2 = 0
start = 0
for i in range(N):
    if (S[i]!=1-start):
        dis1 += 1
    if (S[i]!=start):
        dis2 += 1
    start = 1-start
res = min(dis1, dis2)
print (res)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s; cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC");

	return 0;
}

Measured memory_bytes: 3640