akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j], abs(H[i]-H[i+j])+dp[i])
#        print(dp)

print(dp[-1])

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

struct UnionFind
{
	int N;
	vector<int> parent;
	vector<int> size_r;
	int num_of_sets;

	UnionFind(int N) :  N(N), parent(N), size_r(N, 1), num_of_sets(N) {
		for (int i = 0; i < N; ++i) parent[i] = i;
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size_r[x] < size_r[y]) swap(x, y);
		parent[y] = x;
		size_r[x] += size_r[y];
		size_r[y] = 0;
		num_of_sets--;
		return true;
	}

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

	int size(int x) {
		return size_r[root(x)];
	}

	vector<int> roots() {
		vector<int> v(N);
		for (int i = 0; i < N; ++i) v[i] = root(i);
		return v;
	}
};

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<int>> g(n);
	UnionFind U(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		U.merge(a, b);
	}
	vector<vector<int>> block(n);
	for (int i = 0; i < k; i++) {
		int c, d;
		cin >> c >> d;
		c--; d--;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	auto v = U.roots();
	for (int i = 0; i < n; i++) {
		int ans = U.size(i) - 1;
		ans -= g[i].size();
		for (int e : block[i]) {
			if (v[e] == v[i]) ans--;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 15256
#include<stdio.h>
#include<math.h>
#include<string.h>

#define FOR(n) for(int i=0:i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)

int min(int a,int b){
  if(a>b)return a;
  return b;
}
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  PRN(min(min(a+b,a-b),a*b));
  return 0;
}

Measured memory_bytes: 128
import numpy as np
yes, no = "Yes", "No"
n = int(input())
#listをnumpyのarrayの形にする
a = np.array(list(map(int, input().split())))
b = np.array(list(map(int, input().split())))
sb = np.sort(b)
sa = np.sort(a)

#argsortは,ソートした場合の各要素が元の位置だとどのインデックスにあたるか教えてくれる
# つまり、小さいやつから順にインデックス数を見ていく
sbi = np.argsort(b)
#print("b",b)     [2 2 8 3 4 3]
#print("sb",sb)   [2 2 3 3 4 8]
#print("sbi",sbi) [0 1 3 5 4 2]

sai = np.argsort(a[sbi])
#print("a",a)           [3 1 2 6 3 4]
#print("a[sbi]",a[sbi]) [3 1 6 4 3 2] aの要素を使って、bの大きさ順を再現したって感じか？
#print("sai",sai)       [1 5 0 4 3 2] 小さいやつから順にインデックス数を見ていく

#入れ替えても無理なやつ、どうやってもAi>BiになるやつはNo
# np.anyの返り値は、True or False
if np.any(sb < sa):
    print(no)
    exit(0)

#どうやってもAi<BiになるやつはYes
# [:-1]とか[1:]をつけてる意味がよくわからん
if np.any(sb[:-1] >= sa[1:]):
    print(yes)
    exit(0)

count = 1
i = 0
while True:
  #saiはa[sbi]を小さいやつから見ていってそいつのインデックスを羅列したもの
  #sai[0]なら一番小さいのはどこにあるか、sai[1]なら二番目に小さいやつの位置
  j = sai[i]
  if j == 0:
    break
  i = j
  count += 1
  
if count == n:
    print(no)
else:
    print(yes)
  
  


Measured memory_bytes: 24052
#%%
N = int(input())
ans = 0 
ans_count = 0
for i in range(1,N+1):
  count = 0
  tmp = i
  while tmp%2 == 0 :
    tmp = tmp/2
    count += 1
  if count >= ans_count:
    ans_count = count
    ans = i

print(ans)



Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#define SIZE 105

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	for(int i=0;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			string S="";
			for(int k=0;k<i;k++) S+=str[k];
			for(int k=j;k<n;k++) S+=str[k];
			if(S.size()==7&&S=="keyence")
			{
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int D; cin >> D;
    switch (D)
    {
    case 25:
        cout << "Christmas" << endl;
        break;
    case 24:
        cout << "Christmas Eve" << endl;
        break;
    case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
    case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;
    }
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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 main(){
	int N; cin >> N;
	vector<int> A(N+3);
	vector<int> ans(N+3);
	vector<int> Ret;
	REP(i,N){
	    cin >> A[i+1];
	}

	for (int i = N; 0 <= i; --i) {
		int now = 0;

		FORq(k,2,300002){
			if (k * i >= N+1) break;
			now = (now + ans[k*i]) % 2;
		}

		if (now != A[i]) {
			ans[i] = 1;
			Ret.PB(i);
		}
	}

	cout << Ret.size() << endl;
	REP(i,Ret.size()){
	    cout << Ret[i] << " ";
	}
	cout << endl;

    return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back

using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  double L;
  cin >> L;
  cout<<std::defaultfloat<<std::setprecision(14);
  cout << L*L*L /27ll << endl;


  return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

#define CMAX 26

void solve()
{
  ll D; cin >> D;
  vector<ll> c(CMAX + 1); rep1(i, CMAX) cin >> c[i];
  vector<vector<ll>> s(D + 1, vector<ll>(CMAX + 1));
  rep1(i, D) rep1(j, CMAX) cin >> s[i][j];

  vector<ll> t(D + 1); rep1(i, D) {cin >> t[i];}
  vector<vector<ll>> last(D + 1, vector<ll>(CMAX + 1, 0));
  ll sat = 0;
  ll dis;
  for(ll day = 1; day <= D; day++) {
    rep1(i, CMAX) last[day][i] = last[day - 1][i];
    ll con = t[day];
    sat += s[day][con];
    last[day][con] = day;
    dis = 0;
    rep1(i, CMAX) {
      dis += c[i] * (day - last[day][i]);
    }
    
    sat -= dis;

    cout << sat << endl;
  }

  rep1(day, D) {
    cerr << day << "] ";
    rep1(i, CMAX) {
      cerr << last[day][i] << " ";
    }
    cerr << endl;
  }
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3864
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(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;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

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

	int ans = 0;
	while (n != 0) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<utility>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#define pb push_back
#define st first
#define nd second
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long lo;
const int mod=1000000007,N=500005;
lo a,b,c,d,e,g=1,arr[N],h[N],dp[N];

lo f(lo  x){
	if(h[x] or x>a) return 0;
	if(x==a) return 1;
	if(dp[x]!=-1) return dp[x];
	return dp[x]=(f(x+1)+f(x+2))%mod;
}

void solve(){
	memset(dp,-1,sizeof dp);
	cin >> a >> b;
	for(lo i=1;i<=b;i++){
		lo x;
		cin >> x;
		h[x]=1;
	}
	cout << f(0) << endl;
}

int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	// cin >> g;
	while(g--) solve();
}

Measured memory_bytes: 11176
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [a, b, k] <- getInts
  putStr . unlines . map show $ solve a b k

solve :: Int -> Int -> Int -> [Int]
solve a b k
  | b - a < 2 * k = [a .. b]
  | otherwise      = [a .. a + k - 1] ++ [b - k + 1 .. b]

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine


Measured memory_bytes: 508
# -*- coding: utf-8 -*-
N = int(input())
an = list(map(int, input().split()))

dict = {}
for a in an:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

remove_num = 0

for k,v in dict.items():
    if k > v:
        remove_num += v
    else:
        remove_num += v - k

print(remove_num)


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

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

    ll ans=0;
    ll max=0;
    rep(i,s.size()){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T' ){ans++;}
        else{
            max=std::max(max,ans);
            ans=0;
        }
    }
    max=std::max(max,ans);

    cout<<max<<endl;


}



Measured memory_bytes: 3580
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 8;

/* typedef */

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<string,int> msi;
typedef map<vi,bool> mvib;

/* global variables */

msi cid;
mvib cache;

/* subroutines */

void rotx(vi& dc) {
  vi dc0(dc);
  dc[0] = dc0[1], dc[1] = dc0[3], dc[3] = dc0[2], dc[2] = dc0[0];
  dc[4] = dc0[5], dc[5] = dc0[7], dc[7] = dc0[6], dc[6] = dc0[4];
}

void roty(vi& dc) {
  vi dc0(dc);
  dc[0] = dc0[4], dc[4] = dc0[5], dc[5] = dc0[1], dc[1] = dc0[0];
  dc[2] = dc0[6], dc[6] = dc0[7], dc[7] = dc0[3], dc[3] = dc0[2];
}

void rotz(vi& dc) {
  vi dc0(dc);
  dc[0] = dc0[2], dc[2] = dc0[6], dc[6] = dc0[4], dc[4] = dc0[0];
  dc[1] = dc0[3], dc[3] = dc0[7], dc[7] = dc0[5], dc[5] = dc0[1];
}

/* main */

int main() {
  mvib rimap;
  vi idx(N);
  for (int i = 0; i < N; i++) idx[i] = i;

  for (int x = 0; x < 4; x++, rotx(idx))
    for (int y = 0; y < 4; y++, roty(idx))
      for (int z = 0; z < 4; z++, rotz(idx))
	if (rimap.find(idx) == rimap.end()) rimap[idx] = true;
  //cout << rimap.size() << endl;

  vvi ridx;
  for (mvib::iterator mit = rimap.begin(); mit != rimap.end(); mit++)
    ridx.push_back(mit->first);
  
  for (;;) {
    string cstr;
    cin >> cstr;
    if (cin.eof()) break;

    int id = 0;
    cid.clear();
    vi dc(N);

    dc[0] = id;
    cid[cstr] = id++;

    for (int i = 1; i < N; i++) {
      cin >> cstr;
      if (cid.find(cstr) == cid.end()) {
	dc[i] = id;
	cid[cstr] = id++;
      }
      else
	dc[i] = cid[cstr];
    }

    for (int i = 0; i < N; i++) idx[i] = i;

    cache.clear();
    vi dcr(N), dcr0(N);
    int count = 0;
    
    do {
      for (int i = 0; i < N; i++) dcr[i] = dc[idx[i]];

      if (cache.find(dcr) == cache.end()) {
	//for (int i = 0; i < N; i++) cout << dcr[i]; cout << endl;
	count ++;

	for (vvi::iterator vit = ridx.begin(); vit != ridx.end(); vit++) {
	  for (int i = 0; i < N; i++) dcr0[i] = dcr[(*vit)[i]];
	  cache[dcr0] = true;
	}
      }
    } while (next_permutation(idx.begin(), idx.end()));

    cout << count << endl;
  }

  return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

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

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

struct edge{ int to, cost; };
int N, Q, K;
vector<edge> G[100001];
ll dist[100001];

void solve(int d, ll c) {
    if(dist[d] < LLONG_MAX) return;
    dist[d] = c;
    rep(i, G[d].size()) {
        edge e = G[d][i];
        if(dist[e.to] > dist[d] + e.cost) {
            solve(e.to, dist[d] + e.cost);
        }
    }
}

int main() {
    scanf("%d", &N);
    rep(i, N - 1) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        G[a].push_back(edge{b, c});
        G[b].push_back(edge{a, c});
    }
    fill(dist, dist + N + 1, LLONG_MAX);
    scanf("%d %d", &Q, &K);
    solve(K, 0);
    rep(i, Q) {
        int a, b;
        scanf("%d %d", &a, &b);
        ll res = dist[a] + dist[b];
        printf("%lld\n", res);
    }
    return 0;
}

Measured memory_bytes: 12800
program main
  implicit none
  real i, j, N, D, d2, k,d1
  integer ans
  integer,allocatable :: x(:,:)

  read(*, *) N, D
  allocate(x(N,D))
  do i = 1,N
    read(*, *) (x(i,j), j = 1,D)
  end do
  ans = 0
  do i = 1,N-1
    do j = i+1,N
      d2 = 0
      do k = 1,D
        d2 = d2 + (x(i,k)-x(j,k))**2
      end do
      d1 = floor(sqrt(d2))
      if (d1**2 == d2) then
        ans = ans+1
      endif
    end do
  end do


  write(*,*) ans
end program main


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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    int a[n+1];
    f1(i,0,n)
    cin>>a[i+1];
    int b[n+1];
    memset(b,0,(n+1)*sizeof(int));
    int c[n+1];
    memset(c,0,(n+1)*sizeof(int));

    for(i=n;i>0;i--)
    {
    	if(b[i]%2==a[i])
    	{
    		continue;
    	}
    	else
    	{
    		//cout<<i<<endl;
    		b[i]++;
    		c[i]=1;
    		for(j=1;j*j<=i;j++)
    		{
    			if(i==j)
    				continue;
    			if(i%j==0)
    			{
    				b[j]++;
    				if(j*j!=i)
    					b[i/j]++;
    			}
    		}
    	}
    }
    // f1(i,1,n+1)
    // cout<<1<<gp<<i<<gp<<b[i]<<endl;
    if(b[1]%2!=a[1])
    	cout<<-1;
    else
    {
    	int ans=0;
    	f1(i,0,n+1)
    	{
    		if(c[i]==1)
    			ans++;
    	}
    	cout<<ans<<endl;
    	f1(i,0,n+1)
    	{
    		if(c[i]==1)
    			cout<<i<<gp;
    	}
    }
    return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
vector< pair<int,int> >v;

int solve(int a,int b)
{
    return abs(a-b);
}
int main()
{
    //cout<<solve(1,2,3,4)<<endl;
   ll n;cin>>n;
   string s;cin>>s;
   ll ans = INT_MAX;
   ll east[n]={0};
    east[0] =0;
   for(ll i =1;i<n;i++)
   {
      if(s[i-1]=='W') east[i] = east[i-1]+1;
      else east[i] = east[i-1];

   }
   ll west[n]={0};
   west[0] = 0;
   reverse(s.begin(),s.end());
   for(ll i =1;i<n;i++)
   {
       if(s[i-1]=='E')west[i] = west[i-1]+1;
       else west[i] = west[i-1];
   }

   reverse(west,west+n);
   for(ll i =0;i<n;i++)
   {
       ans = min(east[i]+west[i],ans);
   }
  /* cout<<endl;
   for(int i =0;i<n;i++)
   {
       cout<<west[i]<<" ";
   }
   cout<<endl;*/
   cout<<ans;
    return 0;
}


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

using namespace std;

int a[101];
int n;
int main(){
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	int ans = 0 , sum = 0;
	for(int i = 1 ; i <= n ; ++ i)
		if(a[i] != a[i - 1]){
			ans += sum / 2;
			sum = 1;
		}
		else
			sum ++;
	ans += sum / 2;
	cout << ans << endl;
	return 0;
}

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

static const int MAX = 100000;
int n, e, indeg[MAX];
vector<int> v[MAX];
list<int> out;
bool color[MAX];

void bfs(int u){
  queue<int> Q;
  Q.push(u);

  while ( !Q.empty() ){
    int top = Q.front(); Q.pop(); color[top] = true;
    out.push_back(top);
    for ( int i = 0; i < v[top].size(); i++){
      int t = v[top][i];
      indeg[t] --;
      if ( !color[t] && indeg[t] == 0){
        Q.push(t);
      }
    }
  }
}

void topological_sort(){
  for ( int i = 0; i < n; i++){
    if ( !color[i] && indeg[i] == 0){
      bfs(i);
    }
  }
}

int main() {
  cin >> n >> e;
  int s, t;
  for ( int i = 0; i < n; i++){ indeg[i] = 0;  color[i] = false;}
  for ( int i = 0; i < e; i++){
    cin >> s >> t;
    v[s].push_back(t);
    indeg[t] ++;
  }

  topological_sort();

  for ( list<int>::iterator it = out.begin(); it != out.end(); it++){
    cout << *it << endl;
  }

  return 0;
}


Measured memory_bytes: 6208
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static class UnionFind {
		int[] par; //

		public UnionFind(int n) {
			par = new int[n];
			for(int i = 0; i < n; i++){
				par[i] = -1;
			}
		}

		public int find(int x) {
			if(par[x] < 0){
				return x;
			}else{
				return par[x] = find(par[x]);
			}
		}

		public boolean union(int x, int y) {
			x = find(x);
			y = find(y);

			if(x != y){
				if(par[y] < par[x]){ // 多い方が根になるようにスワップする.
					int tmp = x;
					x = y;
					y = tmp;
				}
				par[x] += par[y];
				par[y] = x;
				return true;
			}else{
				return false;
			}
		}

		public boolean same(int x, int y) {
			return find(x) == find(y);
		}

		public int size(int x) {
			return -par[find(x)];
		}
	}
	
	public static int[][] move_dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final String pat =  "keyence";
			final String str = sc.next();
			
			for(int i = 0; i <= pat.length(); i++) {
				final String exp = "^" + pat.substring(0, i) + ".*" + pat.substring(i) + "$";
				
				if(str.matches(exp)) {
					System.out.println("YES");
					return;
				}
			}
			
			System.out.println("NO");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 22740
#include <cstdio>
const int MAXN = 25;
int A[MAXN], B[MAXN], C[MAXN];
int N;

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  for (int i = 1; i <= N; ++i) scanf("%d", &B[i]);
  for (int i = 1; i <  N; ++i) scanf("%d", &C[i]);
  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    ret += B[A[i]];
    if ((i >= 2) && (A[i] == A[i-1] + 1)) {
      ret += C[A[i-1]];
    }
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> divide(long long n){//素因数分解
    map<long long , long long> res;
    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
int main(){
    long long N;
    cin >> N;
    map<long long, long long> m;
    m = divide(N);
    vector<long long> vec(1000010);
    vec[0] = 0;
    for(long long i = 1; i < 1000010; i++){
        vec[i] += i + vec[i - 1];
    }
    long long ans = 0;
    for(auto u: m){
        int ind = lower_bound(vec.begin(), vec.end(), u.second) - vec.begin();
        if(vec[ind] != u.second) ind--;
        ans += ind;
    }
    cout<< ans << endl;
}

Measured memory_bytes: 11180
mod = 10 ** 9 + 7


def is_ok(last4):
    for i in range(4):
        t = list(last4)
        if i != 3:
            t[i], t[i + 1] = t[i + 1], t[i]
            # i == 0,1,2 : 隣接交換
            # i == 3 : 交換なし
        if 'AGC' in ''.join(t):
            return False
    return True


def dfs(length, last3):
    # last3文字はAGCではない文字列
    if last3 in m[length]:
        return m[length][last3]

    if length == n:
        return 1

    res = 0
    for c in 'ACGT':
        # 末尾につける文字の候補c
        if is_ok(last3 + c):
            res += dfs(length + 1, last3[1:] + c)
            res %= mod

    m[length][last3] = res
    return res


n = int(input())
m = [{} for _ in range(n + 1)]
print(dfs(0, 'TTT'))


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y, m;
string s, t;

ll rem;
ll cnt[3];


// < ----------- func eh ---------------- ? //



// <------------- Start of main() -------------------> //

void MAIN() {
	multiset<ll,greater<ll>> val;
	cin>>n>>m;
	while(n--) {
		cin>>x;
		val.insert(x);
	}
	while(m--) {
		auto it  = val.begin();
		if(*it == 0) break;
		val.erase(it);
		val.insert(*it/2);
	}
	ll sum = 0;
	for(auto it : val) sum+=it;
	cout<<sum;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 8240
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	dd := make([]int, n)

	for i := 0; i < n; i++ {
		dd[i] = getNextInt(scanner)
	}

	ans := 0

	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			ans += dd[i] * dd[j]
		}
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}


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

int main()
{
	int num;
	double w, h;

	while (scanf("%d,%lf,%lf", &num, &w, &h) != EOF){
		if (w / (h * h) >= 25.0){
			cout << num << endl;
		}
	}

	return (0);
}

Measured memory_bytes: 1232
n = int(input())
num1 = n//100
num2 = n//10
num2_last = num2%10
num3 = n%10
if num1 == 7:
    print("Yes")
elif num2_last ==7:
    print("Yes")
elif num3 ==7:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int a[5];
int main() {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if(a[0] == 5 && a[0] == a[1] && a[2] == 7)
        cout << "YES";
    else cout << "NO";
}

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

int n, l;
string s_r;

int main(){
  cin >> n >> l;
  string s[n];
  for (int i = 0; i < n; ++i) cin >> s[i];
  sort(s, s+n);
  for (int i = 0; i < n; ++i) s_r += s[i];
  cout << s_r;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> dp(h+1, vector<int>(w));
    dp[0][0] = 1;

    REP(i, h){
        for(int mask = 0; mask < (1 << (w-1)); mask++){
            bool flag = false;
            REP(j, w-1){
                if(mask & (1 << j) && mask & (2 << (j))) flag = true;
            }
            if(flag) continue;

            REP(j, w){
                if(j > 0 && mask & (1 << (j-1))) (dp[i+1][j-1] += dp[i][j]) %= MOD;
                else if(j < w-1 && mask & (1 << j)) (dp[i+1][j+1] += dp[i][j]) %= MOD;
                else (dp[i+1][j] += dp[i][j]) %= MOD;
            }
        }
    }

    cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn group_by_same(v: Vec<u32>) -> Vec<Vec<u32>> {
    let mut groups = Vec::new();
    let mut group = Vec::new();
    group.push(v[0]);
    for i in 1..v.len() {
        if v[i - 1] != v[i] {
            groups.push(group);
            group = Vec::new();
        }
        group.push(v[i]);
    }
    if !group.is_empty() {
        groups.push(group);
    }
    groups
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.to();
    let v = (0..n).map(|_| iter.to()).collect::<Vec<_>>();
    let mut v1: Vec<u32> = v.iter()
        .enumerate()
        .filter(|&x| x.0 % 2 == 0)
        .map(|x| x.1)
        .cloned()
        .collect();
    v1.sort();
    let mut c1 = group_by_same(v1)
        .into_iter()
        .map(|group| (group.len(), group[0]))
        .collect::<Vec<_>>();
    let mut v2: Vec<u32> = v.iter()
        .enumerate()
        .filter(|&x| x.0 % 2 == 1)
        .map(|x| x.1)
        .cloned()
        .collect();
    v2.sort();
    let mut c2 = group_by_same(v2)
        .into_iter()
        .map(|group| (group.len(), group[0]))
        .collect::<Vec<_>>();

    c1.sort();
    c2.sort();
    let l1 = c1.last().unwrap();
    let l2 = c2.last().unwrap();
    let ans = if l1.1 == l2.1 {
        let l12 = if c1.len() >= 2 { c1[c1.len() - 2].0 } else { 0 };
        let l22 = if c2.len() >= 2 { c2[c2.len() - 2].0 } else { 0 };
        n - std::cmp::max(l1.0 + l22, l2.0 + l12)
    } else {
        n - l1.0 - l2.0
    };

    println!("{}", ans);
}

Measured memory_bytes: 11300
N, M = gets.split.map(&:to_i)
L = N.lcm(M)
S = gets.chomp.chars
T = gets.chomp.chars
S.each_with_index do |s, i|
    if ((L / N) * i % (L / M) == 0 && s != T[(L / N) * i / (L / M)])
        p -1
        exit
    end
end
p L

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

int main()
{
  string S;
  cin >> S;
  for (int i=0; i<3; i++){
    if (S.at(i)=='1') S.at(i)='9';
    else S.at(i)='1';
  }
  cout << S << endl;
}


Measured memory_bytes: 256
h,w,m=map(int,input().split())
item=[list(map(int,input().split())) for i in range(m)]
row=[0]*h
col=[0]*w
for i in range(m):
    x,y=item[i]
    row[x-1]+=1
    col[y-1]+=1
mr,mc=max(row),max(col)
xr=set([i for i in range(h) if row[i]==mr])
xc=set([i for i in range(w) if col[i]==mc])
check=len(xr)*len(xc)
for i in range(m):
    r,c=item[i]
    if r-1 in xr and c-1 in xc:
        check-=1
print(mr+mc if check>0 else mr+mc-1)

Measured memory_bytes: 113492
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;

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

	int n;
	cin >> n;

	int x = (100 * n) / 108;

	if ((x * 108) / 100 == n) {
		cout << x << "\n";
	}
	else if (((x + 1) * 108) / 100 == n) {
		cout << x + 1 << "\n";
	}
	else {
		cout << ":(" << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

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

  int max = 0;
  int cnt = 0;
  rep(i, n){
    int h;
    cin >> h;
    if(h >= max){
      max = h;
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <utility>
#include <set>

using llint = long long int;
using namespace std;

namespace CsF {
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define FOR(I,J,K) for(int I = 0;I < J;I+=K)

	string ConvertBit(int N, int e) {
		string s = "";
		int r = 0;
		while (N != 0) {
			r = N % e;
			s = to_string(r) + s;
			N -= r;
			N /= e;
		}
		return s;
	}

	int GCD(int a, int b) {
		if (a < b)swap(a, b);
		int r = a % b;
		while (r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		return b;
	}

	int LCM(int a, int b) {
		int n = a * b;
		return (n / GCD(a, b));
	}

	int Count(string s, char c) {
		int cou = 0;
		FOR(i, s.length(), 1) {
			if (s[i] == c)cou++;
		}
		return cou;
	}

	vector<int> SieveOfEratosthenes(int N) {
		vector<bool> memo(N + 1);
		vector<int> ret;
		memo[0] = true;
		memo[1] = true;
		for (int i = 2; i < N; i++) {
			if (memo[i])continue;
			ret.push_back(i);
			for (int b = 2; true; b++) {
				if (i*b <= N) {
					memo[i*b] = true;
				}
				else break;
			}
		}
		return ret;
	}

	vector<int> SpInput(int N) {
		vector<int> ret(N);
		FOR(i, N, 1) { cin >> ret[i]; }
		return ret;
	}
}

using namespace CsF;


int main() {
	int A, B;
	cin >> A >> B;
	cout << ((A*B) % 2 == 0 ? "No" : "Yes") << "\n";
	return 0;
}



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



const int MOD = 1000000007;

string str1, str2, str3;
long long dp[55][2];

int main() {
    //freopen("/Users/macuser/Documents/Programming/Contest/test.in", "r", stdin);
    while (cin >> str1 >> str2 >> str3) {
        if (str1 == "0") break;
        
        reverse(str1.begin(), str1.end());
        reverse(str2.begin(), str2.end());
        reverse(str3.begin(), str3.end());        
        int n = str3.size();
        
        dp[0][0] = 1; dp[0][1] = 0;
        for (int i = 0; i < n; ++i) {
            int no_no = 0, no_up = 0, up_no = 0, up_up = 0;
            
            int start = 0;
            if (i == n-1) start = 1;
            
            for (int a = start; a < 10; ++a) {
                if (str1[i] != '?' && str1[i] != (char)(a + '0')) continue;
                
                for (int b = start; b < 10; ++b) {
                    if (str2[i] != '?' && str2[i] != (char)(b + '0')) continue;
                    
                    for (int c = start; c < 10; ++c) {
                        if (str3[i] != '?' && str3[i] != (char)(c + '0')) continue;
                        
                        if (a + b == c) ++no_no;
                        else if (a + b + 1 == c) ++up_no;
                        else if (a + b == c + 10) ++no_up;
                        else if (a + b + 1 == c + 10) ++up_up;
                    }
                }
            }
            
            dp[i+1][0] = (dp[i][0] * no_no + dp[i][1] * up_no) % MOD;
            dp[i+1][1] = (dp[i][0] * no_up + dp[i][1] * up_up) % MOD;
        }
        
        cout << dp[n][0] << endl;
    }              
    
    return 0;
}


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

void dump(vector<int> &data, string name) {
  cout << name << "= { ";
  for(int i = 0; i<data.size(); i++)
    cout << data[i] << " ";
  cout << "} " << endl;
}

int main() {
  int l, r;
  cin >> l >> r;
  if(r-l+1 >= 2019){
    cout << 0 << endl;
    return 0;
  }
  if(l/2019 < r/2019){
    cout << 0 << endl;
    return 0;
  }
  int s = l % 2019;
  vector<int> v(r-l+1);
  rep(i,r-l+1) v[i] = s+i;
  int n = v.size();
  int ans = 2018;
  for(int i = 0; i<n-1; i++) {
    for(int j = i+1; j<n; j++) {
      int candi = (v[i]*v[j]) % 2019;
      if (candi < ans)
	ans = candi;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;
const int N = 3e5 + 500;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;

long long n, m, u, v, k, t, q, a, h, x;


int main() {
   ios::sync_with_stdio(false);cin.tie(0);
   cin >> n >> k;
   n -= k;
   
   if (k == 1) n = 0;
   
   cout << n << endl;
}






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

int main(void){
  long long int a,b,x,c=0;
  cin >> a >> b >> x;
  if(a==0){
    c=1;
    if(x==1) c=0;
  }
  cout << (b/x)-((a-1)/x)+c << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 100000
 
typedef struct pp{
  char name[100];
  int time;
}Process;

 
int head, tail, n, c=0, q;
Process Q[N];


void enqueue(){
  Q[head].time = Q[head].time -q;
  Q[tail] = Q[head];
  if(tail > n+1) tail = 0;
  else tail++;
}
 
void dequeue(){
  printf("%s %d\n",Q[head].name, Q[head].time+c);
}
 
int main(){
  int i;
   
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }
  head = 1;
  tail = n+1;
  i = 1;
  while(head != tail){
    if(Q[head].time > q){
    enqueue();
    c = c + q;
    }
    else{
      dequeue();
      c = c + Q[head].time;
    }
  if(head > n+1) head = 0;
  else head++;
  }
  return 0;
}

Measured memory_bytes: 6744
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt, sum int = 0, 0, 0

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	K, _ := strconv.Atoi(read())

	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i], _ = strconv.Atoi(read())
	}
	dp := make([]int, N+5)
	for i := 1; i < N+5; i++ {
		dp[i] = 1e9
	}

	for i := 0; i < N; i++ {
		for j := i + 1; j < min(i+K+1, N); j++ {
			t := dp[i] + abs(h[i]-h[j])
			dp[j] = min(dp[j], t)
		}
	}
	fmt.Println(dp[N-1])
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; 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
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] > h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 2816
from math import floor, sqrt
from collections import defaultdict
from math import gcd
def factors(n):
    d = defaultdict(int)
    for i in range(2,floor(sqrt(n))+1):
        while n % i == 0:
            n //= i
            d[i] += 1
        if n == 1:
            break
    if n != 1:
        d[n] += 1
    return d

A,B = map(int,input().split())
N = gcd(A,B)
fac = factors(N)
print(len(fac)+1)

Measured memory_bytes: 9476
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100100;
string s, t;
int n, m;
int gcd(int a, int b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> m;
	cin >> s >> t;
	int x = gcd(n, m);
	for(int i = 0; i < x; i ++)
		if(s[i * n / x] != t[i * m / x])
		{
			cout << "-1" << endl;
			return 0;
		}
	cout << 1ll * n * m / x << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

void printMatrix(vvi a){
    rep(i,a.size()){
        rep(j,a[0].size())cout << a[i][j] << " " ;
        cout << endl;
    }
}

vvi product(vvi a, vvi b, int mod){//ret = a * b % mod
    vvi ret(a.size(), vi(b[0].size(),0));
    rep(i,a.size())rep(j,b[0].size()){
        rep(k,a[0].size()) (ret[i][j] += a[i][k]*b[k][j]) %= mod;
    }
    return ret;
}


vvi powMatrix(vvi a, int t, int mod){// A^t % mod
    int n = a.size();

    vvi ret(n, vi(n,0));
    rep(i,n)ret[i][i] = 1; // 単位行列

    while(t > 0){ //繰り返し自乗法
        if(t&1) ret = product(ret, a, mod);
        a = product(a,a, mod);
        t = t >> 1;
    }
    return ret;
}

signed main(void) {
    int l,a,b,m;
    cin >> l >> a >> b >> m;
    int now = 0;//項数
    vvi x(3,vi(3,0));
    x[0][1] = x[1][1] = x[2][2] = 1;
    x[1][2] = b%m;
    x[0][0] = 10;
    vvi y(3,vi(1,0));
    y[1][0] = a%m;
    y[2][0] = 1;
    loop(keta,1,19)if(now < l){
        if(to_string(a+b*now).size() > keta){
            x[0][0] *= 10;
            continue;
        }
        x[0][0] %= m;
        int ok = 0, ng = l+1;
        //桁がketa以下となるような最大の項を探す
        while(ng - ok > 1){
            int mid = (ok + ng)/2;
            string s = to_string(a + b * mid);
            if(s.size() <= keta)ok = mid;
            else ng = mid;
        }
        //cout << "桁" << keta << "　ok=" << ok << ",ng=" << ng << endl;
        if(ok < now)break;
        if(l <= ok)ok = l-1;
        //[now, ok]について計算する
        y = product(powMatrix(x, ok-now+1, m), y, m);
        now = ok+1;
        x[0][0] *= 10;
        //cout << "桁" << keta << " 次の項" << now << " 今の答え" << y[0][0] << endl;
        //printMatrix(x);
        //printMatrix(y);
        //cout << endl;
    }
    cout << y[0][0] << endl;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

R, G, B, N = map(int, input().split())

ans = 0

for i in range(N + 1):
    for j in range(N + 1):
        k = (N - i * R - j * G) / B
        if k.is_integer() and k >= 0:
            # print(i, j, k)
            ans += 1

print(ans)


Measured memory_bytes: 41068