akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#define rep(i,n) for(int i=0;i<(n);i++)
#define EPS (10e-9)

using namespace std;

double dp[16][9];
const string room[3] = { "ABC", "DEF", "GHI" };
const int dir[][2] = { {-1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };

int main()
{
	int n;
	while (cin >> n && n ){
		char s, t, b;
		cin >> s >> t >> b;

		rep (i, 16 ) rep (j, 9 ) dp[i][j] = 0.0;

		dp[0][s-'A'] = 1.0;
		rep (i, n )
			for (int j = 0; j < 9; j++ ){
				if (dp[i][j] > EPS ){
					int cr = j/3, cc = j%3;
					char C = room[cr][cc];
					rep (k, 4 ){
						int nr = cr + dir[k][0];
						int nc = cc + dir[k][1];
						if (nr < 0 || nc < 0 || nr >= 3 || nc >= 3 || room[nr][nc] == b ){
							dp[i+1][C-'A'] += 1./4.*dp[i][C-'A'];
						}else{
							char D = room[nr][nc];
							dp[i+1][D-'A'] += 1./4.*dp[i][C-'A'];
						} // end if
					} // end rep
				} // end if
			} // end for

		printf ("%.9lf\n", dp[n][t-'A'] );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
from math import floor, sqrt


def main():
    N = int(input())
    divs = divisor(N)
    ans = 0
    for i in divs:
        m = i - 1
        if m == 0:
            continue
        if N // m == N % m:
            ans += m
    print(ans)


def divisor(N):
    divs = []
    sup = floor(sqrt(N))
    for i in range(1, sup+1):
        if N % i == 0:
            divs.append(i)
            divs.append(N // i)
    return sorted(divs)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3272
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}
int cnt[26];
int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  for(char c: s) {
    cnt[c - 'a']++;
  }
  int n = s.size();
  int max_char = *(MAX(cnt, cnt + 26));
  // sort(cnt, cnt + 26, greater<int>());
  // int max_char = cnt[0];
  // int second = cnt[1];
  if(n == 1 || (max_char <= (n + 3 - 1) / 3))
    cout << "YES\n";
  else
    cout << "NO\n";
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 512
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int K = 19;
const int KM = 1 << (K - 1);
pair<int, int> dat[1 << K];

pair<int, int> check(int L, int R, int A, int l, int r) {
	if (L <= l && r <= R) return dat[A];
	if (r <= L || R <= l) return mp(1e9, 1e9);
	return min(check(L, R, A * 2, l, (l + r) / 2), check(L, R, A * 2 + 1, (l + r) / 2, r));
}

pair<int, int> query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

ll kotae;
void keisan(int L, int R) {
	auto p = query(L, R);
	ll k2 = (ll)(R - L + 1) * (R - L) - (ll)(R - p.second - 1) * (R - p.second) - (ll)(p.second - L + 1) * (p.second - L);
	kotae += p.first * k2 / 2;
	if (L < p.second) keisan(L, p.second);
	if (R > p.second + 1) keisan(p.second + 1, R);
}

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


	int N = getint();
	rep(i, N) {
		int a = getint();
		dat[i + KM] = mp(a, i);
	}

	for (int i = KM - 1; i >= 1; i--) {
		dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
	}

	keisan(0, N);

	printf("%lld", kotae);

	Would you please return 0;
}

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

int main()
{
    int n, s[12] = {0}, c[101] = {0};
    int p[12] = {0};

    while( cin >> n )
    {
        if( n == 0 )
            break;
    
        for( int i = 0; i < n; i++ )
            cin >> s[i];

        int cnt = 0;
        bool judge = false;
        while( judge == false )
        {
            for( int i = 0; i < 101; i++ )
                c[i] = 0;

            for( int i = 0; i < n; i++ )
            {
                p[i] = s[i];
                c[s[i]]++;
            }

            for( int i = 0; i < n; i++ )
                s[i] = c[s[i]];

            for( int i = 0; i < n; i++ )
            {
                if( p[i] != s[i] )
                {
                    judge = false;
                    cnt++;
                    break;
                }
                else
                    judge = true;
            }
        }

        cout << cnt << endl;
        for( int i = 0; i < n; i++ )
        {
            cout << s[i];
            if( i != n - 1 )
                cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3012
///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 1e5 + 10;

int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    ll n, k;
    cin >> n >> k;
    n = n % k;
    cout << min(n, k - n);
    return 0;
}
/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/
//! N.N


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll D; vll path; vector<string> A; ll magic = 0; vpll list;
//***********//
int main() {
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	ans += A[0] - 1;
	ll value = 2;
	for (i = 1; i < N; i++) {
		if (A[i] == value) {
			value = A[i]+1;
		}
		else if(A[i] > value) ans += (A[i] - 1) / value;
	}
	cout << ans;
}

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

p = 0
count = 0
ans = 0
for i in range(n):
    if a[i] == p:
        count += 1
    else:
        ans += count // 2
        p = a[i]
        count = 1

ans += count // 2
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 13;
int n, k, dp[maxN], a[maxN];
int main () {
    cin >> n >> k;
    dp[0] = 0;
    for (int i = 0; i < n; i++)
	cin >> a[i];
    for (int i = 1; i <= k; i++)
	for (int j = 0; j < n; j++)
	    if (i >= a[j])
		dp[i] |= (!dp[i - a[j]]);
    if (dp[k] == 0)
	cout << "Second" << endl;
    else
	cout << "First" << endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

vector<pair<ll, int>> prime_factorization(ll n) {
	vector<pair<ll, int>> res;
	for(ll i = 2; i * i <= n; i++){
		if(n % i) continue;
		res.emplace_back(i, 0);
		while(n % i == 0){
			n /= i;
			res.back().second++;
		}
	}
	if(n != 1) res.emplace_back(n, 1);
	return res;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll 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 main() {
	int n;
	cin >> n;
	if(n==1) {
		cout << 0 << endl;
		return 0;
		
	}
	map<int, int> fac;
	for(int i = 1; i <= n; i++) {
		auto now = prime_factorization(i);
		rep(j, now.size()) {
			int key = now[j].first;
			int val = now[j].second;
			fac[key] += val;
		}
	}
	// for(auto t: fac) cout << t.first << " " << t.second << endl;
	// auto div75 = divisor(75);
	// for(auto t: div75) cout << t << endl;
	int ans = 0;
	vector<int> cnt;
	for(auto t: fac){
		cnt.push_back(t.second);
	}
	sort(all(cnt));
	for(int i = 0; i < cnt.size()-2; i++) {
		for(int j = i+1; j < cnt.size()-1; j++) {
			for(int k = j+1; k < cnt.size(); k++) {
				if(cnt[i]>=2 && cnt[j]>=4 && cnt[k]>=4) ans++;
				if(cnt[i]>=4 && cnt[j]>=2 && cnt[k]>=4) ans++;
				if(cnt[i]>=4 && cnt[j]>=4 && cnt[k]>=2) ans++;
			}
		}
	}
	for(int i = 0; i < cnt.size()-1; i++) {
		for(int j = i+1; j < cnt.size(); j++) {
			if(cnt[i]>=4 && cnt[j]>=14) ans++;
			if(cnt[i]>=14 && cnt[j]>=4) ans++;
		}
	}
	for(int i = 0; i < cnt.size()-1; i++) {
		for(int j = i+1; j < cnt.size(); j++) {
			if(cnt[i]>=2 && cnt[j]>=24) ans++;
			if(cnt[i]>=24 && cnt[j]>=2) ans++;
		}
	}
	for(int i = 0; i < cnt.size(); i++) {
		if(cnt[i]>=74) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
p = [ int(i) -1 for i in input().split()]
edges = [ [] for _ in range(N)]
visit = [None] * N
ans = 0
for i in range(M):
    x,y = list(map(int,input().split()))
    edges[x -1].append(y -1)
    edges[y -1].append(x -1)
for i in range(N):
    if visit[i]:
        continue
    stack = [i]
    cp = [i]
    visit[i] = "yes"
    while len(stack) > 0:
        t = stack.pop()
        for tt in edges[t]:
            if visit[tt] is None:
                visit[tt] = "yes"
                cp.append(tt)
                stack.append(tt)
    nodes = set()
    for node in cp:
        nodes.add(p[node])
    for node in cp:
        if node in nodes:
            ans +=1
print(ans)


Measured memory_bytes: 36964
/*
https://www.cnblogs.com/zdragon1104/p/12441877.html
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define per(i, x, y) for (int i = x; i >= y; i--)
using namespace std;

const int N = 2e5 + 10;
typedef long long ll;
int n, p, num, tmp = 1, mark[N];
ll ans;
char s[N];

int main() {
    cin >> n >> p;
    scanf("%s", s + 1);
    if (p == 2 || p == 5) {
        rep(i, 1, n) if ((s[i] - '0') % p == 0) ans += i;
    } else {
        mark[0] = 1;
        per(i, n, 1) {
            num = (num + (s[i] - '0') * tmp) % p;
            ans += mark[num];
            mark[num]++;
            tmp = tmp * 10 % p;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 640
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)

ans = 0
before = 100
n.times do |i|
  ans += b[a[i]-1]
  ans += c[a[i-1]-1] if a[i] - before == 1
  before = a[i]
end

puts ans

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const ll inf = 2e18;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	ll c[n][3];
	rep(i, 0, n) rep(a, 0, 3) cin >> c[i][a];

	ll dp[n][3];
	dp[0][0] = c[0][0];	dp[0][1] = c[0][1];	dp[0][2] = c[0][2];
	rep(i, 1, n) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + c[i][0];
		dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + c[i][1];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i][2];
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}

Measured memory_bytes: 4992
#include <iostream>

int N, M, C;
const int MAX = 20;
int B[MAX] = {0};
int A[MAX][MAX] = {0};
int seitou = 0;

int main()
{
  std::cin >> N >> M >> C;
  for (int i=0; i < M; i++){
    std::cin >> B[i];
  }
  for (int i=0; i < N; i++){
    for (int j=0; j < M; j++){
      std::cin >> A[i][j];
    }
  }

  for (int i=0; i < N; i++){
    int sum = C;
    for (int j=0; j < M; j++){
      sum += A[i][j]*B[j];
    }
    if (sum > 0){
      seitou += 1;
    }
  }

  std::cout << seitou;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int sum(int num)
{
    int s = 0;
    while (num) {
        s += num % 10;
        num /= 10;
    }
    return s;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




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

	vector<vector<ll>> dp(N, vector<ll>(N + 1, 0));
	rep(i, N) dp[0][i] = A[i];

	ll ans = INF;

	repn(i, N - 1) {

		rep(j, N) {
			dp[i][j] = min(dp[i - 1][j], dp[i - 1][(j+N - 1)%N]);
		}
	}

	rep(i, N) {
		ll v = x * i;
		rep(j, N) { v += dp[i][j]; }
		ans = min(ans, v);
	}

	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 31864
def examA():
    a, b = LI()
    if b<a:
        a,b = b,a
    if a<=0 and 0<=b:
        print("Zero")
    elif 0<a:
        print("Positive")
    else:
        judge = b-a+1
        if judge%2==0:
            print("Positive")
        else:
            print("Negative")
    return

def examB():
    N, M = LI()
    flag_R = [False]*N
    cnt = [1]*N
    flag_R[0] = True
    for _ in range(M):
        x, y = LI()
        x -= 1; y -= 1
        if flag_R[x]:
            flag_R[y] = True
        cnt[y] += 1
        cnt[x] -= 1
        if cnt[x]==0:
            flag_R[x] = False
    ans = sum(flag_R)
    print(ans)
    return

def examC():
    N, L = LI()
    A = LI()
    can = set()

    if N==2:
        if sum(A)<L:
            print("Impossible")
            return

    l = inf
    for i in range(N-1):
        cur_R = A[i]+A[i+1]
        if cur_R>=L:
            l = min(l,i)
            can.add(i)
    if not can:
        print("Impossible")
        return
    print("Possible")
    ans = []

    for i in range(l):
        ans.append(i+1)
    for i in range(l,N-1)[::-1]:
        if i in can:
            continue
        ans.append(i+1)
    for i in can:
        ans.append(i+1)
    for v in ans:
        print(v)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

Measured memory_bytes: 20088
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		shellSort(c, n);
		in.close();
	}

	private static int insertionSort(int[] A, int n, int g) {
		int v;
		int j;
		int cnt = 0;
		for (int i = g; i < n; i++) {
			v = A[i];
			j = i - g;
			while (j >= 0 && A[j] > v) {
				A[j + g] = A[j];
				j = j - g;
				cnt += 1;

			}

			A[j + g] = v;
		}
		return cnt;
	}

	private static void shellSort(int[] A, int n) {
		int m = 0;
		int[] G = new int[15];
		int cnt = 0;
		for (int i = 1; i <= n; i=i*3+1) {
			G[m] =i;
			m += 1;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = m-1; i >=0; i--) {
			cnt+=insertionSort(A, n, G[i]);
			if (i !=m-1) {
				sb.append(" ");
			}
			sb.append(G[i]);
		}
		System.out.println(m);
		System.out.println(sb.toString());
		System.out.println(cnt);
		for (int i = 0; i < n; i++) {
			System.out.println(A[i]);
		}
	}

}



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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MOD = 1000000007;

inline void add(int &a, int b) {
    a += b;
    if (a >= MOD) {
       a -= MOD;
   }
}

inline void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
       a += MOD;
   }
}

inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}

inline int power(int a, int b) {
    int res = 1;

    while (b > 0) {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }

    return res;
}

inline int inverse(int x) {
    return power(x, MOD - 2);
}

const int MN = 110;
const int MK = 100010;

int dp[MN][MK];
int dp2[MN][MK];

int main() {
    int N, K; cin >> N >> K;
    dp[0][0] = 1;

    rep(i, N) {
        rep(j, MK) {
            dp2[i][j] = dp[i][j];
            if (j > 0) {
                add(dp2[i][j], dp2[i][j-1]);
            }
        }

        int x; cin >> x;
        rep(j, MK) {
            dp[i+1][j] = dp2[i][j];
            if (j > x) {
                sub(dp[i+1][j], dp2[i][j-x-1]);
            }
        }
    }

    cout << dp[N][K] << endl;

	return 0;
}

Measured memory_bytes: 84224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007;

bool isprime(int x) {
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  for(int i = 2; i <= n; i++) {
    if(!isprime(i)) continue;
    ll res = 1;
    for(int j = i; j <= n; j++) {
      int k = j;
      int cnt = 0;
      while(k%i==0) {
        k /= i;
        cnt++;
      }
      res += cnt;
    }
    ans *= (ll)res;
    ans %= (ll)mod;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

// Header files, namespaces,
// macros as defined above
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;


#define f first
#define s second
#define db long double
#define pb push_back
#define sz(c) (c).size()
#define all(c) (c).begin(),(c).end()

typedef long long ll;
typedef pair <int , int> ii;
typedef pair <ii , int> iii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;
typedef vector <vii> vvii;

const ll mod = 1e9+7;
const int MAX = 1e6+7;
const db eps = 1e-13;

string cad;

bool mk[MAX];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cout<<setprecision(0)<<fixed;

    cin>>cad;

    vii v;

    for( int i = 0 ; i < sz(cad) ; i++ ) {

        int cnt = 0;
        int j;
        for( j = i; cad[j]==cad[i] ; j++, cnt++ );
        i = j-1;
        v.pb({(cad[i]=='<'?0:1),cnt});
    }

    ll tmp = 0;
    ll ans = 0;

    for( auto x : v ) {

        if( x.f == 0 ) {
            tmp = 0;
            for( int i = tmp+1 ; i <= tmp+x.s ; i++ )
                ans += i;
            tmp = tmp+x.s;
//            cout<<x.s<<"\n";
        } else {
//            cout<<x.s<<" "<<tmp<<"\n";
            if( tmp < (x.s) ) {

                ans -= tmp;
                tmp = x.s;
                while( tmp ) {

                    ans += tmp;
                    tmp--;

                }

            } else {
                tmp = x.s-1;

                while( tmp ) {

                    ans += tmp;
                    tmp--;

                }

            }
        }

    }


    cout<<ans<<"\n";
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
#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 all(a) a.begin(),a.end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define debug(x) cout<<#x<<": "<<x<<endl
#define INF 1e9
typedef long long ll;

int main(void){
    string s;
    cin>>s;
    reverse(all(s));
    int idx;
    rep(i,12){
        if(s[i]=='?'){
            idx = i;
        }
    }
    // debug(s);debug(idx);
    int res,ok=0;
    rep(k,10){
        s[idx] = '0'+k;
        ll sigma = 0;
        rep1(n,11){
            sigma += (s[n]-'0')*((n<=6) ? (n+1) : (n-5));
        }
        int check = 11-(sigma%11);
        if((sigma%11)<=1) check = 0;
        // debug(k);
        // debug(sigma);
        // debug(check);
        if(check == s[0]-'0'){
            ok++;
            res=k;
        }
    }
    if(ok>1){
        cout<<"MULTIPLE"<<endl;
    }else{
        cout<<res<<endl;
    }
    return 0;
}

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

ll n,a[100009],c[100009],_a[100009],_c[100009],q,jo3[100009];
ll ans;
string s;

// 3^k
ll jo(ll k){
    if(k==0)return 1;
    if(k<0)return 0;
    if(jo3[k])return jo3[k];
    return jo3[k]=(jo(k-1)*3)%mod;
}

int main(){
    cin>>s;
    n=s.size();
    rep(i,n){
        if(s[i]=='A')a[i+1]=1;
        if(s[i]=='C')c[i+1]=1;
        if(s[i]=='?')_a[i+1]=_c[i+1]=1,q++;
    }

    rep(i,n){
        a[i+1]+=a[i];
        _a[i+1]+=_a[i];
    }
    for(int i=n;i;i--){
        c[i]+=c[i+1];
        _c[i]+=_c[i+1];
    }

    for(int i=1;i<=n;i++){
        int x=q;
        if(s[i-1]=='?')x--;
        if(s[i-1]=='B'||s[i-1]=='?'){
            (ans+=a[i-1]*c[i+1]*jo(x))%=mod;
            (ans+=_a[i-1]*c[i+1]*jo(x-1))%=mod;
            (ans+=a[i-1]*_c[i+1]*jo(x-1))%=mod;
            (ans+=_a[i-1]*_c[i+1]*jo(x-2))%=mod;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5888
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <numeric>
#include <iterator>
#include <map>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  int n, k;
  cin >> n >> k;
  // map<int, int> kind;
  vector<int> kind(n, 0);
  int counts = 0;
  rep(i,n){
    int a;
    cin >> a;
    a--;
    if(kind[a] == 0){
      counts++;
    }
    kind[a] += 1;
  }

  int ans = 0;
  sort(kind.begin(), kind.end(), greater<int>());
  for (int i=counts-1;i>k-1;--i){
    ans += kind[i];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
const int MOD = 1000000007;

vector<ll> primes;
void init_primes(ll N)
{
    vector<bool> is_prime(N+1, true);
    is_prime[0] = is_prime[1] = false;
    rep(i, 2, N+1)
    if (is_prime[i])
    {
        primes.push_back(i);
        for (ll j = (ll)i*i; j<=N; j += i)
            is_prime[j] = false;
    }
}

vector<ll> decompose(ll n)
{
    if (n==1) return {1};
    ll org = n;
    vector<ll> res = {};
    for (ll i=1; i*i<=n; ++i)
    if (n%i==0)
    {
        res.emplace_back(i);
        if (i!=n/i)
            res.emplace_back(n/i);
    }
    return res;
}

ll power_mod(ll n, ll m)
{
    ll res = 1;
    ll base = n;
    while (m > 0)
    {
        if (m&1) res = (res * base) % MOD;
        base = (base * base) % MOD;
        m >>= 1;
    }
    return res;
}

int main()
{
    // init primes
    init_primes(100009);

    ll n, k;
    cin >> n >> k;

    ll res = 0;
    vector<ll> cnts(k+1, 0);
    rrep(i, k+1, 1)
    {
        // calc count
        ll cnt = power_mod(k/i, n) - cnts[i];
        debug(i, cnt, power_mod(k/i, n) );
        cnt %= MOD;
        
        debug(i, decompose(i));
        for (auto value: decompose(i))
            cnts[value] += cnt;

        ll now = (cnt*i)%MOD;
        res = (res+now)%MOD;
        debug(res);
        // cout << "*****" << endl;
    }
    res %= MOD;
    if (res<0) res += MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,K;
    cin >> N >> K;
    int f[N];
    rep(i,N) cin >> f[i];
    int ans=0;
    rep(i,N){
        if(f[i]>=K) ans++;
    }
    cout << ans << endl;



}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,j,mn=INT_MAX;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        mn=INT_MAX;
        for(j=1;j<=k;j++)
        {
            if(i-j>=0)
            mn=min(mn,dp[i-j]+abs(a[i]-a[i-j]));
        }
        dp[i]=mn;
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int N, D , X;
    cin >> N >> D >> X;
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    for(int i=0; i<N; i++){
        X+=(D+A[i]-1)/A[i];
    }
    cout<<X<<endl;
    return 0;
}


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

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

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

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int N, A[MAX], B[MAX], C[MAX];

int main(){
    cin >> N;
    rep(i, N){
        int a;
        cin >> a;
        A[i] = --a;
    };
    rep(i, N) cin >> B[i];
    rep(i, N - 1) cin >> C[i];

    int ans = 0;
    rep(i, N) {
        ans += B[ A[i] ];
        if (i < N - 1 && A[i] == A[i + 1] - 1) ans += C[ A[i] ];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/*input
9
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define sz(a) int((a).size())
#define pb push_back
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())     
#define rep(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define N 998244353
#define PI acos(-1.0)
//if (s.find('R') != std::string::npos)
//s.replace(s.find("10"), sizeof("10") - 1, "");
using namespace std;

int main()
{
  // added the two lines below 
  ios_base::sync_with_stdio (false); 
  cin.tie(NULL);
  cout.tie(0);

  ll x,n;
  cin>>x>>n;
  cout<<(3*x+n)/2;
  }

Measured memory_bytes: 256
s = input()

c = 0

if len(s) % 2 == 0:
    for i in range(len(s) // 2):
        # print(s[i], s[-i])
        if s[i] != s[-i - 1]:
            c += 1
else:
    for i in range(len(s) // 2):
        if s[i] != s[-i - 1]:
            c += 1
print(c)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m);
  rep(i, m) cin >> x[i] >> y[i];

  vector<int> bc(n), rb(n);
  rep(i, n) bc[i] = 1;
  rb[0] = 1;

  rep(i, m) {
    int o = x[i] - 1;
    int d = y[i] - 1;

    if (rb[o] != 0) rb[d] = 1;
    bc[o]--;
    if (bc[o] == 0) rb[o] = 0;
    bc[d]++;
  }

  int ans = 0;
  rep(i, n) if (rb[i] != 0) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 4844
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 12 10:38:04 2019
C - Bridge
実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 
300
 点
@author: justwah
"""

import sys
read = sys.stdin.readline

n, m = map(int, input().split())    # single line use regular input() is faster

l = [list(tuple(map(int, read().split()))) for i in range(m)]   #multiple lines use sys.stdin.readline faster

def root(x): #recursively find root for a node
    if parent[x] < 0: # if at root, return self
        return x
    else:
        parent[x] = root(parent[x])  # while searching rejoint queried node to a common parent for hierarchical tree
        return parent[x]
    
def merge(a, b):
    a = root(a)
    b = root(b)
    if rank[a] < rank[b]: # joint lower rank node to a higher rank one
        parent[a] = b
    else:
        parent[b] = a
        if rank[a] == rank[b]: # rank only change if two same rank node joined
            rank[a] +=1    
    return

score = 0

for i in range(m):
    parent = [-1]*(n+1)
    rank = [0]*(n+1)
    first = l[0]
    l = l[1:]
    l.append(first)
    for i, (a, b) in enumerate(l):
        a = root(a)
        b = root(b)
        if a != b:
            merge(a, b)
        else:
            if i == (len(l)-1):
                score += 1

print(m-score)


Measured memory_bytes: 3064
#include<stdio.h>
int main() {
	int a[10], i, j, temp;
	for (i = 0;i < 10;i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0;i < 10;i++) {
		for (j = i + 1;j <10 ;j++) {
			if (a[j] > a[i]) {
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for (i = 0;i < 3;i++) {
		printf("%d\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll dp[3010][3010];



int main(){
   ll A,B,C,D;
   cin >> A >> B >> C >> D;
   dp[A][B] = 1;
   FOR(i,A,C+1){
      FOR(j,B,D+1){
         if(A == i && B == j) continue;
         dp[i][j] = dp[i][j-1] * i + dp[i-1][j] * j - dp[i-1][j-1] * (i-1) * (j-1);
         while(dp[i][j] < 0LL) dp[i][j] += MOD * 1000000000LL;
         dp[i][j] %= MOD;
      }
   }
   cout << dp[C][D] % MOD << endl;
}


Measured memory_bytes: 74108
#include <stdio.h>
int M(int a, int b) {
	return a > b ? a : b;
}
int main() {
	int k,n,i;
	scanf("%d %d", &k, &n);
	int l[n];
	for (i = 0; i < n; i++) {
		scanf("%d", &l[i]);
	}
	int m = k - l[n - 1] + l[0];
	for (i = 0; i < n-1; i++) {
		m = M(m, l[i + 1] - l[i]);
	}
	printf("%d", k - m);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;



int main(void){
  int N,Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> ac(S.size(),0);
  int cnt = 0;
  for(int i =1; i <= S.size(); i++){
    if(S[i-1] == 'A' && S[i] == 'C'){
      cnt++;
    }
    ac[i] = cnt;
  }
  for(int i = 0; i < Q; i++){
    int l, r;
    cin >> l >> r;
    cout << ac[r-1] - ac[l-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    int n,m;
    cin >> n >> m;
    vi s(m);
    vi c(m);
    rep(i,m) cin >> s[i] >> c[i];
    rep(i,1000){
        string str = to_string(i);
        bool flg = true;
        if (str.size() != n) flg = false;
        for (int j=0; j<m; j++){
            if (str[s[j]-1] != (char)(c[j]+'0')) flg = false;
        }
        if (flg){
            cout << i;
            return 0;
        }
    }
    cout << -1;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
string s;
const int NMAX = 1000;
int matrix[NMAX+5][NMAX+5];
int dx [4] = {0, 1, 0, -1};
int dy [4] = {1, 0, -1, 0};
set<int>g[NMAX*NMAX + 5];
void bfs(int n, int m, int ind, int x, int y)
{
   queue<int>qx;
   queue<int>qy;
   qx.push(x);
   qy.push(y);
   matrix[x][y] = ind;
   while(!qx.empty())
   {
      x = qx.front();
      y = qy.front();
      qx.pop();
      qy.pop();
      for(int i=0;i<4;i++)
      {
          int cx = x + dx[i];
          /// x linie
          /// y coloana
          int cy = y + dy[i];
          if(cx <= n and cx >=1 and cy <= m and cy >= 1 and matrix[cx][cy] == 0)
          {
              matrix[cx][cy] = ind;
              qx.push(cx);
              qy.push(cy);
          }
      }
   }
}
void bfs2(int n, int m, int x, int y)
{
    int i, j;
   for(i=-2; i<=2; i++)
   {
       for(j=-2; j<=2;j++)
       {
           int cx = x + i;
           /// x linie
           /// y coloana
           int cy = y + j;
           if(cx <= n and cx >=1 and cy <= m and cy>=1 and matrix[cx][cy] != matrix[x][y] and matrix[cx][cy] != -1)
              g[matrix[x][y]].insert(matrix[cx][cy]);

       }

   }
}
int bfs3(vector<int> viz, int start, int finish)
{
    queue<int>q;
    viz[start] = 1;
    q.push(start);
    while (!q.empty())
    {
        start = q.front();
        if(start == finish)
            break;
        q.pop();
        for(auto x : g[start]) {
            if (viz[x] == 0){
                viz[x] = viz[start] + 1;
                q.push(x);
                if(x == finish)
                    break;
            }
        }

    }
    return viz[finish] - 1;
}
 int main()
 {
     long long  t, n, k, x, m;
     int i, j;
     long long sum = 0;
     cin>>n>>m;
     int x1, x2, y1, y2;
     cin>>x1>>y1>>x2>>y2;
     for(i=1;i<=n;i++)
     {
         cin>>s;
         for(j = 0; j < s.size(); j++)
         {
             if(s[j] == '#')
                 matrix[i][j+1] = -1;
             else
                 matrix[i][j+1] = 0;
         }
     }

     int ind = 1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(matrix[i][j] == 0) {
                bfs(n, m, ind, i, j);
                ind++;
            }
        }
    }

  /*   for(i=1;i<=n;i++)
     {
         for(j=1;j<=m;j++)
         {
             cout<<matrix[i][j]<<" ";
         }
         cout<<"\n";

     }*/

    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++)
            if(matrix[i][j] != -1)
                bfs2(n, m, i, j);
    }


    vector <int> viz(ind+5, 0);
    //cout<<matrix[x1][y1]<<"\n";
    // cout<<matrix[x2][y2]<<"\n";

    cout<<bfs3(viz, matrix[x1][y1], matrix[x2][y2])<<"\n";


 }

Measured memory_bytes: 73416
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	ll n, a, b; cin >> n >> a >> b;
	string s; cin >> s;
	int asum = 0, bsum = 0;
	for (int i = 0; i < (int)s.length(); i++) {
		if (s[i] == 'a') {
			if (asum + bsum < a + b) {
				cout << "Yes" << endl;
				asum++;
			}
			else cout << "No" << endl;
		}
		else if (s[i] == 'b') {
			if (asum + bsum < a + b && bsum < b) {
				cout << "Yes" << endl;
				bsum++;
			}
			else cout << "No" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
long long a[234234],ans;
int b[234],n;
char s[123];

int main()
{int i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
	  scanf("%s",s+1);
	  for(j=1;j<=10;j++) b[j]=s[j]-'a';
	  sort(b+1,b+1+10);
	  for(j=1;j<=10;j++) a[i]=a[i]*26+b[j];
	}
	sort(a+1,a+1+n);
	a[n+1]=-1;
  for(i=1;i<=n;i++) 
    {
	  j=i+1;
	  while(a[j]==a[i]) j++;
	  ans+=(long long)(j-i)*(j-i-1)/2;
	  i=j-1;
	}
	cout<<ans<<endl;
} 

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


int rec[550][550];

int main(){
    int N,M,Q; cin>>N>>M>>Q;
    int L[M],R[M];
    int p[Q],q[Q];
    rep(i,M) cin>>L[i]>>R[i];
    rep(i,Q) cin>>p[i]>>q[i];
    rep(i,M){
        rec[L[i]][R[i]]++;
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N-1;j++){
            rec[i][j+1]+=rec[i][j];
        }
    }
     for(int j=1;j<=N;j++){
        for(int i=N+1;i>0;i--){
            rec[i-1][j]+=rec[i][j];
        }
    }

    rep(i,Q){
        cout<<rec[p[i]][q[i]]<<endl;
    }

    
}

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

using namespace std;

int main(void){
    int a, b, c, d, e, k, flag = 0;

    cin >> a >> b >> c >> d >> e >> k;

    if(b - a > k) flag = 1;
    if(c - a > k) flag = 1;
    if(d - a > k) flag = 1;
    if(e - a > k) flag = 1;
    if(c - b > k) flag = 1;
    if(d - b > k) flag = 1;
    if(e - b > k) flag = 1;
    if(d - c > k) flag = 1;
    if(e - c > k) flag = 1;
    if(e - d > k) flag = 1;

    if(flag){
        cout << ":(" << endl;
    }
    else{
        cout << "Yay!" << endl;
    }

    return 0;
}

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

int main() {
int N,A,B,C,D;
int Z,ZZ;
cin >> N >> A >> B >> C >> D;
if(N%A == 0){
	Z = N/A;
};
if(N%A != 0){
	Z = N/A + 1;
}
if(N%C == 0){
	ZZ = N/C;
};
if(N%C != 0){
	ZZ = N/C + 1;
};
if(Z*B <= ZZ*D){
	cout << Z*B << endl;
}
else if(Z*B > ZZ*D){
	cout << ZZ*D << endl;
}
return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

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

const ll MAXN = 10001;
ll P[MAXN];

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

    for (ll x=1;x*x<=N;++x)
    for (ll y=1;y*y<=N;++y)
    for (ll z=1;z*z<=N;++z)
    {
        const auto n = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
        if (n <= N) { ++P[n]; }
    }

    rep (i, N)
    {
        cout << P[i + 1] << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

int A, B, M;
vector<int> a, b;

void read() {
	cin >> A >> B >> M;
	a.resize(A);
	for (auto &i : a) {
		cin >> i;
	}
	b.resize(B);
	for (auto &i : b) {
		cin >> i;
	}
}

int ans;

void run() {
	ans = *min_element(all(a)) + *min_element(all(b));
	while (M--) {
		int x, y, c;
		cin >> x >> y >> c;
		x--;
		y--;
		chkmin(ans, a[x] + b[y] - c);
	}
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x
    
def main():
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    if y % 2 == 0 and y >= 2*x and y <= 4*x:
        print("Yes")
    else:
        print("No")
main()

Measured memory_bytes: 9976