akhauriyash/Code-Regression huggingface dataset:
#pragma once
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>

using namespace std;

using i8 = char;
using u8 = unsigned char;
using i32 = int;
using u32 = unsigned int;
using i64 = long long int;
using u64 = unsigned long long int;

using pii = pair<i32, i32>;

#define LOOP_TYPE(s, n) decltype((n) - (s))
#define FOR(i, s, n) for (auto i = LOOP_TYPE(s, n)(s); i != LOOP_TYPE(s, n)(n); i++)
#define FORR(i, s, n) for (auto i = LOOP_TYPE(s, n)(n) - 1; i != LOOP_TYPE(s, n)(s) - 1; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FORR(i, 0, n)

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

constexpr i8 WHITE = 0;
constexpr i8 BLACK = 1;

#define mp make_pair

using field = vector<vector<i8>>;


int main()
{
	i32 H, W;
	cin >> H >> W;
	field f(H + 2, vector<i8>(W + 2, BLACK));

	queue<pair<i32, pii>> que;
	REP(i, H) {
		REP(j, W) {
			i8 ch;
			cin >> ch;
			if (ch == '#') {
				f[i + 1][j + 1] = BLACK;
				que.emplace(mp(0, mp(i + 1, j + 1)));
			} else {
				f[i + 1][j + 1] = WHITE;
			}
		}
	}

	i32 count = 0;
	while (!que.empty()) {
		const auto current = que.front();
		i32 depth = current.first;
		i32 cy = current.second.first;
		i32 cx = current.second.second;
		que.pop();
		REP(i, 4) {
			const i32 x = dx[i] + cx;
			const i32 y = dy[i] + cy;
			if (f[y][x] == WHITE) {
				f[y][x] = BLACK;
				count = max(count, depth + 1);
				que.emplace(mp(depth + 1, mp(y, x)));
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 13056
from collections import Counter

n = int(input())
D = [0] + list(map(int, input().split()))

C = Counter(D)

if C[0] >= 2 or C[12] >= 2 or any(v >= 3 for v in C.values()):
  print(0)
  exit()
  
ans = 0
for b in range(1<<11):
  T = []
  T.append(0)
  if C[12]:
    T.append(12)
  for i in range(11):
    if C[i + 1] == 2:
      T.append(i + 1)
      T.append(24 - (i + 1))
    else:
      if C[i + 1] == 1:
        if b & (1 << i):
          T.append(i + 1)
        else:
          T.append(24 - (i + 1))
  T.sort()
  T = T + [24]
  tmp = min(j - i for i, j in zip(T, T[1:]))
  ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


vector<LL> pdivi(LL K){
    vector<LL> v;
    for(LL i=2;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        while(K%i==0){
            K/=i;
        }
    }
    if(K!=1) v.pb(K);
    return v;
}


int main(){
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> cnt(2000000, 0);
    for (int i = 0; i < n; i++) {
        auto p = pdivi(a[i]);
        for (int j = 0; j < p.size(); j++) {
            cnt[p[j]]++;
        }
    }
    bool f = true;
    for (int i = 0; i < cnt.size(); i++) {
        if(cnt[i] > 1){
            f = false;
            break;
        }
    }
    if(f) puts("pairwise coprime");
    else{
        LL aa = a[0];
        for (int i = 0; i < n; i++) {
            aa = gcd(aa, a[i]);
        }
        if(aa == 1) puts("setwise coprime");
        else puts("not coprime");
    }
    return 0;
}


Measured memory_bytes: 18732
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>

using namespace std;

int to[12][12]; int p[12]; bool switch1[12]; int connect[12];
int cnt = 0; int N, M;

void count(){//switchの状態の数をすべて試したとき、いくつの電球がついているのかをしらべる
 for(int i = 1; i <= M; i++){
   connect[i] = 0;}
  //connectを初期化
  
  for(int i = 1; i <= M ; i++){
    for(int X = 1; X <= N; X++){
      if( to[i][X] > 0 && switch1[X] == true){ connect[i]++;}}}
    
    bool flag = true;
    
    for(int j = 1; j <= M ; j++){
      if(connect[j] % 2 != p[j]){flag = false;}}
    
    if(flag){cnt++;}
                  }

void dfs(int depth){
  if(depth == N + 1){ count(); return;}
  switch1[depth] = true; dfs( depth + 1);
  switch1[depth] = false; dfs( depth + 1);}


  

int main(){
   cin >> N >> M;
  for(int i = 1; i <= M; i++){
    int c; cin >> c;
      for(int j = 1; j <= c; j++){
        int s;cin >> s; to[i][s]++;}}
    
    //to[i][s] > 0 means 電球 i is connnected to switch s
    
  for(int i = 1; i <= M ; i++){
    cin >> p[i];}
  
  dfs(1);
    
    cout << cnt << endl;
    
    return 0;
  }
        


Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(ll, M);
    IN(ll, R);
    AIN(ll, r, R);
    vi A(M), B(M), C(M);
    REP(i, M)
    {
        cin >> A[i] >> B[i] >> C[i];
    }

    vvi dp(N + 1, vi(N + 1, INF));
    REP1(i, N)
    {
        dp[i][i] = 0;
    }
    REP(i, M)
    {
        dp[A[i]][B[i]] = C[i];
        dp[B[i]][A[i]] = C[i];
    }
    REP1(k, N)
    {
        REP1(i, N)
        {
            REP1(j, N)
            {
                CH(min, dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    SORT(r);
    ll ans = INF;
    do
    {
        ll d = 0;
        REP(i, R - 1)
        {
            d += dp[r[i]][r[i + 1]];
        }
        CH(min, ans, d);
    } while (next_permutation(ALL(r)));

    OUT(ans);
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

const int MAX = 200001;
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; 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(int n, int k){
   if (n < k) return 0;
   if (n < 0 || k < 0) return 0;
   return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main ()
{
  prep();
  COMinit();
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  long long sums1[100001];
  // height = h-a-1
  for (int i=b; i<w; i++){
      sums1[i] = COM(i+h-a-1, h-a-1);
      //cout << i << " " << h-a-1 << endl;
  }
  long long res = 0;
  // height = h-a
 
  for (int i=b; i<w; i++){
      res += (sums1[i]*COM(w-i-1+a-1, a-1))%mod;
      res %= mod;
      //cout << w-i-1 << " " << a-1 << endl;
  }
  cout << res;
  return 0; 
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<vector<int> > cnt;
    cnt.resize(N);
    string str;
    for (int i = 0; i < N; i++)
    {
        cin >> str;
        cnt[i].resize(26);
        fill(cnt[i].begin(), cnt[i].end(), 0);
        for (char c : str)
        {
            cnt[i][c - 'a']++;
        }
        
    }

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

    long long ans = 0;
    vector<int> prv = cnt[0];
    long long n = 0;
    for (int i = 1; i < N; i++)
    {
        if (prv == cnt[i])
        {
            n++;
        }else
        {
            if (n == 0)
            {
            }else
            {
                ans += (n + 1) * n / 2;
                n = 0;
            }
            
        }
        prv = cnt[i];
        
    }

    if (n != 0)
    {
       ans += (n + 1) * n / 2;
    }
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 15616
#include <iostream>
#include <stdio.h>

#define EPS (1e-10)

using namespace std;
//?
int main(void){
	double a,b,c,d,p,q;
	while(cin >> a >> b >> p >> c >> d >> q){
		double delta = a*d-b*c;
		double x,y;
		x = (d*p-b*q)/delta;
		y = (-c*p+a*q)/delta;
		printf("%.3f %.3f\n",x+EPS,y+EPS);
	}
	return 0;
}

Measured memory_bytes: 0
from math import ceil, log2
import sys
z=sys.stdin.readline


# SegTreeの関数
def segfunc(x, y):
    return max(x, y)


# 単位元
# min->inf, max->-inf, add->0, mul->1
ide_ele = -1


# セグメント木
class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセットする
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


n, k = map(int, z().split())
a = [int(z()) for _ in range(n)]
M=300001
st = SegTree([0]*M, max, 0)
res = 0
for i in a:
    min_a = max(i-k, 0)
    max_a = min(i+k, M)
    s = st.query(min_a, max_a+1)
    st.update(i, max(s, 0)+1)
    res = max(res, max(s, 0) + 1)

print(res)


Measured memory_bytes: 93124
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    int max = 0;
    for (int i = 0; i < N-1; i++) {
        int count = 0;
        std::vector<int> vx(26, 0);
        std::vector<int> vy(26, 0);

        for (int x = 0; x < i+1; x++) {
            vx[S[x] - 'a']++;
        }
        for (int y = i+1; y < N; y++) {
            vy[S[y] - 'a']++;
        }

        for (int j = 0; j < 26; j++) {
            if (vx[j] * vy[j] != 0) {
                count++;
            }
        }

        max = std::max(max, count);
    }

    std::cout << max << std::endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for i in range(n):
    s = list(map(int, list(input().rstrip())))
    for j in range(n):
        if s[j]:
            edges[i].append(j)

            
def dfs(v):
    for v2 in edges[v]:
        if color[v2] != -1:
            if color[v] == color[v2]:
                global is_ok
                is_ok = 0
            continue
        color[v2] = color[v] ^ 1
        dfs(v2)


color = [-1]*n
color[0] = 0
is_ok = 1
dfs(0)


def bfs(init_v):
    next_v = deque([init_v])
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        for v2 in edges[v]:
            if dist[v2] <= dist[v]+1:
                continue
            dist[v2] = dist[v]+1
            next_v.append(v2)
    return dist


if is_ok:
    ans = 0
    for i in range(n):
        dist = bfs(i)
        x = max(dist)
        if ans < x:
            ans = x
    print(ans+1)
else:
    print(-1)

Measured memory_bytes: 3828
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

l = []
now = '.'
count = 0
for i in range(n):
  if ( s[i] != now ):
    l.append(count)
    now = s[i]
    count = 0
  count += 1

if ( count > 0 ):
  l.append(count)

l.append(0)

#print(l)

ans = 99999999999
left = 0
right = 0

for j in range(int((len(l)-1)/2)):
  right += l[(j+1)*2]

for ii in range(int(len(l)/2)):
  i = ii*2

  if( i!=0):
    right -= l[i]

  count = 0
  if ( i!=0):
    left += l[i-1]
  
  count = left + right
  #print(i, count, left, right)
  


  if (ans>count):
    ans = count

if (ans == 99999999999):
  ans = 0

print(ans)


Measured memory_bytes: 5092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

ll k, a[100];
ll n;
ll buf[100];

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	ll ans = 0;
	while (1) {
		bool f = 0;
		rep(i, n) {
			if (a[i] >= n)f = 1;
		}
		if (!f)break;
		rep(i, n)buf[i] = a[i];
		rep(i, n) {
			ll num = a[i] / n;
			//cout << num << endl;
			rep(j, n) {
				if (i != j)buf[j] += num;
				else buf[j] -= num * n;
			}
			ans += num;
		}
		//rep(i, n) {
		//	cout << buf[i] << endl;
		//}
		rep(i, n)a[i] = buf[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int MOD = 1e9+7;
const ll LINF = 1e18;
const int INF = 1e9;
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> N;
    for (ll i = 1; i <= N; i*=10)
    {
        A += (N/i) % 10;
    }
    if(N % A == 0) cout<< "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

bool from1[2505];
bool fromN[2505];
bool ok[2505];
vector<vl> G(2505);
vector<vl> rG(2505);

void dfs(ll u){
    if(from1[u]) return;
    from1[u] = true;
    for(auto v : G[u]){
        if(from1[v]) continue;
        dfs(v);
    }
}

void rdfs(ll u){
    if(fromN[u]) return;
    fromN[u] = true;
    for(auto v : rG[u]){
        //cout << v.first << endl;
        if(fromN[v]) continue;
        rdfs(v);
    }
}


int main(){
    ll n,m,p; cin >> n >> m >> p;
    vector<tuple<ll,ll,ll>> edges;
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        c -= p;
        c = -c;
        G[a].push_back(b);
        rG[b].push_back(a);
        edges.emplace_back(a,b,c);
    }
    dfs(0);
    rdfs(n-1);
    rep(i,n) ok[i] = from1[i] && fromN[i];
    vl d(n,INF);
    d[0] = 0;
    bool upd = true;
    ll times = 0;
    //rep(i,n) cout << ok[i] << endl;
    while(upd){
        upd = false;
        rep(i,m){
            ll a,b,c;
            tie(a,b,c) = edges[i];
            if(!ok[a]) continue;
            if(!ok[b]) continue;
            ll dis = d[a] + c;
            if(dis < d[b]){
                upd = true;
                d[b] = dis;
            }
        }
        times++;
        if(times > n){
            puts("-1");
            return 0;
        }
    }
    ll ans = max(-d[n-1],0LL);
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,m;
  std::cin>>n>>m;
  std::vector<ll> b(n+1);
  b[0]=0;
  rep(i,0,n){
    ll a;
    std::cin>>a;
    b[i+1]=(b[i]+a)%m;
  }
  std::sort(all(b));
  ll prev=-1,count=0,ans=0;
  rep(i,0,n+1){
    if(b[i]!=prev){
      ans+=count*(count-1)/2;
      count=1;
      prev=b[i];
    }else{
      count++;
    }
  }

  ans+=count*(count-1)/2;
  std::cout<<ans;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        System.out.println(gcd(x, y));
        
    }
	
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		else return gcd(b, a % b);
	}
}


Measured memory_bytes: 26364
#include<bits/stdc++.h>
using namespace std;
//using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

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

int main(){
  long long n,k;
  cin >> n >> k;
  long long div_cnt = (n+k-1)/k;
  cout<< min(n,abs(n-k*div_cnt)) <<endl;
}


Measured memory_bytes: 256
N = int(input())
#N, M = map(int, input().split())
#A = list(map(lambda x: int(x)*(-1), input().split()))
#X = list(map(int, input().split()))
X = [int(input()) for i in range(N)]
#C = [list(map(int, input().split())) for i in range()]

pointer = 1
push = 0
for i in range(N):
    pointer = X[pointer-1]
    push += 1
    if pointer == 2:
        print(push)
        exit()
print(-1)

Measured memory_bytes: 7084
import math
A,B,C = map(int, input().split())
K = int(input())
if A > B:
  K1 = math.ceil(math.log(A/B,2))
  B = B * (2 ** K1)
  if A == B:
    B = B * 2
    K1 = K1 + 1
elif A == B:
  B = B * 2
  K1 = 1
else:
  K1 = 0

if B > C:
  K2 = math.ceil(math.log(B/C,2))
  C = C * (2 ** K2)
  if C == B:
    K2 = K2 + 1
elif B == C:
  K2= 1
else:
  K2= 0
  
if K1 + K2 <= K:
  print('Yes')
else:
  print('No')

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    int cnt=0;for(int i=0;i<3;i++) if(s[i]=='o') cnt++;
    cout<<700+100*cnt<<endl;
}


Measured memory_bytes: 256
h, w = gets.split.map &:to_i
ans = h <= w ? h : w
if h % 3 == 0 || w % 3 == 0 then
  ans = 0
else
  1.upto(h/2) { |y|
    arr = [y*w, (h-y)*(w/2), (h-y)*(w-w/2)]
    s = arr.max - arr.min
    ans = s  if ans > s
  }
  1.upto(w/2) { |x|
    arr = [h*x, (h/2)*(w-x), (h-h/2)*(w-x)]
    s = arr.max - arr.min
    ans = s  if ans > s
  }
end
puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAXN = 105;
int main()
{
    ll x,res=0;
    double t=100;
    scanf("%lld",&x);
    while(t<x){
        t*=1.01;
        t=(ll)t;
        res++;
        //cout<<t<<endl;
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 3828
#include<iostream>

using namespace std;

int main(){
  int V,E;
  cin>>V>>E;
  int d[15][15];
  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      d[i][j]=-1;
    }
  }
  while(E--){
    int s,t,d_;
    cin>>s>>t>>d_;
    d[s][t]=d_;
  }
  int dp[1<<15][15];
  for(int i=0;i<V-1;i++){
    if(d[V-1][i]>=0){
      dp[1<<i][i]=d[V-1][i];
    }else{
      dp[1<<i][i]=1e9;
    }
  }
  for(int i=0;i<1<<V-1;i++){
    if(!(i&i-1))continue;
    for(int j=0;j<V-1;j++){
      if(!(i>>j&1))continue;
      dp[i][j]=1e9;
      int p=i^1<<j;
      for(int k=0;k<V-1;k++){
	if(!(p>>k&1)||d[k][j]<0)continue;
	dp[i][j]=min(dp[i][j],dp[p][k]+d[k][j]);
      }
    }
  }
  int b=1e9;
  for(int i=0;i<V-1;i++){
    if(d[i][V-1]<0)continue;
    b=min(b,dp[(1<<V-1)-1][i]+d[i][V-1]);
  }
  cout<<(b>1e8?-1:b)<<endl;
}

Measured memory_bytes: 2128
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int R, G;
    cin >> R >> G;
    cout << 2 * G - R << endl;
    return 0;
}

Measured memory_bytes: 256
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int n;
  while (cin >> n, n) {
    unordered_map<string, int> chie;
    rep(i, n) {
      string s;
      int p;
      cin >> s >> p;
      chie[s] = p;
    }
    int m;
    cin >> m;
    rep(i, m) {
      string s;
      int k;
      cin >> s >> k;
      int res = 0;
      rep(j, k) {
        string t;
        cin >> t;
        res += chie[t];
      }
      chmin(chie[s], res);
    }
    print(chie[in<string>()]);
  }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

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

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

int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  ll Ans=-1;
  rep(i, N){
    cin>>A[i];
    if(i==0){
      Ans=A[0];
      continue;
    }
    Ans=gcd(Ans, A[i]);
  }
  cout<<Ans<<endl;


}

Measured memory_bytes: 3980
#include <stdio.h>

int a, b;

int main(void) {
    scanf("%d%d", &a, &b);
    
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        printf("Possible\n");
    } else {
        printf("Impossible\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 +7;
typedef long long ll;
inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}
int a[maxn];
int main()
{
    int n = read(), k = read();
    for (int i = 1; i <= n; i++) {
        a[i] = read();
        if(i > k) {
            if(a[i - k] < a[i]) printf("Yes\n");
            else printf("No\n");
        }
    }
}


Measured memory_bytes: 4368
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main() {
	string str; getline(cin, str);
	for (int i=0; i<str.length(); i++) {
		if (str[i] != ' ' && str[i] != '.') {
			str[i] = toupper(str[i]);
		}
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 0
/*
    Problem 68
    https://onlinejudge.u-aizu.ac.jp/problems/NTL_1_A
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
map<int, int> primeFactrization(int x) {
    map<int, int> factor;
    int n = x;
    for (int i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            factor[i]++;
            n /= i;
        }
    }
    if (n != 1) factor[n]++;
    return factor;
}
/* main */
int main(){
    int x;
    cin >> x;
    map<int, int> factor = primeFactrization(x);
    cout << x << ":";
    for (auto f : factor)
        for (int i = 0; i < f.second; i++)
            cout << ' ' << f.first;
    cout << '\n';
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<pll> vplll;
ll mod = 1e9+7;
ll m[100005],x;
ll cost(ll ans, ll ar[], ll k,ll n)
{
	if(m[k]!=-1)
		return m[k];
	if(k==n-1)
		return 0;
	else if(k>=n-x-1)
		return abs(ar[n-1]-ar[k]);
	ll tmp = ans;
	ans = 1e10;
	for(int i=k+1;i<=k+x;i++)
	// ans += min(abs(ar[k+1]-ar[k])+cost(ans,ar,k+1,n),abs(ar[k+2]-ar[k])+cost(ans,ar,k+2,n));
	{
		// ans = tmp;
		ans = min(ans,abs(ar[i]-ar[k])+cost(tmp,ar,i,n));
	}
	ans += tmp;
	m[k] = ans;
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int a,b,c,n,t; 
    for(int i=0;i<100005;i++)
    	m[i]=-1;
    cin>>n>>x;
    ll ar[n+2];
    ar[n]=0;
    ar[n+1]=0;
    for(int i=0;i<n;i++)
    	cin>>ar[i];
    ll ans;
    ans = cost(0, ar,0,n);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
long long n,a[11],ans;
char s[100001];
int main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if (s[0]=='M')a[0]++;
		if (s[0]=='A')a[1]++;
		if (s[0]=='R')a[2]++;
		if (s[0]=='C')a[3]++;
		if (s[0]=='H')a[4]++;
	}
	for (int i=0;i<5;i++)
		for (int j=i+1;j<5;j++)
			for (int k=j+1;k<5;k++)ans+=a[i]*a[j]*a[k];
	printf("%lld",ans);
}


Measured memory_bytes: 128
L = [1]
n = int(input())
x = 6
y = 9
while x <= n:
    L.append(x)
    x *= 6
while y <= n:
    L.append(y)
    y *= 9
L.sort()
dp = [float("Inf")]*(n+1)
dp[0] = 0
for i in range(n+1):
    for j in L:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i]+1)
        else:
            break
print(dp[n])

Measured memory_bytes: 9424
s1 = list(input())

s2 = list(input())

ans = 'No'

for i in range(len(s1)):
  if ("".join(s1) == "".join(s2)):
    ans = 'Yes'
    break  
  last = s1.pop()
  s1.insert(0,last)
print(ans)
  

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<utility>

using namespace std;

using P = pair<int, int>;
int ord[100000];
int low[100000];
int v, e;

set<P> M;
vector<int> Edge[100000];
vector<bool> isNew(100000, true);
set<P> U;

bool isEdge(int s, int t) {
	return M.end()!=M.find(P(s, t));
}
bool isUsed(int s, int t) {
	return U.end()!=U.find(P(s, t));
}
void dfs(int u) {
	isNew[u] = false;
	static int k ;
	ord[u] = k; k++;
	//cout << "u=" << u << " k=" << k << endl;
	low[u] = ord[u];
	for (int v : Edge[u]) {
		if (isNew[v]) {
			U.emplace(u, v); U.emplace(v, u);
			dfs(v);
			low[u] = min(low[u], low[v]);
		}
		else if (!isUsed(u, v)) {
			low[u] = min(low[u], ord[v]);
		}
	}
}
int main() {
	cin >> v >> e;
	for (int i = 0; i < e; i++) {
		int s, t;
		cin >> s >> t;
		M.emplace(s, t);
		M.emplace(t, s);
		Edge[s].push_back(t);
		Edge[t].push_back(s);
	}
	dfs(0);
	//for (P p : M) {
	//	cout << p.first << " " << p.second << endl;
	//}
	//for (int i = 0; i < v; i++) {
	//	cout << "low=" << low[v] << " ord=" << ord[v] << endl;
	//}
	//cout << endl;
	for (P p : M) {
		int f = p.first;
		int s = p.second;
		if (f < s) {

		if (ord[f] < low[s] || ord[s] < low[f]) {
			cout << f << " " << p.second << endl;
		}
		}
	}
}

Measured memory_bytes: 12408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ff(i,n) for(i=0;i<n;i++)
ll bg=1000000007;
ll gcd(ll a,ll b)
{
if(b==0)
   return a;
else
   return gcd(b,a%b);   
}
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2);	
	h=(h*h);
	if(y%2==1)
	  return (x*h);
	else
	  return h;  
}
ll isp(string str) 
{ 
    // Start from leftmost and rightmost corners of str 
    int l = 0; 
    int h = str.length() - 1;
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        {  
            return -1; 
        } 
    } 
    return 1; 
} 
vector<vector<pair<ll,ll> > >adj(300000);
ll dis[300000],vis[300000],p[300000];

int main()
{
	ll t;
	t=1;
	while(t--)
	{	
	    ll i,n;
		string f;
		cin>>n;   
		ll a=n/500,b=n%500,c=b/5;
		a=1000*a;
		c=c*5;
		cout<<a+c;     	  	   
	}
return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int X; cin >> X;
  int num = X;
  while(1){
    bool ok = 1;
    for(int i = 2; i*i <= num; i++){
      if(num % i == 0) ok = 0;
    }
    if(ok){
      cout << num << endl;
      return 0;
    }
    num++;
  }
}

Measured memory_bytes: 384
#include <stdio.h>          // printf(), scanf()

#define MAX_LEN 200

typedef enum
{
	type_a,
	type_b,
	type_na
} s_type;

const char NUL = '\0';

s_type
snake_type(char line[MAX_LEN + 2])
{
	int i, j;
	const char *s = line;
	if (*s != '>')
		return type_na;

	s++;
	switch (*s++)
	{
	case '\'':
		for (i = 0; *s != '#' && *s != '\n' && *s != NUL; ++i, ++s)
		{
			if (*s != '=')
				return type_na;
		}

		if (*s++ != '#')
			return type_na;

		for (j = 0; *s != '~' && *s != '\n' && *s != NUL; ++j, ++s)
		{
			if (*s != '=')
				return type_na;
		}

		if (*s++ != '~')
			return type_na;

		if (*s != '\n' && *s != NUL)
			return type_na;

		if (i < 1 || i != j)
			return type_na;

		return type_a;

	case '^':
		for (i = 0; *s != '~' && *s != '\n' && *s != NUL; ++i, s += 2)
		{
			if (s[0] != 'Q' || s[1] != '=')
				return type_na;
		}

		if (s[0] != '~' || s[1] != '~')
			return type_na;

		s += 2;
		if (*s != '\n' && *s != NUL)
			return type_na;

		if (i < 1)
			return type_na;

		return type_b;

	default:
		return type_na;
	}
}

int
main(int argc, char **argv)
{
	char line[MAX_LEN + 2];
	int n;

	scanf("%d\n", &n);
	for (int i = 0; i < n; ++i)
	{
		fgets(line, sizeof(line), stdin);
		switch (snake_type(line))
		{
		case type_a:
			printf("A\n");
			break;

		case type_b:
			printf("B\n");
			break;

		default:
			printf("NA\n");
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1760
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner num = new Scanner(System.in);
    int x = num.nextInt();
    int y = num.nextInt();
    int area = x * y;
    int length = x * 2 + y * 2;
    System.out.println(area + " "+ length);
  }
}

Measured memory_bytes: 26148
import itertools

N, M, Q = map(int, input().split())
abcd = list(list(map(int, input().split())) for _ in range(Q))

ans = 0
for l in list(itertools.combinations_with_replacement(list(range(1,M+1)), N)):
    tmp = 0
    for i in range(Q):
        if l[abcd[i][1]-1] - l[abcd[i][0]-1] == abcd[i][2]:
            tmp += abcd[i][3]
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 21400
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t a,b,x;
  cin>>a>>b>>x;
  if(a!=0){
  int64_t ans=(b/x)-((a-1)/x);
  cout<<ans<<endl;
  }else{
  int64_t ans=1+(b/x);
    cout<<ans<<endl;
  }
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void){
  int a[3];
  int count5 = 0;
  int count7 =0;
  for (int i=0; i<=3; i++){
    scanf("%d",&a[i]);
    if(a[i] == 5) {
      count5++;
    }else if (a[i] == 7){
      count7++;
    }
  }
    if (count5 == 2 && count7 == 1){
      printf("YES");
    }else {
      printf("NO");
    }
    return 0;
 }


Measured memory_bytes: 1708
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;
template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, y;
  cin >> n >> x >> y;
  x--; y--;

  map<int, int> mp;
  rep(i, n){
    mp[i+1] = n - (i+1);
  }

  if(x >y) swap(x, y);
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      int bd = abs(j - i);
      int nd = abs(x - i) + 1 + abs(j - y);
      if(nd >= 1 && nd < bd){
      // cout << bd << ' ' << nd << endl;
        mp[bd]--;
        mp[nd]++;
      }
    }
  }

  for(int i = 1; i < n; i++){
    cout << mp[i] << endl;
  }


}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////
ll c[200100];
ll dp[200100];
vector<ll>color[200100];
vector<ll>C;
int main() {
	ll N; cin >> N;
	REP(i, N)cin >> c[i];
	REP(i, N) {
		if (i == N - 1) {
			C.push_back(c[i]);
			continue;
		}
		if (c[i] == c[i + 1])continue;
		C.push_back(c[i]);
	}
	REP(i, 200100)color[i].clear();
	REP(i, C.size()) {
		color[C[i]].push_back(i);
	}
	dp[0] = 1;
	for (int i = 1; i <= C.size(); ++i) {
		dp[i] += dp[i - 1];
		int j = lower_bound(color[C[i - 1]].begin(), color[C[i - 1]].end(), i - 1) - color[C[i - 1]].begin();
		if (j > 0) {
			dp[i] += dp[color[C[i - 1]][j - 1]+1];
		}
		dp[i] %= INF;
	}
	cout << dp[C.size()] << endl;
	return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	
	for(int i=0;i<n;i++){
		if(a[i]<b[i]) break;
		if(a[i]>b[i]){
			a.swap(b);
			break;
		}
	}
	int res=0;
	while(a!=b){
		next_permutation(a.begin(),a.end());
		res++;
	}
	cout << res << "\n";
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
isYes = True
tmpmin = 10**9+1
for i in range(1, n):
    if h[n-i] <= tmpmin:
        tmpmin = h[n-i]
    if h[n-(i+1)]-h[n-i]>= 2 or h[n-(i+1)]-tmpmin >= 2:
        isYes = False
        break
if isYes:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 15020
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip()
W = [0] * N
E = [0] * N

cnt = 0
for i in range(1, N):
    if S[i-1] == "W":
        cnt += 1
        W[i] = cnt
    else:
        W[i] = cnt
cnt = 0
for i in reversed(range(N-1)):
    if S[i+1] == "E":
        cnt += 1
        E[i] = cnt
    else:
        E[i] = cnt

min = float("inf")
for i in range(N):
    if W[i] + E[i] < min:
        min = W[i] + E[i]
print(min)

Measured memory_bytes: 17648
// Aizu Vol0 0007: Debt Hell
// 2017.7.28

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

char *gets(char *);

#define MVS 0

int main()
{
	char buf[1000];
	int i, n, a, b;

#if MVS
	for (;;) {
		if (gets(buf) == NULL) break;
#else
		gets(buf);
#endif
		n = atoi(buf);
		a = 100000;
		for (i = 0; i < n; i++) {
			b = a * 5;
			b /= 100;
			a += b;
			b = a % 1000;
			if (b > 0) a += 1000 - b;
		}
		printf("%d\n", a);
#if MVS
	}
#endif
	return 0;
}

Measured memory_bytes: 524
//author Forsaken
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<numeric>
#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#define lowbit(x) ((x) & (-(x)))
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.in", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.out", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define memset0(arr) memset(arr, 0, sizeof(arr))
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
il int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll quick_pow(ll base, ll index) {
	ll res = 1;
	while (index) {
		if (index & 1)res = res * base % mod;
		base = base * base % mod;
		index >>= 1;
	}
	return res;
}
ll L, R;
int main()
{
	cin >> L >> R;
	ll d = R - L;
	if (d >= 2019) {
		cout << 0 << endl;
	}
	else {
		int mx = 20000;
		for (ll i = L; i < R; ++i)
			for (ll j = i + 1; j <= R; ++j) {
				mx = min(mx, i % 2019 * j % 2019);
			}
		cout << mx << endl;
	}
//	system("pause");
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())

dx=[1,0,-1,0]
dy=[0,1,0,-1]

not_ok=0
for y in range(H):
    for x in range(W):
        if s[y][x] == '#':
            ok=0
            for i in range(4):
                if 0 <= x+dx[i]<W and 0 <=y+dy[i]<H:
                    if s[y+dy[i]][x+dx[i]] == '#':
                        ok=1
            if ok!=1:
                not_ok=1
if not_ok==1:
    print('No')
else:
    print('Yes')


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    string s,t;
    cin>>s>>t;
    int as=inf;
    for(int i=0;i<_sz(s)-_sz(t)+1;i++){
        string g=s.substr(i,_sz(t));
        int x=0;
        rep(j,0,_sz(t))
            if(t[j]!=g[j])
                x++;
        as=min(as,x);
    }
    cout<<as;
    return 0;
}



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

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

  int ans = 0;
  for(int A=0; A<=N; A++) {
    int cnt = 0;
    for(int i=0; i<N; i++) {
      if(P[i] >= A) cnt++;
    }
    if(cnt >= A) ans = max(ans, A);
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
	int a[3];
	for (int i = 0; i < sizeof(a)/sizeof(*a); i++) {
		cin >> a[i];
	}
	sort(a, a+3);
	int ans = 0;
	for (int i = 1; i < sizeof(a)/sizeof(*a); i++) {
		ans += a[i] - a[i-1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256