akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#define rep(i,n) for(int i = 0;i<(int)(n);i++);
using namespace std;
using ll = long long;
const ll INF = 100100100100100;


int main() {
	ll num;
	cin >> num;
	if (num == 1) cout << "Hello World" << endl;
	else {
		ll a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n,count=0;
    scanf("%d",&n);
    vector<int> S(n);
    for(int i=0;i<n;i++){
        int s;
        scanf("%d",&S[i]);
    }

    int q;
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        int t;
        scanf("%d",&t);
        if(*lower_bound(S.begin(),S.end(),t) == t) count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2740
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int mnx = 3e5 + 9;
const int mod = 1e9 + 7;

int n, m;
int a, b;
int cnt[mnx];

int main(){

cin>>n>>m;

for(int i=0; i<m; i++){
    cin>>a>>b;
    cnt[a]++; cnt[b]++;
}

for(int i=1; i<=n; i++){
    if(cnt[i] % 2 != 0){
        cout<<"NO\n";
        return 0;
    }
}

cout<<"YES\n";

return 0;

}












Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#define N 200
#define mod
#define inf
#define rg register
using namespace std;
typedef long long ll;
int n;
int main(){
	scanf ("%d",&n);
	int x;
	int cnt=0,tmp=0;
	for (int i=1;i<=n;++i){
		scanf ("%d",&x);
		if (x%2==1) {cnt--;continue;}
		if (x%4==0) {cnt++;continue;}
		if (x%2==0) tmp++;
	}
	if (cnt<-1) {printf ("No\n");return 0;}
	if (cnt==-1&&tmp) {printf ("No\n");return 0;}
	printf ("Yes\n");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
ans = -1
for i in range(N):
    for j in range(i + 1, N):
        num = [int(x) for x in str(A[i] * A[j])]
        if all(num[i] + 1 == num[i + 1] for i in range(len(num) - 1)) and ans < A[i] * A[j]:
            ans = A[i] * A[j]
print(ans)

Measured memory_bytes: 7760
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

ll n, m, x;
vector<ll> c;
vector<vector<ll>> a;

ll dfs(ll p, ll sum, vector<ll> v)
{
    if (p == 0)
    {
        for (ll i = 0; i < m; i++)
        {
            if (v[i] < x)
            {
                return LLONG_MAX;
            }
        }
        return sum;
    }

    ll ans = dfs(p - 1, sum, v);
    sum += c[p - 1];
    for (ll i = 0; i < m; i++)
    {
        v[i] += a[p - 1][i];
    }

    return min(ans, dfs(p - 1, sum, v));

}

int main(int argc, char const *argv[])
{
    cin >> n >> m >> x;
    ll ans = 0;

    c.resize(n);

    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
        vector<ll> t(m);
        for (ll j = 0; j < m; j++)
        {
            cin >> t[j];
        }
        a.push_back(t);
    }

    vector<ll> t(m, 0);
    ans = dfs(n, 0, t);

    if (ans == LLONG_MAX)
    {
        cout << -1 << endl;
    }
    else
        cout << ans << endl;
}

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

using namespace std;

int c[10][10];

int main()
{
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			cin >> c[i][j];
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			for (int k = 0; k < 10; k++)
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
	int r = 0, a;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a;
			if (a > -1)
				r += c[a][1];
		}
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 384
import Control.Applicative
import Data.List
import Data.Char

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine

getIntArray :: IO [Int]
getIntArray = ((map (\a -> read a :: Int)) . words) <$> getLine

getStrArray :: Int -> IO [String]
getStrArray 0 = return [] :: IO [String]
getStrArray n = (:) <$> getLine <*> (getStrArray (n - 1))

balance :: [Int] -> String
balance [a, b, c, d]
    | a + b == c + d = "Balanced"
    | a + b < c + d = "Right"
    | otherwise = "Left"

main = do
    putStrLn =<< balance <$> getIntArray


Measured memory_bytes: 508
#include <iostream>
#include <algorithm>

using namespace std;

bool check(int year)
{
  if(year%400 == 0 || (year%4 == 0 && year%100 != 0))
    return true;

  return false;
}

int main()
{
  int a, b;
  bool flg = false;

  while(cin>>a>>b && a+b){
    if(flg) cout << endl;

    flg = false;
    for(int year = a; year <= b; ++year){
      if(check(year)){
	cout << year << endl;
	flg = true;
      }
    }

    if(!flg) cout << "NA" << endl;
    flg = true;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll memo[100010];
string s;

bool hoge(ll i){
    if(s.size()-i<=7){
        if(s.substr(i)=="" || s.substr(i)=="dream" || s.substr(i)=="dreamer" || s.substr(i)=="erase" || s.substr(i)=="eraser"){
            memo[i]=1;
            return true;
        }
        memo[i]=-1;
        return false;
    }
    if(memo[i]!=0){
        if(memo[i]==1){
            return true;
        }else{
            return false;
        }
    }
    if(s.substr(i,5)=="dream"){
        if(hoge(i+5)){
            memo[i]=1;
            return true;
        }
    }
    if(s.substr(i,7)=="dreamer"){
        if(hoge(i+7)){
            memo[i]=1;
            return true;
        }
    }
    if(s.substr(i,5)=="erase"){
        if(hoge(i+5)){
            memo[i]=1;
            return true;
        }
    }
    if(s.substr(i,6)=="eraser"){
        if(hoge(i+6)){
            memo[i]=1;
            return true;
        }
    }
    memo[i]=-1;
    return false;
    
}

int main(){
    cin>>s;
    if(hoge(0)){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}


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

int main() {
    int k, cnt = 0;
    cin >> k;
    queue<long long> q;
    for (int i = 1; i <= 9; i++) q.push(i);
    while (!q.empty()) {
        long long x = q.front(); q.pop();
        cnt++;
        if (cnt == k) {
            std::cout << x;
            return 0;
        }
        if ((x % 10) > 0) q.push(10 * x + (x % 10) - 1);
        q.push(10 * x + (x % 10));
        if ((x % 10) < 9) q.push(10 * x + (x % 10) + 1);
    }
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;


//ここから

struct UF {
	vector<int>par;//親
	vector<int>Rank;//木の深さ
    vector<int>sz;//要素数

    UF(int n){init(n);}

	//初期化
	void init(int n) {
		par.resize(n); Rank.resize(n);sz.resize(n);
		for (int i = 0; i < n; i++) {
			par[i]= i;
			Rank[i] = 0;
            sz[i]=1;
		}
	}

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

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (Rank[x] < Rank[y]) {//高さが小さい方を下に
			par[x] = y;
            sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			if (Rank[x] == Rank[y])Rank[x]++;//同じだとrankが変わらないままになるので増やす（それ以外は大きい方のrankが採用される）
            sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};

void solve(){
  int n,m;
  cin>>n>>m;
  UF tree(n);
  rep(i,m){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    tree.unite(x,y);
  }
  set<int>st;
  rep(i,n)st.emplace(tree.find(i));
  cout<<st.size();
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 6144
module Main where

import Data.List
import qualified Data.Map.Strict as Map
import Control.Monad
import Data.Ord

main = do
    print =<< solve <$> readInts

readInts :: IO [Int]
readInts = ((map read) . words) <$> getLine


solve :: [Int] -> Int
solve [a, b]
    | a >= 10 = -1
    | b >= 10 = -1
    | otherwise = a * b



Measured memory_bytes: 508
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    a, b = nm()
    print('Yay!' if a <= 8 and b <= 8 else ':(')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9112
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int cmp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main() {
    int i, N, K, *h, dh, min = INT_MAX;
    if (scanf("%d %d%*c", &N, &K) == -1) return -1;
    h = (int *)malloc(sizeof(int) * N);
    if (!h) return-1;
    for (i = 0; i < N; i++) if (scanf("%d%*c", &h[i]) == -1) return -1;
    qsort(h, N, sizeof(int), cmp);
    for (i = 0; i < N - K + 1; i++) {
        dh = h[i+K-1] - h[i];
        if (dh < min) min = dh;
    }
    printf("%d\n", min);
    free(h);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0;i<N;i++){
    cin >> X.at(i);
  }
  sort(X.begin(),X.end());
  int mi=1e9;
  for(int P=X.at(0);P<=X.back();P++){
    int sum=0;
    for(int i=0;i<N;i++){
      sum+=pow(X.at(i)-P,2);
    }
    if(mi>sum){
      mi=sum;
    }
  }
  cout << mi << endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

ll n, m, q;
vll a, b, c, d;
ll ans = 0;
vll seq {1};
void dfs(ll v){
  if(v == n + 1){
    ll summ = 0;
    rep(i, 0, q) if(seq.at(b.at(i)) - seq.at(a.at(i)) == c.at(i)) summ += d.at(i);
    chmax(ans, summ);
    return;
  }
  rep(next, seq.at(v - 1), m + 1){
    seq.push_back(next);
    dfs(v + 1);
    seq.pop_back();
  }
  return;
}

int main(){
  cin >> n >> m >> q;
  a.assign(q, 0), b.assign(q, 0), c.assign(q, 0), d.assign(q, 0);
  rep(i, 0, q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  dfs(1);
  cout << ans << endl;
}

Measured memory_bytes: 3636
n,l = map(int,input().split())

allpie = 0
for i in range(n):
    a = l+(i+1)-1
    allpie += a
    if i == 0:
        t = abs(a)
        num = i
    elif t > abs(a):
        t = abs(a)
        num = i
# print(t)
# print(num)
print(allpie-(l+(num+1)-1))











Measured memory_bytes: 39896
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 998244353
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
int main()
{
       ios::sync_with_stdio(0) ;
       cin.tie(0); 
       int n,m;
       cin>>n>>m;
       ll ans=n*(n-1);
       ans/=2;
       ll t=m*(m-1);
       t/=2;
       
       ans+=t;
       cout<<ans<<endl;
  return 0 ;
}
//make all values ll



Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 200005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
#define endl "\n"
#define de(x) cout<<#x<<"="<<x<<endl
int n, x, y;

struct node
{
    int id;
    int dis;

    node() {}

    node(int a, int b) :
            id(a), dis(b) {}

    friend bool operator<(node a, node b)
    {
        return a.dis > b.dis;
    }
};

vector<node> G[2005];
bool flag[2005];
int dist[2005];

void dij(int s)
{
    priority_queue<node> q;
    node t, to;
    memset(dist, 0x3f, sizeof(dist));
    memset(flag, 0, sizeof(flag));
    dist[s] = 0;
    q.push(node(s, 0));
    while (!q.empty())
    {
        t = q.top();
        q.pop();
        if (flag[t.id])
            continue;
        flag[t.id] = 1;
        int sz = G[t.id].size();
        for (int i = 0; i < sz; i++)
        {
            to = G[t.id][i];
            if (dist[to.id] > dist[t.id] + to.dis)
            {
                dist[to.id] = dist[t.id] + to.dis;
                q.push(node(to.id, dist[to.id]));
            }
        }
    }
}

int ans[2005];

int main()
{
    cin >> n >> x >> y;
    for (int i = 1; i < n; ++i)
    {
        G[i].push_back(node{i + 1, 1});
        G[i + 1].push_back(node{i, 1});
    }
    G[x].push_back(node{y, 1});
    G[y].push_back(node{x, 1});
    for (int i = 1; i <= n; ++i)
    {
        dij(i);
        for (int j = 1; j <= n; ++j)
            ans[dist[j]]++;
    }
    for (int i = 1; i < n; ++i)
        cout << ans[i]/2 << endl;
    return 0;
}

Measured memory_bytes: 384
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut a: Vec<i64> = (0..n).map(|_| input()).collect();
    a.sort();
    println!("{}", a[n - 1] - a[0]);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void){
	int a[31]={0};
	int b,i;
	for(i=1;i<=28;i++){
		scanf("%d",&b);
		a[b]=1;
	}
	for(i=1;i<=30;i++){
		if(a[i]==0){
			printf("%d\n",i);
		}
	}
	return 0;
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int x,y; cin>>x>>y;
  bool flag=0;
  for(int i=1;i<=x;i++){
    if(((x-i)*2+i*4==y)||(x-i)*4+i*2==y)
      return cout<<"Yes\n", 0;
  }
cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3608
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

a,b = I2()
print(a*b)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n),d(100,0);
    rep(i,n) cin>>a[i];
    rep(i,n){
        rep(j,40)if(a[i]&((ll)1<<j))d[j]++;
    }
    ll l=0;
    for(int j=40;j>=0;j--){
        if(d[j]>(n/2))continue;
        if(l+((ll)1<<j)<=k) l+=((ll)1<<j);
    }
    ll res=0;
    rep(i,n){
        res+=a[i]^l;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 4056
a,v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a < b:
    if a + v * t >= b + w * t :
        print("YES")
    else:
        print("NO")
else : 
    if a - v * t <= b - w * t :
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9184
n = int(input())
a =[int(i)  for i in input().split()]
z = sum(a)
ans = 10**20
c = 0

for i in range(n-1):
    c += a[i]
    z -= a[i]
    if abs(c-z) < ans:
        ans = abs(c-z)
    
print(ans)

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

int main() {
  string S;
  cin >> S;
  int ans;
  if(S=="SUN")ans=7;
  if(S=="MON")ans=6;
  if(S=="TUE")ans=5;
  if(S=="WED")ans=4;
  if(S=="THU")ans=3;
  if(S=="FRI")ans=2;
  if(S=="SAT")ans=1;
  cout << ans << endl;
}

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

ll N, D, T[100000], F[100000];

int main(void) {
  cin >> N >> D;
  REP(i, 0, N) cin >> T[i] >> F[i];

  if(T[0] < F[0] - 1) {
    cout << -1 << endl;
    return 0;
  }

  ll t = T[0], f = F[0], ans = 0, cnt = 1;
  REP(i, 1, N) {
    if(cnt <= D && f > 1 && T[i] - t >= f + F[i] - 2) {
      ans += cnt * (f - 1);
      cnt = 1;
      t = T[i];
      f = F[i];
    } else if(cnt + 1 <= D && abs(F[i] - f) <= T[i] - t) {
      ans += cnt * (T[i] - t);
      cnt++;
      t = T[i];
      f = F[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  ans += (f - 1) * cnt;
  cout << ans << endl;
}

Measured memory_bytes: 4628
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
    lli A,B,C;
    cin >> A;
    C=A%60;
    A=(A-C)/60;
    B=A%60;
    A=(A-B)/60;
    cout << A << ":" << B << ":" << C << endl;
}
    


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}

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

int main() {
  string s;
  int a, b;
  cin >> a >> b >> s;
  if(s.at(b - 1) == 'A'){
    s.at(b - 1) = 'a';
  }else if(s.at(b - 1) == 'B'){
    s.at(b - 1) = 'b';
  }else if(s.at(b - 1) == 'C'){
    s.at(b - 1) = 'c';
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define H 500001
#define NIL -2000000001
int n;
int A[H];
void maxHeapify(int A[],int i);
void buildMaxHeap(int A[]);

int main(){
  int i;
  scanf("%d",&n);
  /* for(i=0;i<=n;i++){
    A[i]=NIL;
  }
  */
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap(A); 

  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
  
  
}
void maxHeapify(int A[],int i){
  int l,r,largest,temp;
  l=i*2;
  r=i*2+1;
  if(l<=n && A[l]>A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  if(r<=n && A[r]>A[largest]){
    largest = r;
  }
  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A,largest);
  } 
}
void buildMaxHeap(int A[]){
  int i; 
 for(i=n/2;i>=1;i--)
    maxHeapify(A,i);

}

Measured memory_bytes: 2552
let n=Int(readLine()!)!
let s=readLine()!
let S=Array(s)
var k=0
if n%2==1{
  print("No")
}else{
  for i in 0...n/2-1{
    if S[i] != S[i+n/2]{
      k=1
    }
  }
  if k==1{
    print("No")
  }else{
    print("Yes")
  }
}
      

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

int m_min(vector<int> m){
  int M = m[0];
  for(x:m){
    M = min(M,x);
  }
  return M;
}

int main(){
  int N,X;
  cin >> N >> X;
  vector<int> m(N);
  for(int i=0;i<N;i++){
    cin >> m[i];
    X -=m[i];
  }
  int a=m_min(m);
  int count = N;
  while(X>=a){
    X -= a;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

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

    ll a, b, w, h;
    w = ll(1e9);
    a = 1;
    if(S>w) {
        h = (S+w-1)/w;
        b = h*w - S;
    } else {
        h = 1;
        b = w - S;
    }
    
    
	cerr << "h = " << h << endl;
    cerr << "b = " << b << " w*h - a*b = " << w*h - a*b  << " w*h - a*b == S : " << (w*h - a*b == S) << endl;
    cerr << (w <= 1e9) << (a <= 1e9) << (b <= 1e9) << (h <= 1e9) << endl;
    cout << 0 << " " << 0 << " " << w << " " << a << " " << b << " " << h << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>
#include <stack>
 
using namespace std;
 
int n, k;
int dp[610][610];
int f[610];
int ans = 0;
vector<pair<int, int> > line;
bool p[602];
 
const int MOD = 1e9 + 7;
 
int add(long long a, long long b){
	return ((a + b) % MOD + MOD) % MOD;
}
 
int mul(long long a, long long b){
	return (a * b) % MOD;
}
 
int main(){
	// freopen("input.in", "r", stdin);
	f[0] = 1;
	f[2] = 1;
	for(int i = 4; i <= 600; i += 2) f[i] = mul(f[i - 2], i - 1);
 
	scanf("%d%d", &n, &k);
 
	while(k--){
		int u, v;
		scanf("%d%d", &u, &v);
		if(u > v) swap(u, v);
		line.emplace_back(u, v);
		p[u] = p[v] = true;
	}
 
	n <<= 1;
	for(int i = 1; i <= n - 1; i++){
		int ins, out; ins = out = 0;
		bool ok = true;
 
		for(auto k : line){
			int j = i + 1;
			if(i <= k.first && k.first <= j && i <= k.second && k.second <= j) ins++;
			else if ((i <= k.first && k.first <= j) ^ (i <= k.second && k.second <= j)) ok = false;
			else out++;
		}
		if(!ok) continue;
		dp[i][i + 1] = 1, ans = add(ans, f[n - 2 - (out << 1)]);
	}
 
	for(int len = 2; len <= n - 1; len++){
		for(int i = 1; i <= n - len; i++){
			int j = i + len;
 
			int ins, out;
			ins = out = 0;
 
			bool ok = 1;
			for(auto k : line){
				if(i <= k.first && k.first <= j && i <= k.second && k.second <= j) ins++;
				else if ((i <= k.first && k.first <= j) ^ (i <= k.second && k.second <= j)) ok = false;
				else out++;
			}
 
			if(!ok) continue;
 
			int tp = 0;
 
			for(int k = i; k <= j; k++){
				if(p[k]) continue;
				tp++;
			}
 
			// if(i == 2 && j == 5) cout << tp << endl;
 
			dp[i][j] = f[tp];
 
			for(int k = i; k <= i + 1; k++){
				if(!p[k]) tp--;
			}
 
			// if(i == 2 && j == 5) cout << tp << endl;
 
			for(int k = i + 1; k < j; k++){
				// if(i == 2 && j == 5) cout << k << " " << dp[i][k] << " " << tp << "XXX\n";
				dp[i][j] = add(dp[i][j], -mul(dp[i][k], f[tp]));
				if(!p[k + 1]) --tp;
			}
 
			// cout << i << " " << j << " " << dp[i][j] << endl;
 
			ans = add(ans, mul(dp[i][j], f[n - (len + 1) - (out << 1)]));
		}
	}
 
	printf("%d\n", ans);
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  multiset<int> max;
  for(int i = 1; i <= N;i++){
    int M;
    cin >> M;
    for(int j = 0;j < M; j++){
      int c;
      cin >> c;
      max.insert(c);
      if(i<max.size())max.erase(max.begin());
    }
  }
  long long int ans = 0;
  for(auto x = max.begin(); x != max.end(); x++){
    ans += *x;
  } 
  cout << ans << endl;
}



Measured memory_bytes: 17160
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(long i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long n;
    cin >> n;
    long long m;
    long long ans = 0;
    long  k = long(sqrt(n))+2;
    rep(i,k){
        if((n-i-1)%(i+1) == 0){
            m = (n-i-1)/(i+1);
            if(m>i+1){
                ans+=m;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli x, y, a, b, c;

int main(void){
    cin >> x >> y >> a >> b >> c;
    vector<lli> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];
    vector<lli> s;
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());
    rep(i, x) s.push_back(p[i]);
    rep(i, y) s.push_back(q[i]);
    rep(i, c) s.push_back(r[i]);
    sort(s.rbegin(), s.rend());
    lli ans = 0;
    ans = accumulate(s.begin(), s.begin()+x+y, 0LL);
    cout << ans << endl;

    return 0;
}


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

using namespace std;

void subsets(vector<int> S, vector<int> U, int n) 
{
     int nSub = 1<<n;
     vector<int> v;
     
     for(int i = 0; i < nSub; i++)
     {
         for(int k = 0; k < n; k++)
         {
             if((1 << k) & i)
             {
                 v.emplace_back(S[k]);
             } 
         }
         
         bool cond = true;
         
         for(int k = 0; k < (int)U.size(); k++)
         {
             if(!(binary_search(v.begin(), v.end(), U[k])))
             {
                 cond = false;
                 break;
             }
         }
         
         if(cond)
         {
             int k;
             cout << i << ":";
             for(k = 0; k < (int)v.size(); k++)
                cout << " " << v[k];
            cout << "\n";
         }
         v.clear();
     }
}

int main() 
{
    int n, m, k;
    scanf("%d %d", &n, &k);
    vector<int> T;
    vector<int> U;
    
    for(int i = 0; i < k; i++)
    {
        scanf("%d", &m);
        U.emplace_back(m);
    }
    
    for(int i = 0; i < n; i++)
        T.emplace_back(i);
        
    subsets(T, U, n);
    
    return 0;
}


Measured memory_bytes: 3244
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    h, w, k = LI()
    s = SR(h)
    done = []
    ans = [[None] * w for i in range(h)]
    for y in range(h):
        f = 0
        for x in range(w):
            if f:
                if s[y][x] == "#":
                    k -= 1
                ans[y][x] = str(k)
            else:
                if s[y][x] == "#":
                    f = 1
                ans[y][x] = str(k)
        if f:
            done.append(y)
            k -= 1
    
    for d in done:
        for y in range(d + 1, h):
            if y in done:
                break
            ans[y] = ans[d]
        for y in range(d - 1, -1, -1):
            if y in done:
                break
            ans[y] = ans[d]
    
    for a in ans:
        print(" ".join(a))

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 48368
import collections as c
import sys
input = sys.stdin.readline
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
N,M = ip()
S = {}
for i in range(M):
    s,c = ip()
    if s not in S:
        S[s] = c
    elif S.get(s,10) == c:
        continue
    else:
        print(-1)
        exit()
for i in range(1000):
    si = str(i)
    # print(i,si)
    if len(si)!=N:
        continue
    # print(i,si)
    for j in S:
        # print(si[j-1],S[j])
        if si[j-1]!=str(S[j]):
            # print('a')
            break
    else:
        print(i)
        exit()
print(-1)

# ans = 0
# for i in range(1,1+N):
#     if i==1:
#         ans += S.get(i,1)*10**(N-i)
#     else:ans += S.get(i,0)*10**(N-i)
# if ans>=10**(N-1):
#     print(ans)
# elif ans == 0 and N==1:
#     print(0)
# else:print(-1)

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int a,b,tmp;
    scanf("%d %d",&a,&b);
    while(a!=b)
    {
        if(a>b)
        {
         tmp=a-b;
         a=b;
         b=tmp;
        }
        else
        {
         tmp=b-a;
         b=a;
         a=tmp;
        }
    }
    printf("%d\n",a);
}


Measured memory_bytes: 2148
d={}
a=[]
N=int(input())
for i in range(N):
  s=input()
  if s not in a:
    a.append(s)
    d[s]=1
  else:
    d[s]+=1
  a=list(set(a))
M=int(input())
for j in range(M):
  t=input()
  if t not in a:
    a.append(t)
    d[t]=-1
  else:
    d[t]-=1
  a=list(set(a))
ans=0
for k in a:
  ans=max(ans,d[k])
print(ans)

Measured memory_bytes: 9212
# 2019/02/03
# AtCoder Beginner Contest117 - C

# Input
n, m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()

# Calc Distance
dlist = list()
for i in range(m-1):
    dlist.append(x[i+1]-x[i])

# Sum distance(for m-1-(n-1))
dlist.sort()
sum = 0
for j in range(m-1-(n-1)):
    sum += dlist[j]

# Output
print(sum)

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

int main() {

  long long int n, m, s, t;
  cin >> n >> m >> s >> t;

  s--;
  t--;

  vector< vector< long long int > > v;
  vector< long long int > cs;
  vector< long long int > ct;

  for ( long long int i = 0; i < n; i++ ) {
    vector< long long int > vv;
    v.push_back( vv );
    cs.push_back( m + 10 );
    ct.push_back( m + 10 );
  }

  for ( long long int i = 0; i < m; i++ ) {

    long long int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back( y );
    v[y].push_back( x );

  }

  vector< vector< long long int > > ps;
  vector< vector< long long int > > pt;
  for ( long long int i = 0; i <= m; i++ ) {
    vector< long long int > vs;
    ps.push_back( vs );
    vector< long long int > vt;
    pt.push_back( vt );
  }


  queue< long long int > q;
  q.push( t );
  ct[t] = 0;
  pt[0].push_back( t );

  while( q.size() > 0 ) {

    long long int k = q.front();
    q.pop();

    for ( long long int i = 0; i < v[k].size(); i++ ) {

      if ( ct[ v[k][i] ] > m ) {
	ct[ v[k][i] ] = ct[k] + 1;
	q.push( v[k][i] );
	pt[ ct[ v[k][i] ] ].push_back( v[k][i] );
      }

    }

  }


  q.push( s );
  cs[s] = 0;
  ps[0].push_back( s );

  while( q.size() > 0 ) {

    long long int k = q.front();
    q.pop();

    for ( long long int i = 0; i < v[k].size(); i++ ) {

      if ( cs[ v[k][i] ] > m ) {
	cs[ v[k][i] ] = cs[k] + 1;
	q.push( v[k][i] );
	ps[ cs[ v[k][i] ] ].push_back( v[k][i] );
      }

    }

  }


  long long int ans = 0;

  long long int k = cs[t] - 2;

  for ( long long int i = 0; i <= k; i++ ) {

    ans += ps[i].size() * pt[k-i].size();

  }

  cout << ans << endl;

  return 0;

}

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

void solve1(){
    int n; cin >> n;
    cout << (1000 - n%1000)%1000 << endl;
    
}

void solve2(){
    int n; cin >> n;
    int _ac=0, _wa=0, _tle=0, _re=0;
    string s;
    for(int i=0; i<n; i++){
        cin >> s;
        if(s[0] == 'A'){
            _ac++;
        }
        if(s[0] == 'W'){
            _wa++;
        }
        if(s[0] == 'T'){
            _tle++;
        }
        if(s[0] == 'R'){
            _re++;
        }
    }
    cout << "AC" << " x " << _ac << endl;
    cout << "WA" << " x " << _wa << endl;
    cout << "TLE" << " x " << _tle << endl;
    cout << "RE" << " x " << _re << endl;
}

int main() {
	// your code goes here
	solve2();
	return 0;
}


Measured memory_bytes: 3632
import math

n = int(input())
line = list(map(int,input().split( )))

bline = line[:]
sep = math.ceil(n/2)
bline[:sep] = [0]*sep
# print([0]*sep)


for i in reversed(range(sep)):
    bline[i]=(sum(bline[i::i+1])+line[i])%2

blist=[]

for i in range(len(bline)):
    if bline[i]==1:
        blist.append(i+1)

# print(line)
# print(bline)
# print(blist)
print(len(blist))
print(' '.join(map(str,blist)))

Measured memory_bytes: 82448
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
K = lines[0][1]

a_max = 10 ** 9
a_min = 1
a_current = a_max
searching = true
twice = false

while searching do
  num_cut = 0
  for i in 1..N do
    num_cut += (lines[1][i-1] - 1) / a_current
  end
  if num_cut <= K then   #safe!
    a_max = a_current
    a_current = (a_min + a_max) / 2
  else  #out!
    a_min = a_current
    a_current = (a_min + a_max) / 2
  end
  if a_min + 1 == a_max or a_max == 1 then
    if twice then
      searching = false
      ans = a_max
    else
      twice = true
    end
  end
end
    
puts ans

Measured memory_bytes: 29664
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define ll long long int
#define MOD 1000000007LL
using namespace std;

int main() {
    string s;
    cin>>s;
    int sl=s.length();
    if((sl%2==0)^(s[0]==s[sl-1])){
        cout<<"Second"<<endl;
    }else{
        cout<<"First"<<endl;
    }

}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <cmath>

using namespace std;

const double sqrt2 = sqrt(2.0); 
const double eps = 1e-6;
char dx[] = {-1,1,-1,1};
char dy[] = {1,1,-1,-1};

class Square{
public:
	int bound; double x, y, size;
	Square(int bound, double x, double y, double size) : bound(bound), x(x), y(y), size(size) {}
	bool operator < (const Square &s) const { return bound < s.bound; }
};

inline double sqr(double x) { return x*x; }

int main(){
	int N;
	double x[300], y[300];
	while(cin >> N){
		if(!N) break;
		for(int i=0;i<N;i++) cin >> x[i] >> y[i];
		int ans = 1;
		priority_queue<Square> qu;
		qu.push(Square(N, 5.0, 5.0, 10.0));
		while(!qu.empty()){
			Square s = qu.top(); qu.pop();
			if(s.bound <= ans) break;
			for(int i=0;i<4;i++){
				double nx = s.x + dx[i]*s.size/2.0;
				double ny = s.y + dy[i]*s.size/2.0;
				int c = 0, upper = 0;
				for(int j=0;j<N;j++){
					double dist = sqr(x[j]-nx)+sqr(y[j]-ny);
					if(dist < 1.0+eps) c++;
					if(dist < sqr(1.0+sqrt2*s.size/2.0)+eps) upper++;
				}
				ans = max(ans, c);
				if(upper > ans) qu.push(Square(upper, nx, ny, s.size/2.0));
			}
		}
		cout << ans << endl;
	}
}

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

signed main() {
	int r, g, b;
	cin >> r >> g >> b;
	if ((100 * r + 10 * g + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int max = 1;
        int i = 2;

        while (i * i <= x) {
            int m = i * i;
            while (m <= x) {
                if (m > max) {
                    max = m;
                }
                m *= i;
            }
            i++;
        }

        System.out.println(max);
    }
}


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

int main() {
    int N; cin>>N;
    vector<int> A(N);
    rep(i,N) cin>>A[i];
    
    bool flag = true;
    int ans=0;
    for(int i=0;flag;i++){
        flag = false;
        for(int j=N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                flag=true;
                ans++;
            }
        }
    }
    rep(i,N){
        cout<<A[i];
        if(i!=N-1)cout<<' ';
        else cout<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>

#define ll long long
#define MOD 998244353

using namespace std;

ll n,k;
ll h;


int main(){
 int ans=0;
 cin>>n>>k;
 for(int i=0;i<n;++i){ 
     cin>>h;
     if(h>=k) ans++;
 }
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 256
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<set>
using std::set;

#include<vector>
using std::vector;

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<int> h(n);
  vector<bool> f(n);
  for (int i = 0; i < n; i ++)
  {
    cin >> h.at(i);
    f.at(i) = true;
  }
    
  while(1)
  {
    int a, b;
    cin >> a >> b;
    
    if (h.at(a - 1) < h.at(b - 1)) f.at(a - 1) = false;
    else if (h.at(b - 1) < h.at(a - 1)) f.at(b - 1) = false;
    else
    {
      f.at(a - 1) = false;
      f.at(b - 1) = false;
    }
    
    if (cin.eof()) break;
  }
  
  int count = 0;
  for (int i = 0; i < n; i ++)
  {
    if (f.at(i)) count ++;
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

queue<char>q[3];


int main()
{
    fast;
  
  ll a,b,x;
  cin>>a>>b>>x;
  
  ll ans;
  
  ans=b/x;
  ans=ans-(a/x);
  
  if(a%x==0)ans++;
  cout<<ans;
  	
}

		
	
	
	
	


Measured memory_bytes: 3528
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=201000;

int f[N],ans[N],pos[N];
int n;

void calc(int x)
{
	if(ans[x+1]==0)
	{
		if(pos[x]>pos[x+1])ans[x]=1,f[x]=x+1;
		else ans[x]=0,f[x]=-1;
	}
	else 
	{
		int y=f[x+1];
		if((pos[y]<pos[x] && pos[x]<pos[x+1])
		|| (pos[x]<pos[x+1] && pos[x+1]<pos[y])
		|| (pos[x+1]<pos[y] && pos[y]<pos[x]))
			ans[x]=ans[x+1],f[x]=y;
		else ans[x]=ans[x+1]+1,f[x]=x+1;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++)
		scanf("%d",&x),pos[x]=i;
	ans[n]=0,f[n]=-1;
	for(int i=n-1;i;i--)
		calc(i);
	printf("%d\n",ans[1]);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>

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

void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int N,minr=INF,mins=INF,A,B;
	cin>>N;
	REP(i,N){
		cin>>A>>B;
		if(mins>B){
			mins=B;
			minr=A;
		}
	}

	print(minr+mins);
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int A[][] = new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				A[i][j] = in.nextInt();
			}
		}
		int b[] = new int[m];
		for(int i=0;i<m;i++) {
			b[i] = in.nextInt();
		}

		int ans[] = new int[n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				ans[i] += A[i][j]*b[j];
			}
		}

		for(int i=0;i<n;i++) {
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 40680
def p_d():
    n = int(input())
    t = [[] for _ in range(n)]
    p = [-1] * n
    for i in range(n - 1):
        a, b = map(int, input().split())
        t[a - 1].append((i, b - 1))
        p[b - 1] = a - 1
    q = [(0, -1)]
    ans = [-1] * (n - 1)
    while q:
        x, c0 = q.pop()
        c = 1
        for i, y in t[x]:
            if c == c0:
                c += 1
            ans[i] = c
            q.append((y, c))
            c += 1
    print(max(ans))
    for a in ans:
        print(a)
        
p_d()

Measured memory_bytes: 30892
#include <bits/stdc++.h>
#include <set> 
#include <iterator> 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


int main()
{
    
    fastio();

        ll n,w;
        cin>>n>>w;
        vector <pair<ll, ll> > v;
        ll a,b;
        for(ll i=0;i<n;i++)
        {
            cin>>a>>b;
            v.pb(mp(a,b));
        }
        sort(v.begin(),v.end());
        ll dp[n][w+1]={0};
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<=w;j++)
            {
                dp[i][j]=0;
            }
        }
        for(ll i=v[0].ff;i<=w;i++)
            dp[0][i]=v[0].ss;
        for(ll i=1;i<n;i++)
        {
            for(ll j=0;j<=w;j++)
            {
               if(j<v[i].ff)
               {
                    dp[i][j] = dp[i-1][j];
               }
               else
               {
                    dp[i][j] = max(v[i].ss+dp[i-1][j-v[i].ff],dp[i-1][j]);
               }
            }
        }
        /*for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<=w;j++)
            {
                cout<<" "<<dp[i][j];
            }
            nl;
        }*/
        cout<<dp[n-1][w]<<endl;
}


Measured memory_bytes: 78336
s = input()
k = int(input())
n = len(s)

ans = 0
def aa(s):
    ansaa=0
    a = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            a += 1
        else:
            if a > 0:
                ansaa += (a+1)//2
                a = 0
    ansaa += (a+1)//2    
    return ansaa
# print(aa(s))
# print(aa(s*2))
# print(aa(s) + (aa(s*2) - aa(s))*(k-1))

l = -1
r = 0
if s[0] == s[-1]:
    ss = s[0]
    while l >= -n and s[l] == ss:
        l -= 1
    while r < n and s[r] == ss:
        r += 1
    # print(l,r)
    if l == -n-1:
        ans = (n*k)//2
    else:
        ans += ((r-l-1)//2)*(k-1)
        # print(aa(s[r:n+l+1])*k)
        ans += aa(s[r:n+l+1])*k
        ans += aa(s[:r])
        ans += aa(s[n+l+1:])
else:
    ans += aa(s)*k

print(ans)

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

int main(){

	long long a = 0, b = 0;

	while (cin >> a >> b){
		long long gcd = 0;
		long long lcm = 0;
		long long r = 0;
		long long temp_a = 0, temp_b = 0;
		long long tmp = 0;
		temp_a = a;
		temp_b = b;
		if (temp_a < temp_b){
			tmp = temp_a;
			temp_a = temp_b;
			temp_b = tmp;
		}
		while (temp_a % temp_b != 0){
			r = temp_a % temp_b;
			temp_a = temp_b;
			temp_b = r;
		}
		gcd = temp_b;
		lcm = (a / gcd) * b;
		cout << gcd << " "<< lcm << endl;


	}

	//getchar();

	return 0;
}

Measured memory_bytes: 1156
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n,m,a[105],f[10000005][2];
int dfs(int x,int y){
    if(f[x][y]!=0)return f[x][y];
    int sum=0;
    for(int i=1;i<=n;i++)if(x>=a[i])if(dfs(x-a[i],1-y)==0)sum=1;
    return f[x][y]=sum;
}
int main(){
    in(n);in(m);
    for(int i=1;i<=n;i++)in(a[i]);
    puts(dfs(m,0)==1?"First":"Second");
	return 0;
}


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

int main()
{
	int k,n,i,j,l,sum;
	int a[100001],min=INT_MAX;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n-k+1;i++)
	{
		sum=0;
		for(j=i;j<i+k-1;j++)
			sum=sum+(a[j+1]-a[j]);
		if(sum<min) 
		{
			min=sum;
			l=i;
		}
	}
	cout<<a[l+k-1]-a[l]<<endl;
	return 0; 
}

Measured memory_bytes: 640