akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pll pair <ll,ll>
#define Mid ((L+R)/2)
#define Left (2*Node)
#define Right (2*Node+1)

using namespace std;

const ll N = 200200;
const ll M = 4 * N;
const ll Inf = 1e18;

ll n;
pll h[N];
ll a[N];
ll Dp[N];
ll SegTree[M];

void Merge(ll Node)
{
    SegTree[Node] = max(SegTree[Left],SegTree[Right]);
}

void Build(ll Node = 1,ll L = 0,ll R = n)
{
    if(L == R)
    {
        SegTree[Node] = Dp[L];
        return ;
    }

    Build(Left,L,Mid);
    Build(Right,Mid+1,R);

    Merge(Node);
}

void Update(ll i,ll Node = 1,ll L = 0,ll R = n)
{
    if(i < L || R < i)  return ;
    if(i <= L && R <= i)
    {
        SegTree[Node] = Dp[i];
        return ;
    }

    Update(i,Left,L,Mid);
    Update(i,Right,Mid+1,R);

    Merge(Node);
}

ll Query(ll i,ll j,ll Node = 1,ll L = 0,ll R = n)
{
    if(j < L || R < i)      return -Inf;
    if(i <= L && R <= j)    return SegTree[Node];

    return max( Query(i,j,Left,L,Mid)
              , Query(i,j,Right,Mid+1,R) );
}

int main()
{
    cin >> n;

    for(ll i = 0; i < n; i++)   scanf("%lld",&h[i].first), h[i].second = i;
    for(ll i = 0; i < n; i++)   scanf("%lld",a+i);

    sort(h,h+n);

    Dp[n] = 0;
    for(ll i = 0; i < n; ++i)   Dp[i] = -Inf;

    Build();

    for(ll i = n - 1; ~i; --i)
    {
        ll idx = h[i].second;

        Dp[idx] = a[idx] + Query(idx+1,n);

        Update(idx);
    }

    ll Ans = -Inf;

    for(ll i = 0; i < n; i++)   Ans = max(Ans,Dp[i]);

    cout << Ans;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

signed main() {
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;
  print(max(a * b, c * d));
}


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

using namespace std;
int main() {
	int n, k;
	cin >> n;
	string s;
	cin >> s;
	cin >> k;
	rep(i, s.size()) {
		if (s.at(i) != s.at(k - 1)) s.at(i) = '*';
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import java.math.RoundingMode

fun main() {
    val a = nextLong().toBigDecimal()
    val b = sc.nextDouble().toBigDecimal()
    println((a * b).setScale(0, RoundingMode.FLOOR).toPlainString())
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(), nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")
fun printString(action: StringBuilder.() -> Unit) = println(buildString(action))

Measured memory_bytes: 38656
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

int main()
{
    // std::cout << std::fixed << std::setprecision(5);
    int a, b, c, d; std::cin >> a >> b >> c >> d;
    int ans = std::min(b, d) - std::max(a, c);
    std::cout << ((ans<0) ? 0 : ans) << std::endl;
    return 0;
}

Measured memory_bytes: 256
function main()
  readline()
  c=zeros(Int,10^5)
  s=0
  for a=map(x->parse(Int,x),split(readline()))
    c[a]+=1
    s+=a
  end
  readline()
  for t=readlines()
    x,y=map(x->parse(Int,x),split(t))
    s+=c[x]*(y-x)
    c[y]+=c[x]
    c[x]=0
    println(s)
  end
end
main()

Measured memory_bytes: 216980
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M,X; cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i,N) {
        cin >> C[i];
        rep(j,M) cin >> A[i][j];
    }

    ll ans = 1e18;
    rep(mask,1<<N) {
        vector<ll> B(M);
        ll val = 0;
        rep(i,N) {
            if (mask&(1<<i)) {
                rep(j,M) {
                    B[j] += A[i][j];
                }
                val += C[i];
            }
        }
        bool ok = true;
        rep(i,M) {
            if (B[i] < X) ok = false;
        }
        if (ok) chmin(ans,val);
    }

    cout << (ans == 1e18 ? -1 : ans) << ln;
}

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

template <typename T>
using Matrix = vector<vector<T>>;

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

    string s; cin >> s;
    const auto n = int(s.size());

    auto f = Matrix<int>(n+2, vector<int>(27, n+1));
    for (auto i = n-1; i >= 0; i--)
    {
        const auto start = s[i]-'a';
        f[i][start] = i+1;
        for (auto c = start+1; c <= 26; c++)
            f[i][c] = f[f[i][c-1]][c-1];
        for (auto c = 0; c < start; c++)
            f[i][c] = f[f[i][26]][c];
    }

    auto children = vector<vector<int>>(n+2);
    children[n+1].push_back(n);
    for (auto i = 0; i < n; i++)
        children[f[i][26]].push_back(i);

    auto time = 0;
    auto start_times = vector<int>(n+2), exit_times = vector<int>(n+2);
    const function<void(int)> dfs = [&](const int v)
    {
        start_times[v] = time++;
        for (const auto c : children[v])
            dfs(c);
        exit_times[v] = time;
    };
    dfs(n+1);

    int Q; cin >> Q;
    for (auto q = 0; q < Q; q++)
    {
        int l, r; cin >> l >> r;
        l--; r--;
        cout << (start_times[r+1] <= start_times[l] && start_times[l] < exit_times[r+1] ? "Yes": "No") << "\n";
    }
}


Measured memory_bytes: 122268
N, M, X, Y= map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))


xx = max(x)
yy = min(y)

if (X >= Y):
    print('War')
elif (xx >= yy):
    print('War')
elif (yy <= X):
    print('War')
elif (Y <= xx):
    print('War')
else:
    print('No War')

Measured memory_bytes: 3064
//abc123_c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>
#define ll long long
#define rep(a,b,c) for(ll i=a;i<b;i+=c)

ll N,A,B,C,D,E;

ll min(ll a, ll b, ll c, ll d, ll e){
    ll x[5]={a,b,c,d,e};
    ll min=1000000000000000;
    for(int i=0;i<5;i++){
        if(x[i]<min){
            min=x[i];
        }
    }
    return min;
}

int main(void){
    scanf("%lld %lld %lld %lld %lld %lld",&N,&A,&B,&C,&D,&E);
    ll lowspeed=min(A,B,C,D,E);
    ll ans;
    if(N<=lowspeed){
        printf("5\n");
    }else {
        if(N%lowspeed==0){
            ans=(N/lowspeed)+4;
        }else {
            ans=(N/lowspeed)+5;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1704
N=int(input())
A=list(map(int,input().split()))
D=0
for i in range(N-1):
  D+=abs(A[i+1]-A[i])
D+=abs(A[0])+abs(A[N-1])

for i in range(N):
  if i==0:
    print(D-abs(A[0])-abs(A[1]-A[0])+abs(A[1]))
  elif i==(N-1):
    print(D-abs(A[N-1])-abs(A[N-1]-A[N-2])+abs(A[N-2]))
  else:
    print(D-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1]))

Measured memory_bytes: 14172
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

long exp_mod(long long a, long long b, long m) {
	long long res = 1;
	while (b > 0) {
		if (b&1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}
	return (long)res;
}

long fact_mod(long n, long m) {
	long long res = 1;
	for (long i=n; i>0; --i)
		res = (res * i)%m;
	return (long)res;
}

long comb_mod(long n, long r) {
	long long res = 1;
	for (long i=0; i<r; ++i)
		res = (res * (n - i) )%MOD;
	return ( res * exp_mod(fact_mod(r, MOD), MOD-2, MOD) ) % MOD;
}

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

struct Pony
{
    long s, t, x;

    Pony(long s_, long t_, long x_)
    {
        s = s_;
        t = t_;
        x = x_;
    }

    bool operator<(const Pony &another) const
    {
        return x < another.x;
    };
};

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

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

  string s;

  cin >> s;

  long giri = 2;
  long an = 1;
  for (long i = 1; i < s.size(); i++) {
    if (s[i] == '1') {
      long tmp = giri;
      giri = (giri * 2) % MOD;
      an = ((an * 3) + tmp) % MOD;
    } else {
      an = (an * 3) % MOD;
    }
  }

  cout << (giri + an) % MOD << endl;
}


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

using namespace std;

int bfs(int sx,int sy,vector<vector<char>>& mat)
{
  int n = mat.size();
  int m = mat[0].size();
  queue<int> qx;
  queue<int> qy;
  queue<int> lv;
  qx.push(sx);
  qy.push(sy);
  lv.push(0);
  int xi[4] = {1,-1,0,0};
  int yi[4] = {0,0,1,-1};
  int ans = 0;
  bool vis[n][m];
  memset(vis,0,sizeof(vis));

  while(qx.size() != 0)
  {
    int x = qx.front(); int y = qy.front(); int l = lv.front();
    qx.pop(); qy.pop(); lv.pop();
    ans = max(ans,l);
    vis[x][y] = true;
    for(int i=0; i<4; i++){
        int xn = x + xi[i];
        int yn = y + yi[i];
        if(xn >= 0 && xn < n && yn >= 0 && yn < m && vis[xn][yn] == false && mat[xn][yn] == '.'){
            vis[xn][yn] = true;
            qx.push(xn);
            qy.push(yn);
            lv.push(l+1);
        }
    }
  }

  return ans;
}

int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<char>> mat(n,vector<char>(m));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++) cin >> mat[i][j];
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(mat[i][j] == '.') ans = max(ans,bfs(i,j,mat));
        }
    }

    cout << ans;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];
    rep(i, k) {
        vi b(n);
        rep(j, n) {
            int l = max(0, j-a[j]), r = min(n-1, j+a[j]);
            b[l]++;
            if (r<n-1) b[r+1]--;
        }
        rep1(j, n-1) b[j] += b[j-1];
        a = b;
        bool ok = true;
        rep(j, n) if (a[j] != n) ok = false;
        if (ok) break;
    }
    rep(i, n) printf("%d%c", a[i], (i<n-1?' ':'\n'));
    return 0;
}


Measured memory_bytes: 4964
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef long long int ll;
typedef long double ld;
using namespace std;
const int M=1e9+7;
#include<iostream> 
#include<climits> 
using namespace std; 
int main() {
    ios;
  ll n,k;cin>>n>>k;
  ll a[n];
  for(ll i=0;i<n;++i)
  {
      cin>>a[i];
  }
  sort(a,a+n);
  if(n<=k)
  cout<<"0";
  else
  {
      ll p=n-k;
      ll s=0;
      for(ll i=0;i<p;++i)
      {
          s+=a[i];
      }
  cout<<s;
  }
}



Measured memory_bytes: 1792
n = int(input())
def prime_judge(p):
    if p == 2 or p == 3:
        return True
    N = int(p**(1/2)) + 1
    for i in range(2, N):
        if p % i == 0:
            return False
    return True
lst = []
print(n,': ', sep = '', end = '')
while n != 1:
    if prime_judge(n):
        lst.append(n)
        break
    else:
        N = int(n ** (1/2)) + 1
        for p in range(2, N):
            if prime_judge(p) and n % p == 0:
                lst.append(p)
                n = n // p
                break
print(*lst)


Measured memory_bytes: 5640
n=int(input())
a=[]
b=[]
for x in range(1,int(-(-n**0.5//1))+1):
    if n%x ==0:
        i=x
        a.append(i)
        j=n//x
        b.append(j)

ans_i=0
ans_j=0
if len(a)==0:
    print(n-1)

else:
    min=abs(a[0]-b[0])
    for i in range(len(a)):
        if min >= abs(a[i]-b[i]):
            min=abs(a[i]-b[i])
            ans_i=a[i]
            ans_j=b[i] 
    print((ans_j-1)+(ans_i-1))

Measured memory_bytes: 3296
# BFS, queue
from collections import deque

h, w = map(int, input().split())
s = [input() for _ in range(h)]

# print(s)

inf = 1001001001
di = [0, -1, 0, 1]
dj = [-1, 0, 1, 0]

def update(i, j, x):
    if dist[i][j] != inf:
        return
    dist[i][j] = x
    q.append([i, j])

ans = 0

for si in range(h):
    for sj in range(w):
        if s[si][sj] == "#":
            continue
        dist = [[inf] * w for _ in range(h)]
        q = deque()



        update(si, sj, 0)
        while q:
            i, j = q.popleft()
            for dir in range(4):
                ni = i + di[dir]
                nj = j + dj[dir]
                if ni < 0 or ni >= h or nj < 0 or nj >= w:
                    continue
                if s[ni][nj] == "#":
                    continue
                update(ni, nj, dist[i][j] + 1)
        for i in range(h):
            for j in range(w):
                if dist[i][j] == inf:
                    continue
                ans = max(ans, dist[i][j])
print(ans)



Measured memory_bytes: 3316
from collections import deque
n=int(input())
x=lambda i:int(i)-1
a=[deque(list(map(x,input().split()))+[-1]) for _ in range(n)] 
tcnt,ans=n*(n-1),0
chk=set(range(n))
while tcnt>0:
    chk_next=set()
    for i in chk:
        if a[a[i][0]][0]==i:
            chk_next.add(i)
    if len(chk_next)==0:
        ans=-1
        break
    tcnt-=len(chk_next)
    chk=set()
    for i in chk_next:
        a[i].popleft()
        chk.add(i)
        if a[i][0]!=-1:
            chk.add(a[i][0])
    ans+=1

print(ans)

Measured memory_bytes: 36084
n,m=map(int,input().split())
r=[set() for i in range(n+1)]
for i in range(m):
    ai,bi=map(int,input().split())
    if not bi in r[ai]:
        r[ai].add(bi)
        r[bi].add(ai)

if len(r[1]&r[n])==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")
    

Measured memory_bytes: 67740
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

int binary_search(ll x, vel a) {
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin();
    } else {
        return -1;
    }
}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll N,sum = 0;
    cin >> N;
    vel A(N);
    REP(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());
    sum = A[0];
    REP(i,N/2 -1){
        sum += 2 * A[i+1];
    }

    if(N % 2 == 0){
        cout << sum << endl;
    } else {
        cout << sum + A[(N-1) / 2] << endl;
    }
}

Measured memory_bytes: 4732
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
ans = 0
for n in range(N):
    A = list(map(int,input().split()))
    x = 0
    for m in range(M):
        x += A[m] * B[m]
    x += C
    if x > 0:
        ans += 1

print(ans)
    

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	for(int i=n;;i++)
	{
		int temp=i;
		int check=0;
		int temp1=0;
		bool haha=0;
		while(temp)
		{
			temp1=temp%10;
			temp/=10;
			if(temp1==0)
			{
				haha=1;
				break;
			}
			if(check!=0&&check!=temp1)
			{
				haha=1;
				break;
			}
			else if(check==0)
			check=temp1;
		} 
		 if(haha==0)
		 {
		 	cout<<i<<endl;
		 	return 0;
		 }
		 else
		 {
		 	temp1=0;
		 	haha=0;
		 	check=0;
		 }
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <deque>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int inf = (int)1e9;
const int mod = inf+7;
	
int a, b, c;

int main(){

	cin >> a >> b >> c;
	int num = a*100 + b*10 + c;

	if(num%4==0){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

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


// 最大公約数を求める
// 計算量O(logn)
template<class T>
T gcd(T a, T b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

// 最小公倍数を求める
// 計算量O(logn)
template<class T>
T lcm(T a, T b){
    return a/gcd(a,b)*b;
}

// 素数判定
// 計算量O(√n)
template<class T>
bool isPrime(T n){
    if(n < 2) return false;
    for(T i = 2; i*i < n; ++i) if(n % i == 0) return false;
    return true;
}

// 素数列挙
// nまでの素数をEratosthenesの篩で列挙する
// 計算量O(nloglogn)
template<class T>
vector<T> prime_list(T n){
    vector<T> ret;
    vector<T> isPrime(n+1,1);
    isPrime[0] = isPrime[1] = 0;
    for(long long i = 2; i <= n; ++i){
        if(isPrime[i] == 0) continue;
        ret.push_back(i);
        for(long long j = i*i; j <= n; j += i) isPrime[j] = 0;
    }
    return ret;
    // return isPrime;  // 状況によってはこっちを返す
}

// 素因数分解
// nを素因数分解してmapに記録
// 計算量O(√nlogn),必要ならmapではなくvectorにすると計算量を落とせる
template<class T>
map<T,int> prime_factor(T n){
    map<T,int> ret;
    if(n <= 0){
        cout << "Prime_factor Error" << "\n";
        return ret;
    }
    for(long long i = 2; i*i <= n; ++i){
        while(n%i== 0){
            ++ret[i];
            n /= i;
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}


// 関数名：pow
// 概要：modつき指数関数
// 第一引数a：指数の底
// 第二引数b：指数
// 第三引数mod：法となる値
// 戻り値：a^b(m mod)
// 計算量O(log b)
template<class T>
T pow(T a, int b){
    if(b == 0) return 1;
    if(b%2){
        T ret = pow(a,(b-1)/2); 
        return ret*ret*a;
    }else{
        T ret = pow(a,b/2);
        return ret*ret;
    }
}

template<class T>
T pow(long long a, long long b, T mod){
    if(b == 0) return 1;
    if(b % 2 == 0){
        T d = pow(a,b/2,mod);
        return (d*d)%mod;
    }else return a%mod*pow(a,b-1,mod)%mod;
}

//関数名：comb
//概要：二項係数
//第一引数n：組み合わせの全体
//第二引数r：何個取り出すか
//第三引数mod：法となる値
//戻り値：nCr(m mod)
// 計算量O(r), 第三引数まで指定するとO(rlogmod)
template<class T>
T comb(T n, T r){
    if(r > n) return 0;
    if(n == r || r == 0) return 1;
    T ret = 1;
    for(T i = 1; i <= r; ++i){
        ret *= n--;
        ret /= i;
    }
    return ret;
}

template<class T>
T comb(long long n,long long r,T mod){
    if(r > n) return 0;
    if(n == r || r == 0) return 1;
    long long fact1 = 1,fact2 = 1;
    for(long long i = n; i >= n-r+1; --i) fact1 = fact1*i%mod;
    for(long long i = r; i >= 1; --i) fact2 = fact2*i%mod;
    return fact1*pow(fact2,mod-2,mod)%mod;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin >> x;
    int ans = 1;
    for(int i = 2; i*i <= x; ++i){
        int a = i*i;
        while(a <= x) a*= i;
        a /= i;
        ans = max(ans,a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 1..(n + 1) {
        if dp1[0][i] < INF {
            println!("{}", i - 1);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, power_only: bool) -> Vec<i64> {
    let mut ans = vec![INF; dp.len() + child1.len() - 1];
    assert_eq!(dp[0], INF);
    assert_eq!(child1[0], INF);
    assert_eq!(child2[0], INF);
    for groups in 0..dp.len() {
        if dp[groups] == INF { continue; }
        for child_groups in 0..child1.len() {
            let total_groups = groups + child_groups;

            if total_groups >= 1 {
                if child1[child_groups] != INF {
                    ch_min(&mut ans[total_groups - 1], dp[groups] + child1[child_groups]);
                }
                if child2[child_groups] != INF && !power_only {
                    ch_min(&mut ans[total_groups - 1], dp[groups] + child2[child_groups]);
                }
            }
            if child1[child_groups] != INF || child2[child_groups] < 0 {
                ch_min(&mut ans[total_groups], dp[groups]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 211836
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll tmp,res=0,N,A[100001],mi=0;
  cin >> N;
  REP(i,N)cin >> A[i];
  REP(i,N){
    if(A[i] == mi+1)
      mi++;
    else if(A[i] == mi)
      continue;
    else{
      res += A[i] % (mi+1) == 0 ? A[i]/(mi+1) - 1 : A[i]/(mi+1);
    }
    if(i == 0)
      mi = 1;
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

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

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



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

static const int MOD=1e9+7;
vector<int> g[100100];
long long ans=1;
int K;

void solve(int u,int pa=-1){
    int res=K-(pa!=-1);
    for(auto v:g[u]){
        if(v==pa) continue;
        res--;
        ans*=res;
        ans%=MOD;
        solve(v,u);
    }
}

int main(){
    int N; cin >> N >> K;
    for(int i=0;i<N-1;i++){
        int a,b; cin >> a >> b; a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ans*=K;
    solve(0);
    cout << ans << endl;
}

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

int read(){
	int a = 0; char c = getchar();
	while(!isdigit(c)) c = getchar();
	while(isdigit(c)){a = a * 10 + c - 48; c = getchar();}
	return a;
}

const int _ = 1e5 + 7;
struct Edge{int end , upEd;}Ed[_ << 1];
int head[_] , cntEd , N , mx , id;

void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd;}

int pre[_]; bool vis[_];
void dfs(int x , int p , int l){
	if(l > mx){mx = l; id = x;}
	pre[x] = p;
	for(int i = head[x] ; i ; i = Ed[i].upEd)
		if(Ed[i].end != p) dfs(Ed[i].end , x , l + 1);
}

int main(){
	N = read();
	for(int i = 1 ; i < N ; ++i){int x = read() , y = read(); addEd(x , y); addEd(y , x);}
	dfs(1 , 0 , 0); int p = id; mx = 0; dfs(p , 0 , 0); int q = id;
	vis[id] = 1; while(id) vis[id = pre[id]] = 1;
	for(int i = 1 ; i <= N ; ++i) if(!vis[i] && !vis[pre[i]]){puts("-1"); return 0;}
	vector < int > node; deque < int > ans1 , ans2; int cnt = 0;
	for(int t = q ; t ; t = pre[t]) node.push_back(t);
	
	for(auto q : node){
		int now = ++cnt , sz = 0;
		for(int i = head[q] ; i ; i = Ed[i].upEd) sz += !vis[Ed[i].end];
		for(int i = now + 1 ; i <= now + sz ; ++i) ans1.push_back(i);
		ans1.push_back(now); cnt += sz;
	}
	
	reverse(node.begin() , node.end()); cnt = 0;
	for(auto q : node){
		int now = ++cnt , sz = 0;
		for(int i = head[q] ; i ; i = Ed[i].upEd) sz += !vis[Ed[i].end];
		for(int i = now + 1 ; i <= now + sz ; ++i) ans2.push_back(i);
		ans2.push_back(now); cnt += sz;
	}

	for(int i = 0 ; i < ans1.size() ; ++i)
		if(ans1[i] < ans2[i]) break;
		else if(ans1[i] > ans2[i]){swap(ans1 , ans2); break;}
	for(auto t : ans1) cout << t << ' ';
	
	return 0;
}

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
	string a, b, c;
	cin >> a >> b >> c;
	char dif ='A'-'a';
    cout<<(char)(a[0]+dif)
        <<(char)(b[0]+dif)
        <<(char)(c[0]+dif)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    int n,w;
    cin >> n>> w;
    long long dp[w+1]={0};//dp[i] means the max value at exactly i weight taken;
    for(int i=0;i<n;i++){
        long long ww,vl;
        cin >> ww >> vl;
        for(int j=w;j>=ww;j--){
            dp[j]=max(dp[j],dp[j-ww]+vl);
            //cout << j << "-> " << dp[j] << endl;
        }
    }
    cout << dp[w] << endl;
}


Measured memory_bytes: 1024
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a:number[]=[];for(let i=0;i<arg;i++) {a.push(t.n());}return a;}else{const a = t.input[0];t.input.shift();return Number(a);}},s:(arg:number=0):any=>{if(arg){const a:string[]=[];for(let i=0;i<arg;i++){a.push(t.s());}return a;}else{const a=t.input[0];t.input.shift();return String(a);}},c:(arg:number=0):any=>{if(arg) {const a:string[]=[];for(let i=0;i<arg;i++) {a.push(t.c());}return a;}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('');}else{t.input.shift();}return String(b);}},o: (...arg)=>{console.log(...arg);},abs:(a)=>{return Math.abs(a);},min:(...a)=>{return Math.min(...a);},max:(...a)=>{return Math.max(...a);},floor:(a)=>{return Math.floor(a);},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b});},desc:(ar:number[])=>{ return ar.sort((a,b)=>{return b-a});},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1]}return arr[arr.length-1];}}
const main = ()=>{
  let [a,b,c] = t.n(3)
  t.o(a==b?c:a==c?b:a)
}
main()

Measured memory_bytes: 7372
h,w=map(int,input().split())
a=[input() for i in range(h)]
dp=[[0]*(w+1) for i in range(h+1)]
mod=10**9+7
# for i in range(h+1):
#     for j in range(w+1):
#         if i==0 or j==0:
#             dp[i][j]=1
dp[0][0]=1
# print(dp)
for i in range(h):
    for j in range(w):
        if j-1>=0:
            if a[i][j-1]!='#':
                dp[i][j]+=dp[i][j-1]%mod
        if i-1>=0:
            if a[i-1][j]!='#':
                dp[i][j]+=dp[i-1][j]%mod
print(dp[h-1][w-1]%mod)

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

#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 FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong gcd(llong a, llong b){
    if(a < b) swap(a, b);
    while(b > 0){
        llong c;
        c = a;
        a = b;
        b = c % b;
    }
    cerr << a << endl;
    
    return a;
}

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int N;
    llong T[110];
    cin >> N;
    for(int i = 1; i <= N; ++i) cin >> T[i];

    llong lcm = T[1];

    for(int i = 2; i <= N; ++i){
        lcm = lcm/gcd(lcm, T[i])*T[i];
    }

    cout << lcm << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


int main(){
    char str1[100], str2[100];
    int n, point[2] = {0}, tmp, i;
    
    scanf("%d", &n);
    
    for(i = 0; i < n;i++){
        scanf("%s %s", str1, str2);
        tmp = strcmp(str1, str2);
        if(tmp == 0)  point[0] += 1, point[1] += 1;
        if ( tmp > 0) point[0] += 3;
        if ( tmp < 0) point[1] += 3;
    }
    
    printf("%d %d\n", point[0], point[1]);
    return 0;
    
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n-1);
  rep(i,n-1){
    cin >> b[i];
  }
  a[0] = b[0];
  a[n-1] = b[n-2];
  for(int i=0;i<n-2;i++){
    a[i+1] = min(b[i],b[i+1]);
  }
  ll goukei = 0;
  rep(i,n){
    goukei += a[i];
  }
  cout << goukei << endl;
}

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

int main(){
  int N, T, c, t, minCost = 1001;
  cin >> N >> T;

  for(int i=0; i < N; i++){
    cin >> c >> t;
    if(c < minCost & t <= T){
      minCost = c;
    }
  }

  if(minCost == 1001){
    cout << "TLE" << endl;
  }else{
    cout << minCost << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <climits>

using std::queue;
using std::min;
const int MAXN=105,MAXV=MAXN<<1,MAXE=MAXV*MAXV;
int n,s,t;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
int he[MAXV],iter[MAXV],dis[MAXV];

struct line{int to,nex,cap;}ed[MAXE<<1];

inline void addE(int u,int v,int cap){
	static int cnt=1;
	ed[++cnt]=(line){v,he[u],cap};
	he[u]=cnt;
}

inline int revE(int i){return i^1;}

int aug(int u,int rest){
	if(u==t) return rest;
	int ret=0;
	for(int &i=iter[u],v,cap,flow;i;i=ed[i].nex){
		v=ed[i].to,cap=ed[i].cap;
		if(dis[v]!=dis[u]+1 || !cap) continue;
		flow=aug(v,min(cap,rest));
		if(flow){
			ed[i].cap-=flow,ed[revE(i)].cap+=flow;
			ret+=flow,rest-=flow;
			if(!rest) return ret;
		}
	}
	if(!ret) dis[u]=-1;
	return ret;
}

inline bool BFS(){
	static queue<int> que;
	memset(dis,-1,sizeof(dis));
	dis[s]=0;
	que.push(s);
	int u;
	while(que.size()){
		u=que.front();
		que.pop();
		for(int i=he[u],v;i;i=ed[i].nex){
			if(!ed[i].cap) continue;
			v=ed[i].to;
			if(dis[v]==-1){
				dis[v]=dis[u]+1;
				que.push(v);
			}
		}
	}
	return dis[t]!=-1;
}

inline int Dinic(){
	int ret=0;
	while(BFS()){
		memcpy(iter,he,sizeof(iter));
		ret+=aug(s,INT_MAX);
	}
	return ret;
}

inline void build(){
	s=n<<1|1,t=s+1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(a[i]<c[j] && b[i]<d[j])
				addE(i,n+j,1),addE(n+j,i,0);
		}
	}
	for(int i=1;i<=n;++i)
		addE(s,i,1),addE(i,s,0);
	for(int i=1;i<=n;++i)
		addE(n+i,t,1),addE(t,n+i,0);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&a[i],&b[i]);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&c[i],&d[i]);
	build();
	printf("%d",Dinic());
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

a,b,c = map(int,input().split())

if a%2==0 and b%2==0 and c%2==0 and (a == b == c):
	print(-1)
	sys.exit()
cnt = 0
while True:
	if a%2==1 or b%2==1 or c%2==1:
		break
	a,b,c = (b+c)//2,(a+c)//2,(b+c)//2
	cnt += 1

print(cnt)

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

int main(void){
    int n;
    cin>>n;
    rep(i,n){
        long long a,b,c;
        cin>>a>>b;
        c = sqrt(a*b);
        if(c*(c+1) < a*b){
            cout<<2*c-1<<endl;
        }else if(a*b == c*c && a!=b){
            cout<<2*c-3<<endl;
        }else{
            cout<<2*c-2<<endl;
        }
    }
    return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while(n > 0) {
  n /= k;
  ans++;
}
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
N, M = map(int, input().split())

dp = [[0 for i in range(N)] for j in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    dp[a-1][b-1] += 1
    dp[b-1][a-1] += 1
    
for i in range(N):
    print(sum(dp[i]))

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

int N;
pii r[110], b[110];
int used[110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> r[i].first >> r[i].second;
  }
  for (int i = 0; i < N; i++) {
    cin >> b[i].first >> b[i].second;
  }
  sort(r, r + N);
  sort(b, b + N);
  int ans = N;
  for (int i = 0; i < N; i++) {
    int pos = -1;
    for (int j = 0; j < N && r[j].first < b[i].first; j++) {
      if (used[j]) continue;
      if (!(r[j].second < b[i].second)) continue;
      if (pos < 0 || r[j].second > r[pos].second) pos = j;
    }
    if (pos < 0) ans--;
    else used[pos] = 1;
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
	int n;
	cin >> n;
	map<int, int> a;
	for(int i=0; i<n; i++){
		int p;
		cin >> p;
		if(a.count(p)==0){
			a[p]=1;
		}else{
			a[p]++;
		}
	}
	
	int ans=0;
	map<int,int>::iterator itr;
	for(itr=a.begin(); itr!=a.end(); itr++){
		if(itr->first < itr->second){
			ans += itr->second - itr->first;
		}else if(itr->first > itr->second){
			ans += itr->second;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4736
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#define lowbit(x) (x&(-x))
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define drep(i,x,y) for(int i=x;i>=y;i--)
#define repg(i,x) for(int i=p[x];i;i=e[i].nt)  
using namespace std;
typedef long long LL;
LL read(){
	LL rtn=0;char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')rtn=(rtn<<3)+(rtn<<1)+ch-'0',ch=getchar();
	return rtn;
}
const int N=200010;
const LL mod=1e9+7;
int a[N],n,c[N],m;
LL s[N];

void upd(int l,int r,int x){
	s[l]+=x;s[l+1]-=x;
	s[l+1]++;s[r+1]--;
	s[r+1]-=x+r-l;s[r+2]+=x+r-l;
}

int main(){
#ifdef WK
	freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
#endif
	m=read();n=read();a[1]=read();a[1]%=n;
	LL ans=0;
	rep(i,2,m){
		a[i]=read();a[i]%=n;
		int l=(a[i-1]+1)%n,r=a[i];
		if(l>r){
			ans+=(n-l)+r+1;
		}else ans+=r-l+1;
		if(l==r)continue;
		l=(l+1)%n;
		if(l>r){
			upd(l,n-1,1);
			upd(0,r,n-l+1);
		}else upd(l,r,1);
	}
	rep(i,1,n-1)s[i]+=s[i-1];
	rep(i,1,n-1)s[i]+=s[i-1];
	//while()
	LL mx=0;
	rep(i,0,n-1)mx=max(mx,s[i]);
	printf("%lld",ans-mx);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin>>s;
  
  int ans=0;
  for(int i=0;i<s.size();i++){
    int res=0;
    for(int j=i;j<s.size();j++){
      if(s[j]=='A'||s[j]=='T'||s[j]=='C'||s[j]=='G') res++;
      else break;
    }
    ans=max(ans,res);
}
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

#define N 1000000

int main(){
  int inser[N];
  int i,j,g,value;
  int num,cnt;
  int m;
  int shell[N];
  int k;

  scanf("%d",&num);
  for(i=0;i<num;i++) scanf("%d",&inser[i]);

  //shellsort
  cnt = 0;

  j=0;

  for(i=num/2;i>0;i=i/2){
    shell[j] = i;
    j++;
  }
  m=j+1;
    
  for(k=0;k<=m-1;k++){
    //insertionsort
    for(i=shell[k];i<=num-1;i++){
      value = inser[i];
      j = i - shell[k];
      while(j>=0 && inser[j] > value){
	inser[j+shell[k]] = inser[j];
	j = j - shell[k];
	cnt++;
	inser[j+shell[k]] = value;
      }
    }
  }

  printf("%d\n",m);
  for(i=0;i<m;i++){
    if(i) printf(" ");
    printf("%d",shell[i]);
  }
  printf("\n");

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

  for(i=0;i<num;i++){
    printf("%d\n",inser[i]);
  }
    
  return 0;
}





Measured memory_bytes: 6644
import fractions
import collections
   
A,B = map(int,input().split())
gcd = fractions.gcd(A,B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(gcd))
print(len(list(c.keys()))+1)

Measured memory_bytes: 5472
N =int(input())
X = list(map(int,input().split()))
X.sort()
tans=[]
try:
  for i in range(1,X[N-1]+1):
    P=i
    ans=0
    for j in range(N):
      ans+=(X[j]-P)**2
    tans.append(ans)
  print(min(tans))
except:
  print(0)

Measured memory_bytes: 3064
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 8005;
int N;
int a[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

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

    int abs_max = 0;
    int abs_max_id = 0;
    for (int i = 1; i <= N; i++) {
        if (abs(abs_max) < abs(a[i])) {
            abs_max = a[i];
            abs_max_id = i;
        } 
    }

    if (abs_max == 0) {
        std::cout << 0 << std::endl;
        return 0;
    } else if (0 < abs_max) {
        std::cout << N * 2 << std::endl;
        std::cout << abs_max_id << " " << 1 << std::endl;
        std::cout << abs_max_id << " " << 1 << std::endl;
        for (int i = 2; i <= N; i++) {
            std::cout << i - 1 << " " << i << std::endl;
            std::cout << i - 1 << " " << i << std::endl;
        }
    } else {
        std::cout << N * 2 << std::endl;
        std::cout << abs_max_id << " " << N << std::endl;
        std::cout << abs_max_id << " " << N << std::endl;
        for (int i = N - 1; 1 <= i; i--) {
            std::cout << i + 1 << " " << i << std::endl;
            std::cout << i + 1 << " " << i << std::endl;
        }
    }
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	int K;
	int answer = 0;

	cin >> N >> K;
	vector<int> l(N);
	for (int i = 0; i < N; i++) cin >> l.at(i);
	
	sort( l.begin(), l.end(), greater<int>() ); // 降順にソート

	for (int i = 0; i < K; i++) {
		answer += l.at(i);
	}
	
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;
use std::cmp;

fn main() {
    input! {
        h: usize,
        w: usize,
        boards: [Chars; h],
    }
    let inf: usize = 1 << 60;
    let mut dp = vec![vec![inf; w]; h];
    if boards[0][0] == '#' {
        dp[0][0] = 1;
    } else {
        dp[0][0] = 0;
    }

    for i in 0..h {
        for j in 0..w {
            if i > 0 {
                if boards[i][j] != boards[i - 1][j] {
                    dp[i][j] = cmp::min(dp[i][j], dp[i - 1][j] + 1);
                } else {
                    dp[i][j] = cmp::min(dp[i][j], dp[i - 1][j]);
                }
            }
            if j > 0 {
                if boards[i][j] != boards[i][j - 1] {
                    dp[i][j] = cmp::min(dp[i][j], dp[i][j - 1] + 1);
                } else {
                    dp[i][j] = cmp::min(dp[i][j], dp[i][j - 1]);
                }
            }
        }
    }
    if boards[h - 1][w - 1] == '#' {
        dp[h - 1][w - 1] += 1;
    }

    println!("{}", dp[h - 1][w - 1] / 2);
}


Measured memory_bytes: 2300
#include <cstdio>
#include <cstring>
#include <utility>

#define MAXN 36
#define DEBUG(d,n) {for (int i = 0; i < n; i++) {\
                        if (i != n-1)   printf("%c%c ", d[i].suit, d[i].value);\
                        else            printf("%c%c", d[i].suit, d[i].value);\
                    }   printf("\n");}

using std::swap;

struct Card { char suit, value; };

void bubbleSort(Card d[], int len) {
	for (int i = 0; i < len; i++) {
		for (int j = len-1; j > i; j--) {
			if (d[j].value < d[j-1].value) {
				swap(d[j], d[j-1]);
			}
			// number of loop operations
		}
	}
}

void selectSort(Card d[], int len) {
	for (int i = 0; i < len; i++) {
		int mini = i;
		for (int j = i; j < len; j++) {
			if (d[j].value < d[mini].value) {
				mini = j;
			}
		}
		swap(d[i], d[mini]);
	}
}

void isStable(Card In[], Card Out[], int len) {
	DEBUG(Out, len);
	for (int i = 0; i < len; i++) {
		for (int j = i+1; j < len; j++) {
            if (In[i].value == In[j].value)
                for (int a = 0; a < len; a++) {
                    if (Out[a].value == In[i].value)
                        for (int b = a+1; b < len; b++) {
                            // find order is opposite
                            if (Out[a].value == Out[b].value && In[i].suit == Out[b].suit && In[j].suit == Out[a].suit) {
                                printf("Not stable\n");
                                return;
                            }
                        }
                }
		}
	}
	printf("Stable\n");
}

int main() {
	Card O[MAXN], C1[MAXN], C2[MAXN];

	int n;
	scanf("%d", &n);
	getchar();
	for (int i = 0; i < n; i++) {
		scanf("%c%c", &O[i].suit, &O[i].value);
		getchar();
	}
	//DEBUG(C1, n);
	memcpy(C1, O, sizeof(Card)*MAXN);
	memcpy(C2, O, sizeof(Card)*MAXN);

	bubbleSort(C1, n);
	isStable(O, C1, n);

	selectSort(C2, n);
	isStable(O, C2, n);

	return 0;
}

/*
5
H4 C9 S4 D2 C3
*/

Measured memory_bytes: 2728