akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
-- https://qiita.com/drken/items/cce6fc5c579051e64fab#abc-087-d-people-on-a-line の Haskell 実装
import           Control.Monad         (forM_, when)
import           Control.Monad.ST      (ST, runST)
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust)
import           Data.Vector.Mutable   (STVector)
import qualified Data.Vector.Mutable   as MV

main :: IO ()
main = do
  [n, m] <- readInts <$> BS.getLine
  lrds <- map readInts . BS.lines <$> BS.getContents
  putStrLn $ if solve n m lrds then "Yes" else "No"

solve :: Int -> Int -> [[Int]] -> Bool
solve n _ lrds = runST $ do
  wuf <- create n 0 :: ST s (WeightedUnionFind s Int)
  allM (solve' wuf) lrds

solve' :: WeightedUnionFind s Int -> [Int] -> ST s Bool
solve' wuf [l, r, d] = do
  let (l', r') = (l - 1, r - 1)
  f <- find wuf l' r'
  if f
    then do
      d' <- diff wuf l' r'
      return $ d' == d
    else do
      _ <- unite wuf l' r' d
      return True
solve' _ _ = undefined

allM :: (Monad m) => (a -> m Bool) -> [a] -> m Bool
allM _ []     = return True
allM p (x:xs) = do
  q <- p x
  if q
    then allM p xs
    else return False

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readInts :: BS.ByteString -> [Int]
readInts = map readInt . BS.words

-- WeightedUnionFind
data WeightedUnionFind s a = WeightedUnionFind
  { par  :: STVector s Int
  , rank :: STVector s Int
  , dw   :: STVector s a
  }

create :: Int -> a -> ST s (WeightedUnionFind s a)
create n w = do
  par' <- MV.new n
  forM_ [0 .. n-1] $ \i ->
    MV.write par' i i
  rank' <- MV.replicate n 0
  dw' <- MV.replicate n w
  return $ WeightedUnionFind par' rank' dw'

root :: Num a => WeightedUnionFind s a -> Int -> ST s Int
root wuf x = do
  px <- MV.read (par wuf) x
  if px == x
    then return x
    else do
      r <- root wuf px
      dwpx <- MV.read (dw wuf) px
      MV.modify (dw wuf) (+ dwpx) x
      MV.write (par wuf) x r
      return r

weight :: Num a => WeightedUnionFind s a -> Int -> ST s a
weight wuf x = root wuf x >> MV.read (dw wuf) x

unite :: Num a => WeightedUnionFind s a -> Int -> Int -> a -> ST s Bool
unite wuf x y w = do
  wx <- weight wuf x
  wy <- weight wuf y
  let w' = w + wx - wy
  x' <- root wuf x
  y' <- root wuf y
  if x' == y'
    then return False
    else do
      rx <- MV.read (rank wuf) x
      ry <- MV.read (rank wuf) y
      let (x'', y'', w'') = if rx >= ry then (x', y', w') else (y', x', -w')
      when (rx == ry) $ MV.modify (rank wuf) (+ 1) x''
      MV.write (par wuf) y'' x''
      MV.write (dw wuf) y'' w''
      return True

find :: Num a => WeightedUnionFind s a -> Int -> Int -> ST s Bool
find wuf x y = (==) <$> root wuf x <*> root wuf y

diff :: Num a => WeightedUnionFind s a -> Int -> Int -> ST s a
diff wuf x y = (-) <$> weight wuf y <*> weight wuf x


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string t = "AKIHABARA";
	REP(i, s.size()) {
		if (s[i] != t[i]) {
			if (t[i] == 'A') {
				s.insert(i+s.begin(),'A');
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	if (s == "AKIHABARA"||s=="AKIHABAR")cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli k;
    cin>>k;
    lli sum=0;
    for(lli i=1;i<=k;i++){
    	for(lli j=1;j<=k;j++){
    		for(lli l=1;l<=k;l++){
    			sum=sum+__gcd(i,__gcd(j,l));
			}
		}
	}
	cout<<sum;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;


int main(){
  int n,x;
  cin >> n >> x;
  vector<int> vec(n);
  
  rep(i,n){
    int a;
    cin >> a;
    vec[i] = abs(x-a);
  }
  
  int d = vec[0];
  
  for (int i = 1; i < n; i++){
    d = __gcd(d,vec[i]);
  }
  
  cout << d;

  return 0;
}

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

long long n, k, l=0, a[20], ans=0;


int main(){

cin >> n;
while(n>0){
    k=n%10;
    n/=10;
    ans+=k;
    a[l++]=k;
}

ans = max(ans, (l-1)*9 + a[l-1]-1);
cout << ans << endl;


return 0;}


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

int a, b;

int main(void){
    
    scanf("%d %d", &a, &b);
    printf("%d\n", (a <= b) ? a : a - 1);
    
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] ={ 1,0,-1,0 };
int dy[4] ={ 0,1,0,-1 };

int N;
ll A[200000], sum[200001];

int solve(int L, int R){
	int l = L;
	int r = R;
	while(r-l > 1){
		int m = (l+r)/2;
		if(sum[m-1]-sum[L-1] <= sum[R-1]-sum[m-1]) l = m;
		else r = m;
	}
	return l;
}

signed main() {
	cin >> N;
	rep(i, N) cin >> A[i];
	sum[0] = 0;
	rep(i, N) sum[i+1] = sum[i] + A[i];

	ll ans = LLONG_MAX;
	for(int m=2; m<N-1; m++){
		int l = solve(0+1, m+1)-1;
		int r = solve(m+1, N+1)-1;
		
		ll tmp1 = max({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] })
			- min({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] });
		l++;
		ll tmp2 = max({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] })
			- min({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] });
		r++;
		ll tmp3 = max({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] })
			- min({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] });
		l--;
		ll tmp4 = max({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] })
			- min({ sum[l], sum[m]-sum[l], sum[r]-sum[m], sum[N]-sum[r] });
		ans = min({ ans, tmp1, tmp2, tmp3, tmp4 });
	}
	cout << ans << endl;
}

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

int coin[6] = {500,100,50,10,5,1};

int main(){

    int input,money,ans;

    while(1){
      cin >> input;
      if(input == 0){
        break;
      }
      money = 1000 - input;

      ans = 0;

      for(int i=0;i<6;i++){
        ans += money/coin[i];
        money = money % coin[i];
        if(money==0){
          break;
        }
      }
      cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 3064
n, m, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(k)]
con = [1 for _ in range(n+1)]
uni = [-1 for i in range(n+1)]
rank = [0 for _ in range(n+1)]

def root(num, pea):
    if pea[num] < 0:
        return num
    else:
        pea[num] = root(pea[num], pea)
        return pea[num]

for i in range(m):
    a, b = ab[i]
    con[a] += 1
    con[b] += 1
    root_a = root(a, uni)
    root_b = root(b, uni)
    if root_a!=root_b:
        if rank[root_a] < rank[root_b]:
            uni[root_b] += uni[root_a]
            uni[root_a] = root_b
        else:
            uni[root_a] += uni[root_b]
            uni[root_b] = root_a
            if rank[root_a] == rank[root_b]:
                rank[root_a] += 1


for i in range(k):
    c, d = cd[i]
    if root(c, uni) == root(d, uni):
        con[c] += 1
        con[d] += 1

result = []
for i in range(1, n+1):
    root_i = root(i, uni)
    result.append(-uni[root_i]-con[i])
print(*result)


Measured memory_bytes: 60504
#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 all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size();
  vector<int> a(n+1);
  rep(i, n) a[i] = s[n-1-i] - '0';
  a[n] = 0;
  vector<int> b(n+1);
  b = a;

  int sum = 0;
  rep(i, n){
    if(a[i] == 5 && a[i+1] >= 5){
      sum += 10-a[i];
      a[i] = 0;
      a[i+1]++;
    }
    else if(6<= a[i] && a[i] <= 10){
      sum += 10-a[i];
      a[i] = 0;
      a[i+1]++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 9220
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>

#define INFINITY 2000000000

using namespace std;

int main(){

	int V,E,from,to,dist;

	scanf("%d %d",&V,&E);
	long long int table[V][V];

	for(int i = 0; i < V; i++){
		for(int k = 0; k < V; k++){
			if(i != k){
				table[i][k] = INFINITY;
			}else{
				table[i][k] = 0;
			}
		}
	}

	for(int i = 0; i < E; i++){
		scanf("%d %d %d",&from,&to,&dist);
		table[from][to] = dist;
	}

	for(int k = 0; k < V; k++){
		for(int i = 0; i < V; i++){
			if(table[i][k] == INFINITY)continue;
			for(int j = 0; j < V; j++){
				if(table[k][j] == INFINITY)continue;
				table[i][j] = min(table[i][j],table[i][k]+table[k][j]);
			}
		}
	}

	bool FLG = true;

	for(int i = 0; i < V; i++){
		if(table[i][i] < 0){
			FLG = false;
			break;
		}
	}

	if(!FLG)printf("NEGATIVE CYCLE\n");
	else{
		for(int i = 0; i < V; i++){
			if(table[i][0] == INFINITY)printf("INF");
			else{
				printf("%lld",table[i][0]);
			}

			for(int k = 1;k < V; k++){
				if(table[i][k] == INFINITY)printf(" INF");
				else{
					printf(" %lld",table[i][k]);
				}
			}
			printf("\n");
		}
	}

    return 0;
}


Measured memory_bytes: 2828
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
map<string, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, ans, cnt, sum[5000][5000], a[210000], b[210000]; 
string str;
bool f;
char c[1100][1100];
int main() {
	cin >> n>>m;
	cin >> str;
	str[m - 1] = str[m - 1] + 'a' - 'A';
	cout << str << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N;
  cin >> N;
  vector<pair<int64, int64>> vp;
  int64 a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    vp.push_back(make_pair(a, b));
  }
  sort(vp.begin(), vp.end(), [](const auto& x, const auto& y) {
    if (x.first - y.second > y.first - x.second)
      return true;
    else
      return false;
  });
  debug(vp);
  int64 T = 0;
  int64 A = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      T += vp[i].first;
    } else {
      A += vp[i].second;
    }
  }
  cout << T - A << endl;
  return 0;
}

Measured memory_bytes: 5352
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};
vector<pii>g[maxn];
int c[maxn];
bool used[maxn];
int mx;
void dfs(int v,int col){
    used[v]=1;
    int color=0;
    for(auto to:g[v]){
        mx=max(mx,(int)g[v].size());
        if(used[to.F]==0){
            color++;
            if(color==col){
                color++;
            }
            c[to.S]=color;
            dfs(to.F,color);
        }
    }
}
int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1,u,v;i<=n-1;i++){
        cin>>u>>v;
        g[u].pb({v,i});
        g[v].pb({u,i});
    }
    dfs(1,0);
    cout<<mx<<"\n";
    for(int i=1;i<=n-1;i++){
        cout<<c[i]<<"\n";
    }
    exit(0);
}


Measured memory_bytes: 9856
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n,b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define sf(i,s) for(ll i=0;s[i]!='\0';i++)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define inf 1e18
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tr(v,i) for(typeof(v).begin() i = v.begin(); i != v.end(); i++)
#define pre(v,x) (v.find(x) != v.end())
#define vpre(v,x) (find(all(v),x) != v.end())
#define gcd(x,y) __gcd(x,y)
#define bc(x) __builtin_popcountll(x)
//cin.ignore(1, '\n');
ll power(ll a, ll b)
{
    if (b == 0)
        return 1;
    if (b == 1)
        return a % mod;
    else
    {
        ll t = power(a, b / 2);
        if (b % 2 == 0)
            return ((t % mod) * (t % mod)) % mod;
        else
            return ((((t % mod) * (t % mod)) % mod) * ((a % mod) % mod)) % mod;
    }
}
void solve()
{
  ll n1,i,hcf,c=0,j;
  map<ll,ll>m;
  cin>>n1;
  ll a[n1+1];
  f(i,0,n1)
  {
      cin>>a[i];
  }
  f(j,0,n1)
  {
      ll n=a[j];
      m[n]++;
      if(n!=1&&m[n]>1)
      {
      c=1;
      break;
      }
      for( i=2;i*i<=n;i++)
      {
          if(n%i==0)
          {
              if(i==n/i)
              {
                  m[i]++;
                  if(m[i]>1)
                  {
                      c=1;
                      break;
                  }
              }
              else
              {
              m[i]++;
              if(m[i]>1)
              {
                  c=1;
                  break;
              }
              m[n/i]++;
              if(m[n/i]>1)
              {
                  c=1;
                  break;
              }
              }
          }
      }
      if(c==1)
      {
          break;
      }
  }
  if(c!=1)
  {
      cout<<"pairwise coprime";
  }
  else
  {
      hcf=a[0];
      for(i=1;i<n1;i++)
      {
          hcf=gcd(hcf,a[i]);
      }
      if(hcf==1)
      cout<<"setwise coprime";
      else
      {
          cout<<"not coprime";
      }
  }
  
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
  //  cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    vector<long long> v(2020, 0);
    long long curr = 0;
    long long p = 1;
    v[0]++;
    reverse(s.begin(), s.end());
    for (auto &x: s) {
        curr = curr + (x - '0') * p;
        p = p * 10 % 2019;
        curr %= 2019;
        v[curr]++;
    }
    long long ans = 0;
    for (auto &x: v) {
        ans += x * (x-1) / 2;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    while (true) {
        ll A, B, P;
        cin >> A >> B >> P;
        if (A == 0 and B == 0 and P == 0) { break; }
        const ll NUM = B - A + 1;
        auto dig = [](const ll n) {
            int ans = -1;
            for (ll num = 1; num <= n; ans++, num *= 10) {}
            return ans;
        };
        const int MAXD = dig(B);
        auto lower = [](const ll n, const int dig) {
            ll ans = n;
            for (int i = 0; i < dig; i++) { ans *= 10; }
            return dig == 0 ? ans + 1 : ans;
        };
        auto upper = [&](const int dig) {
            ll ans = 1;
            for (int i = 0; i <= dig; i++) { ans *= 10; }
            return min(ans, B + 1);
        };
        vector<ll> dp(NUM, 0);
        vector<ll> accum(NUM, 0);
        auto accumulate = [&](const int l, const int r) { return (l >= r or r > NUM) ? 0LL : (accum[l] + P - (r == NUM ? 0 : accum[r])) % P; };
        for (int i = NUM - 1; i >= 0; i--) {
            const ll num = i + A;
            const int d = dig(num);
            ll sum = 1;
            for (int t = d; t <= MAXD; t++) {
                const ll u = upper(t) - A, l = lower(num, t - d) - A;
                (sum += accumulate(l, u)) %= P;
            }
            dp[i] = sum, accum[i] = ((i == NUM - 1 ? 0 : accum[i + 1]) + sum) % P;
        }
        cout << accum[0] << endl;
    }
    return 0;
}



Measured memory_bytes: 4404
N = int(input())
A = [int(x) for x in input().split()]

minus = 0
for i in range(N):
    if A[i] < 0:
        minus += 1
        A[i] *= -1
if minus % 2 == 0:
    print(sum(A))
else:
    print(sum(A) - min(A)*2)

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

#define debug 0

using namespace std;
typedef long long lint;

const int maxn = 1e2+5;

struct pr
{
    lint x, y;
};

lint n, i, j, h;
pr v[maxn]; lint b[maxn];

inline lint ab(lint x) { return (x < 0 ? -x: x); }
inline lint dist(pr x, pr y) { // manhattan
    return ( ab(x.x - y.x) + ab(x.y - y.y) );
}

int main()
{
    #if debug
    freopen("f.in", "r", stdin);
    freopen("f.out", "w", stdout);
    #endif

    cin >> n;
    for(i = 1; i <= n; i ++) {
        cin >> v[i].x >> v[i].y >> b[i];
    }

    for(i = 0; i <= 100; i ++) {
        for(j = 0; j <= 100; j ++) {

            bool ok = true;
            lint height = -1;
            for(h = 1; h <= n && ok == true; h ++) {
                if(b[h] != 0)
                {
                    if(height == -1) {
                        height = (dist({i, j}, v[h])) + b[h];
                    } else
                    if((dist({i, j}, v[h])) + b[h] != height) {
                    ok = false;
                    }
                }
            }

            if(ok == true)
            {
                for(h = 1; h <= n && ok == true; h ++) {
                    if(b[h] == 0) {
                        if(height - dist({i, j}, v[h]) > 0) {
                            ok = false;
                        }
                    }
                }
            }

            if(ok == true) {
                cout << i << ' ' << j << ' ' << height << '\n';
                return 0;
            }

        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		String N = sc.next();
		String answer = null;
		switch (N) {
		case "A":
			answer = "T";
			break;
		case "T":
			answer = "A";
			break;
		case "C":
			answer = "G";
			break;
		case "G":
			answer = "C";
			break;
		}

		System.out.println(answer);

	}
}


Measured memory_bytes: 22484
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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






int main(void) 
{
	int N;
	cin >> N;
	if ((N / 90) || N%10 == 9) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main()
{
	int N = 0;
	double ans = 0;
	std::cin >> N;

	std::vector<double> V(N);

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

	std::sort(V.begin(), V.end());
	ans = V[0];
	for (int i = 1; i < N; i++){
		ans = (V[i] + ans) / 2;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    int d, t, s;
    cin >> d >> t >> s;

    int x = t * s;
    if(x >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+100;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)
#define pb push_back

int n,a[N];
char sgn[N];
ll f[N][2];
ll ans;
ll ssum[N];
/*
5
1 - 20 - 13 + 14 - 5
*/

int main(){
   ios::sync_with_stdio(false);
   ans = -0x3f3f3f3f;
   cin >> n;
   fr(i,1,n){
      if(i > 1)cin >> sgn[i]; cin >> a[i];
      if(sgn[i] == '-')a[i] = -a[i];
   }

   ssum[n+1] = 0;
   nfr(i,n,1)ssum[i] = ssum[i+1]+abs(a[i]);

   memset(f,0xf7,sizeof f);
   f[0][0] = 0;
   fr(i,1,n){
      f[i][0] = max(f[i-1][0]+a[i],f[i-1][1]+a[i]);
      f[i][1] = f[i-1][1]-a[i];
      if(sgn[i] == '-')f[i][1] = max(f[i][1],f[i-1][0]+a[i]);
      if(sgn[i] == '-' && i > 2)ans = max(ans,f[i-1][1]+ssum[i]);
   }
   ans = max(ans,max(f[n][0],f[n][1]));
   printf("%lld\n",ans);
   return 0;
}


Measured memory_bytes: 3072
#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::vector<int> a(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        while(a[i] % 2 == 0) {
            a[i] /= 2;
            count++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import re
n, k = map(int, sys.stdin.readline().split())
S = sys.stdin.readline()

ptnr = 'R+'
ptnr = re.compile(ptnr)
ptnl = 'L+'
ptnl = re.compile(ptnl)

if len(ptnl.findall(S)) <=len(ptnr.findall(S)):
    f = 'L'
else:
    f = 'R'

score = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        score+=1

idx = []
for i in range(n):
    if S[i] == f:
        idx.append(i)
idx.append(-10)

s =-1
e =-1
ten = [0]
for i in range(len(idx)-1):
    if s ==-1:
        s = idx[i]
    if idx[i]+1 != idx[i+1]:
        e = idx[i]
        if s==0 and e ==n-1:
            pass
        elif s ==-1 or e==-1:
            pass
        elif s ==0 or e ==n-1:
            ten.append(1)
        else:
            ten.append(2)
        s =-1
ten = sorted(ten, reverse=True)
print(score+ sum(ten[0:k]))


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

int main(){
  string s, t;  cin >> s >> t;
  int slen = s.size(), tlen = t.size();
  
  int ans = 1e9;
  for(int i=0; i<slen-tlen+1; i++){
    int thisans = 0;
    for(int j=0; j<tlen; j++){
      if(t[j] != s[i+j])  thisans++;
    }
    ans = min(ans, thisans);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int N, K; cin >> N >> K;
    vi v(N); rep (i, N) cin >> v[i];
    vi dp(N, INF); dp[0] = 0;

    rep (i, N) {

        for (int j = max(0, i-K); j < i; ++j) {
            dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]);
            // cout << dp[i] << endl;
        }
        // cout << endl;
    }
    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define print(x) cout << x << "\n"

int main() {
    fastcin;
    int n, k, a, mi, ans = 1000000007;
    cin >> n >> k;
    rep(i, 0, n) {
        cin >> a;
        if(a==1) mi = i+1;
    }
    rep(i, 0, k) {
        int ta = 1;
        int lb = mi-k+i;
        int lf = n-mi-i;
        if(lb>0) {
            ta += lb/(k-1);
            if(lb%(k-1)!=0) ta++;
        }
        if(lf>0) {
            ta += lf/(k-1);
            if(lf%(k-1)!=0) ta++;
        }
        ans = min(ans, ta);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
const long long int MOD = 1000000007;
const int INF = 1000000000;

int n, m;
set<vector<int> > ho, ge;
set<vector<int> >::iterator it;
int ans = 0;
bool saw[100];
int ed[100][100];

int main(){
    cin >> n >> m;
    rep(i,m){
        int f, t, c;
        cin >> f >> t >> c;
        f--; t--;
        if(f > t) swap(f,t);
        ed[f][t] = c; ed[t][f] = c;
        vector<int> tmp;
        tmp.push_back(f); tmp.push_back(t);
        ho.insert(tmp);
        ans = max(ans,c*2);
    }
    while(true){
        ge.clear();
        for(it = ho.begin(); it != ho.end(); it++){
            vector<int> tmp = (*it);
            memset(saw,0,sizeof(saw));
            rep(i,tmp.size()) saw[tmp[i]] = true;
            rep(i,n){
                if(saw[i]) continue;
                bool ok = true;
                rep(j,tmp.size()){
                    if(ed[i][tmp[j]] == 0){
                        ok = false;
                        break;
                    }
                }
                if(!ok) continue;
                vector<int> foge = tmp;
                foge.push_back(i);
                sort(foge.begin(),foge.end());
                ge.insert(foge);
                int cnt = 0;
                rep(j,foge.size()){
                    int mi = INF;
                    rep(k,foge.size()){
                        if(j == k) continue;
                        mi = min(mi,ed[foge[j]][foge[k]]);
                    }
                    cnt += mi;
                }
                ans = max(ans,cnt);
            }
        }
        ho = ge;
        if(ge.size() == 0) break;
    }
    cout << ans << endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int a, b, c;cin >> a >> b >> c;
    int x;cin >> x;
    int ans = 0;
    inc(i, 0, a+1){
        inc(j, 0, b+1){
            inc(k, 0, c+1){
                if(500*i+100*j+50*k == x) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int N, M, D;

	while (true)
	{
		scanf("%d", &N);
		scanf("%d", &M);

		if (N == 0 && M == 0) { break; }

		vector<int> C; C.push_back(0);

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &D);

			if (D <= M)
			{
				C.push_back(D);
			}
		}

		vector<int> r;

		for (int i = 0; i < C.size(); i++)
		{
			for (int j = i; j < C.size(); j++)
			{
				if (C[i] + C[j] <= M)
				{
					r.push_back(C[i] + C[j]);
				}
			}
		}

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

		int ret = 0, lc = 0, rc = r.size() - 1;

		while (rc - lc >= 0)
		{
			if (r[lc] + r[rc] > M)
			{
				rc--;
			}
			else
			{
				ret = max(ret, r[lc++] + r[rc]);
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 6788
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int T, X;

int main(void)
{
  cin >> T >> X;
  printf("%.10f\n", (double)T / X);
  return 0;
}


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

int main()
{
	int n, m;
	while (cin >> n >> m, n | m) {
		vector<int> K(n), sum(n), rsum(n);
		for (int i = 0; i < n; i++) {
			ll tmp;
			cin >> tmp;
			K[i] = tmp % m;
		}
		sum[0] = K[0];
		rsum[0] = (m - sum[0]) % m;
		for (int i = 1; i < n; i++) {
			sum[i] = (sum[i - 1] + K[i]) % m;
			rsum[i] = (m - sum[i]) % m;
		}
		int res = sum[0];
		set<int> s;
		for (int i = 1; i < n; i++) {
			s.insert(rsum[i - 1]);
			auto ub = s.upper_bound(rsum[i] - 1);
			if (ub != s.begin()) {
				ub--;
				res = max(res, *ub + sum[i]);
			}
			else {
				res = max(res, sum[i]);
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

struct point {
	int x;
	int y;
	int time;
}points[100100];

bool cmp(point a, point b) {
	return a.time < b.time;
}

int main() {
	int flag = true;
	int N;
	cin >> N;
	points[0].x = 0;
	points[0].y = 0;
	points[0].time = 0;
	for (int i = 1; i <= N; i++) {
		cin >> points[i].time >> points[i].x >> points[i].y;
	}

	sort(points, points + N + 1, cmp);

	for (int i = 0; i < N; i++) {
		int p_time = points[i + 1].time - points[i].time;
		int p_x = points[i + 1].x - points[i].x;
		int p_y = points[i + 1].y - points[i].y;
		if (p_time >= p_x + p_y && (p_time - p_x - p_y) % 2 == 0) {
		
		}
		else {
			flag = false;
			break;
		}
	}

	if (flag)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

int n;
ll a[N];
ll dp[N][3];
bool used[N][3];

ll calc(int pos,int can_go){
	if(pos>=n){
		if(can_go==2) return -oo;
		else return 0;
	}
	if(used[pos][can_go]) return dp[pos][can_go];
	used[pos][can_go]=1;
	dp[pos][can_go]=-oo;
	for(int step=0;step<=can_go&&pos+step<n;++step){
		dp[pos][can_go]=max(dp[pos][can_go],a[pos+step]+calc(pos+step+2,can_go-step));
	}
	return dp[pos][can_go];
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	memset(used,0,sizeof(used));
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	ll ans=calc(0,n%2+1);
	cout<<ans;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = 0, ans1 = 0;
  if (k % 2 != 0) {
    for (int i = 1; i <= n; ++i)
      if (i % k == 0) ans++;
    cout << (ll)pow(ans, 3) << endl;
    return 0;
  } else {
    for (int i = 1; i <= n; ++i)
      if (i % k == k / 2)
        ans++;
      else if (i % k == 0)
        ans1++;
    cout << (ll)(pow(ans, 3) + pow(ans1, 3)) << endl;
    return 0;
  }
  // for (int i = 1; i <= n; ++i) {
  //   for (int j = 1; j <= n; ++j) {
  //     for (int l = 1; l <= n; ++l) {
  //       if ((i + j) % k == 0 && (i + l) % k == 0 && (l + j) % k == 0) ans++;
  //     }
  //   }
  // }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 int H, W;
 int seen[10000][10000];
  char S[10000][10000];
vector<pair<ll, ll>> prime_factorize(ll n) { //素因数分解と各素数の個数
    vector<pair<ll, ll>> res;

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
        {
            continue;
        }
        int num = 0;
        
        while (n % i == 0)
        {
            ++num;
            n /= i;
        }
        res.push_back(make_pair(i, num));
       
    }
     if (n != 1) 
        {
            res.push_back(make_pair(n, 1));
        }
        return res;
        
} 
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
const int MAX = 510000;
const int MOD = 1000000007;

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

void dfs(int st, int fi) {
  //  cout << st << " " << fi <<  endl;
    if (st < 0 || fi < 0 || st >= H || fi >= W)
    {
        return ;
    }
    if (S[st][fi] == '#')
    {
        return ;
    }

    if (seen[st][fi] == 1)
    {
        return ;
    }
    
    
    if (S[st][fi] == '.')
    {
        seen[st][fi] = 1;
    }
    

    dfs(st + 1, fi);
    dfs(st, fi + 1);
    dfs(st, fi - 1);
    dfs(st - 1, fi);
    
}
int main() {
 int N;
 cin >> N;
 vector<int> a(N), sum(9);
 for(int i = 0; i < N; i++) {
     cin >> a[i];
 }
 int ans = 0;
 for (int i = 0; i < N; i++)
 {
     //cout << 1 << endl;
    if (a[i] >= 1 && a[i] <= 399)
    {
        
        sum[0]++;
       
    }else if (a[i] >= 400 && a[i] <= 799)
    {
        sum[1]++;
       
    }else if (a[i] >= 800 && a[i] <= 1199)
    {
        sum[2]++;
       
    }else if (a[i] >= 1200 && a[i] <= 1599)  
    {
        sum[3]++;
       
    }else if (a[i] >= 1600 && a[i] <= 1999)
    {
        sum[4]++;
       
    }else if (a[i] >= 2000 && a[i] <= 2399)
    {
        sum[5]++;
       
    }else if (a[i] >= 2400 && a[i] <= 2799)
    {
        sum[6]++;
       
    }else if (a[i] >= 2800 && a[i] <= 3199)
    {
        sum[7]++;
       
    }else
    {
        sum[8]++;
    }
    
 }
 for (int i = 0; i < 8; i++)
 {
    if(sum[i] >= 1) ans += 1; 
 }
 if (ans == 0)
 {
     cout << 1 << " " << sum[8] << endl;
     return 0;
 }
 
 cout << ans << " " << ans + sum[8] << endl;
    return 0;


}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define MOD (10e9+7)
 
using namespace std;
 


 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); 
    
    long long n, k;
    cin >> n >> k;
    long long a[n+1] ;
    long long visited[1000000] = {0};
    //visited[1] = 1;
    for(int i = 1; i <= n; i++) cin >> a[i];
    long long  l, i;
    long long idx[n+1] = {0};
    vector <long long> v;
    for(i = 1;  k;  k--){
        if(visited[i]){
            
            l = idx[i];
            break;
        }
        else{
            idx[i] = v.size();
            v.push_back(i);
            visited[i]++;
            i = a[i];
        }
    }
    vector<long long> v2;
    v2.assign(v.begin()+l, v.end());
    int sz = v2.size();
    if(k == 0) cout << i;
    else cout << v2[k%sz];
    



    return 0;
}

Measured memory_bytes: 16580
package main

import (
	"fmt"
	"math"
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var a, b, c, x, y int
	fmt.Scan(&a, &b, &c, &x, &y)

	min := math.MaxInt32
	for i := 0; i <= 100000; i++ {
		p := 2*c*i + a*max(0, x-i) + b*max(0, y-i)
		if p < min {
			min = p
		}
	}

	fmt.Println(min)
}


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

string s;
int d[2019];
int sum, res, pow10=1;

void _input(){
    cin>>s;
}

void _solve(){
    d[0]=1;
    for(int i=s.size()-1; i>=0; --i){
        sum=(sum+(s[i]-'0')*pow10)%2019;
        res+=d[sum];
        ++d[sum];
        pow10=pow10*10%2019;
    }
}

void _output(){
    cout<<res;
}

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

    //freopen("input.inp", "r", stdin);

    _input();
    _solve();
    _output();

    return 0;
}


Measured memory_bytes: 3760
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main() {
	int N;
	cin >> N;
	int ans = INT_MAX;
	REP(i, N) {
		int A, tmp = 0;
		cin >> A;
		while (!(A & 1)) {
			A >>= 1; tmp++;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import numpy as np

N, M, X = map(int, input().split())
CA = []
for _ in range(N):
    Ci, *A = map(int, input().split())
    CA.append((Ci, A))

ans = 10**8
studied = np.array([0] * M)

for i in range(2**N):
    flag = True
    tmp_ans = 0
    studied = np.array([0] * M)
    for j in range(N):
        if i >> j & 1:
            tmp_ans += CA[j][0]
            studied += CA[j][1]
    for study in studied:
        if study < X:
            flag = False
            break
    if flag:
        ans = min(ans, tmp_ans)

if ans == 10**8:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 27224
void main()
{
    long n, x;
    rdVals(n, x);
    long[] l = rdRow;

    long[] d = new long[n+1];
    foreach (i; 1 .. n+1)
    {
        d[i] = d[i-1] + l[i-1];
    }

    long cnt;
    foreach (i; 0 .. n+1)
    {
        if (d[i] <= x) ++cnt;
    }

    cnt.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256