akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

const int MOD = 1'000'000'007;

struct mint {
  long long x;

  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(MOD - 2); }

  mint &operator/=(const mint a) { return *this *= a.inv(); }

  mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// n が小さいときの combination
struct combination {
  vector<mint> fact, ifact;

  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }

  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

// a が小さいときの combination
mint combination2(int n, int k) {
  mint x = 1; // 分子
  mint y = 1; // 分母
  for (int i = 0; i < k; i++) {
    x *= (n - i);
    y *= (k - i);
  }
  return x / y;
}

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
//  mint res = mint(10).pow(n);
//  res -= mint(8).pow(n);
//  res -= mint(9).pow(n) * 2;
//  res -= mint(9) * mint(8).pow(n - 1);
//  res -= mint(9) * mint(8).pow(n - 1);\

  mint res = mint(10).pow(n);
  combination x = combination(n);
  mint x2 = mint(9).pow(n);
  res -= x2;
  for (int i = 1; i <= n; i++) {
    mint x1 = x(n, i) * mint(8).pow(n - i);
    res -= x1;
  }

//  mint res = 1;
//  combination x = combination(n);
//  for (int i = 1; i < n; i++) {
//    res += x(n, i) * mint(8).pow(n - i) * 2;
//  }

//  mint res = combination2(n, 2) * 2;
//  res *= mint(8).pow(n - 2);
  cout << res.x << endl;
  return 0;
}


Measured memory_bytes: 18580
n = input()
if n[0]==n[1]==n[2]:
    print(n)
elif n[0]>n[1]:
    print(n[0]+n[0]+n[0])
elif n[0]<n[1]:
    t = str(int(n[0])+1)
    print(t+t+t)
elif n[0]==n[1]>n[2]:
    print(n[0]+n[0]+n[0])
elif n[0]==n[1]<n[2]:
    t = str(int(n[0])+1)
    print(t+t+t)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = LINF;
    ll N,C; cin >> N >> C;
    vector<vector<ll>> D(C+1,vector<ll>(C+1));
    vector<vector<ll>> c(N+1,vector<ll>(N+1));
    for(int i = 1; i <= C;i++)for(int j = 1; j <= C;j++) cin >> D[i][j];
    for(int i = 1; i <= N;i++)for(int j = 1; j <= N;j++) cin >> c[i][j];
    for(int i = 1; i <= C; i++){
        for(int j = 1; j <= C;j++){
            for(int k = 1; k <= C;k++){
      //          D[j][k] = min(D[j][k],D[j][i]+D[i][k]);
            }
        }
    }
    vector<vector<ll>> cnt(3,vector<ll>(C+1));
    for(int i = 1; i<=N;i++){
        for(int j = 1;j<=N;j++){
            cnt[(i+j)%3][c[i][j]]++;
        }
    }
//    cout << cnt << endl;
    for(int c1 = 1; c1 <= C; c1++){
        for(int c2 = 1; c2 <=C; c2++){
            if(c1 == c2) continue;
            for(int c3 = 1; c3 <= C;c3++){
                if(c1 == c3) continue;
                if(c2 == c3) continue;
                ll T = 0;
                for(int j = 1; j <= C;j++){
                    T += cnt[0][j]*D[j][c1];
                }
                for(int j = 1; j <= C;j++){
                    T += cnt[1][j]*D[j][c2];
                }
                for(int j = 1; j <= C;j++){
                    T += cnt[2][j]*D[j][c3];
                }
               // cout << c1 << " " << c2 << " " << c3 << endl;
               // cout << T << endl;
                res = min(res,T);
            }
        }
    }

    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(int i=1;i<=n;++i)
#define x first
#define y second
typedef long long ll;

int main(void){
	int N;
	cin>>N;
	vector<pair<ll,int>> a(N+1);
	rep1(i,N){
		cin>>a[i].x;
		a[i].y=i;
	}
	sort(a.begin(),a.end(),greater<pair<ll,int>>());
	vector<ll> cnt(N+1);
	int min_y = a[0].y;
	rep1(i,N){
		cnt[min_y] += i*(a[i-1].x-a[i].x);
		min_y = min(min_y,a[i].y);
	}
	rep1(i,N)cout<<cnt[i]<<endl;
	return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(Math.min(a, b) + Math.min(c, d));
		}
	}
}


Measured memory_bytes: 35580
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


int main()
{
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;

	bool f = true;

	if (a < b) {
		if (v <= w) f = false;
		else if (b - a > t * (v - w)) f = false;
	}
	else {
		if (v <= w) f = false;
		if (a - b > t * (v - w)) f = false;
	}
	if (f)  cout << "YES" << endl;
	else  cout << "NO" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,ans=1e9;
  cin >> n >> k;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0;i<=n-k;i++){
    ans=min(ans, abs(a[i]-a[i+k-1]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[500][500];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;cin>>n;
vector<ll> s(n),sum(n+1,0);
vector<vector<ll>> dp(n+1,vector<ll>(n+1,inf));
for(int i=0;i<n;i++)dp[i][i+1]=0;
for(int i=0;i<n;i++)cin>>s[i];
for(int i=0;i<n;i++)sum[i+1]=sum[i]+s[i];
for(int i=2;i<=n;i++){
    for(int l=0;l<=n-i;l++){
        int r=i+l;
        for(int k=l+1;k<r;k++){
            dp[l][r]=min(dp[l][r],dp[l][k]+dp[k][r]);
        }
        dp[l][r]+=(sum[r]-sum[l]);
    }
}
cout<<dp[0][n]<<endl;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int N,M,max1=0,all2=0;
	scanf("%d %d",&N,&M);
	int A[M]={0},B[M]={0};
	for(int i=0;i<M;i++)
	{
		scanf("%d %d",&A[i],&B[i]);
		if(A[i]>=N){}
		else if(max1<N-A[i])
		{
			all2+=max1;
			max1=(N-A[i]);
		}
		else
		{
			all2+=(N-A[i]);
		}
	}
	printf("%d\n",all2);
	return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
using namespace std;

int main(){
  int A, B, C, ans = 0;
  cin >> A >> B >> C ;
  if(A == B) ans++ ;
  if(C == B) ans++ ;
  if(A == C) ans++ ;
  if(ans == 1){
    cout << "Yes" << endl ;
  }  
  else{
    cout << "No" << endl ;
  }  
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 200001
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rer(i, a, b) for(ll i=a-1; i>=b; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n;

ll bit[MAX_N+1];

void init(ll _n){
    memset(bit, 0, _n+1);
}

void add(ll x, ll a){
    for(ll i=x; i<=n; i+=i&-i) bit[i] += a;
}

ll sum(ll x){
    ll ret = 0;
    for(ll i=x; i>0; i-=i&-i) ret += bit[i];
    return ret;
}

signed main(){
    string s; cin >> s;
    vector<ll> a[26];
    n = s.size();
    rep(i, 0, n){
        a[s[i]-'a'].pb(i);
    }
    ll odd = 0;
    rep(i, 0, 26){
        if(a[i].size()%2 == 1) odd++;
    }
    if(odd>=2){
        cout << -1 << endl;
        return 0;
    }

    string l, m, r;
    ll idx[26];
    rep(i, 0, n){
        ll j = s[i]-'a';
        if(a[j].size()%2 == 1){
            if(idx[j]<a[j].size()/2) l += s[i];
            else if(idx[j]==a[j].size()/2) m += s[i];
            else r += s[i];
        }
        else{
            if(idx[j]<a[j].size()/2) l += s[i];
            else r += s[i];
        }
        idx[s[i]-'a']++;
    }
    string kaibun = l + m;
    reverse(l.begin(), l.end());
    kaibun += l;
    // cout << kaibun << endl;

    ll b[MAX_N], idx2[26];
    rep(i, 0, n){
        ll j = kaibun[i] - 'a';
        b[i] = a[j][idx2[j]];
        idx2[j]++;
    }
    // rep(i, 0, n) cout << b[i] << " ";
    // cout << endl;
    // init(n);
    ll ret = 0;
    for(ll i=0; i<n; i++){
        ret += i - sum(b[i]+1);
        add(b[i]+1, 1);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 6020
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include <string.h>
int Anna[5005],Bluno[5005];
using namespace std;
int main(){
	int A,B,a;
	cin>>A>>B;
	for(int i=0;i<A;i++){
		cin>>a;
		Anna[i]=a;
	}
	for(int i=0;i<B;i++){
		cin>>a;
		Bluno[i]=a;
	}
	
	int ans=0;
	for(int i=0;i<B;i++){
		int k=i,cnt=0;
		for(int j=0;j<A;j++){
			if(Anna[j]==Bluno[k])cnt++,k++;
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1200
N,T = readline.split.map(&:to_i)

min = Float::INFINITY

N.times do |i|
  c,t = readline.split.map(&:to_i)
  if t <= T and c < min
    min = c
  end
end
if min == Float::INFINITY
  puts 'TLE'
else
  puts min
end


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


int n , k;

ll mem[N][5][3];
int a[N];

ll dp(int i , int cnt , int f){
    if(cnt > k)return 0;
    if(i == n){
            if(cnt == k)return 1ll;
            return 0;
    }
    ll &ret = mem[i][cnt][f];
    if(ret != -1)return ret;

    int mn = 0;
    int mx = a[i];
    if(f)mx = 9;

    ret = 0;
    for(int j = mn ; j <= mx ; j ++){
            ret += dp(i + 1 , cnt + (j != 0) , f | j < mx);
    }

    return ret;
}

void solve(int testCase){

    string s; cin >> s;
    for(int i = 0 ; s[i] ; i ++){
            a[i] = int(s[i] - '0');
    }
    n = s.length();

    scanf("%d" , &k);

    memset(mem , -1 , sizeof mem);
    ll ans = dp(0 , 0 , 0);

    printf("%lld\n" , ans);

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 23680
#include <stdio.h>

int main(void) {
  char c;

  while ((c = getchar()) != EOF) {
    if (c >= 'A' && c <= 'Z') {
      putchar(c - 'A' + 'a');
    } else if (c >= 'a' && c <= 'z') {
      putchar(c - 'a' + 'A');
    } else {
      putchar(c);
    }
  }

  return 0;
}

Measured memory_bytes: 524
'''
ITP-1_5-B
 ?????¬???????????????
??\????????????????????????H cm ?????? W cm ???????????????????????°?????????????????????????????????
##########
#........#
#........#
#........#
#........#
##########
?????????????????? 6 cm ?????? 10 cm ???????????¨??????????????????
???Input
??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????
H W
H, W ?????¨?????? 0 ?????¨????????\?????????????????¨????????????
???Output
?????????????????????????????????????????? H cm ?????? W cm ?????????????????????????????????
?????????????????????????????????????????????????????\??????????????????
'''
# import
import sys

for line in sys.stdin:
    # ?????°??????????????????
    H, W = map(int, line.split())
    if H == 0 and W == 0:
        break
    # ?????¢??????
    print('#' * W)
    for a in range(H-2):
        print('#'+'.'*(W-2)+'#')
    print('#' * W)
    print('')

Measured memory_bytes: 7608
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
   cin>>n;
   for(i=0,k=0;i<n;i++)
   {
       cin>>o;
       u[o]++;
   }
   for(MLL it=u.B;it!=u.E;it++)
   {
       if(it->SE%2==1)
       {
           k++;
       }
   }
   cout<<k<<endl;

    return 0;

}


Measured memory_bytes: 6528
use proconio::{fastout, input};
use std::collections::{HashMap, HashSet};

#[fastout]
#[allow(non_snake_case)]
#[allow(unused)]
fn main() {
    input! {
        W: usize,
        H: usize,
        M: usize,
        HW: [(usize, usize); M],
    }

    let mut xmax = 0;
    let mut ymax = 0;

    let mut xmap = HashMap::new();
    let mut ymap = HashMap::new();

    for &(x, y) in &HW {
        let xn = xmap.entry(x).or_insert(0);
        let yn = ymap.entry(y).or_insert(0);

        *xn += 1;
        *yn += 1;

        xmax = std::cmp::max(xmax, *xn);
        ymax = std::cmp::max(ymax, *yn);
    }

    let xs : Vec<usize> = xmap.iter().filter(|(&k, &v)| v == xmax).map(|(&k, &v)| k).collect();
    let ys : Vec<usize> = ymap.iter().filter(|(&k, &v)| v == ymax).map(|(&k, &v)| k).collect();

    let set: HashSet<(usize, usize)> = HW.clone().into_iter().collect();

    let res = xs.iter().find(|&&x| ys.iter().find(|&&y| !set.contains(&(x, y))).is_some()).is_some();
    let ans = xmax + ymax - (if res { 0 } else { 1 });

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

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

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

  vi a(N);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }

  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    if (a[i] % 2 == 0) {
      cnt += 1;
    }
  }

  if (cnt == N) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Winter Bells
public class Main{

	int[] d;
	void run(){
		Scanner sc = new Scanner(System.in);
		int INF = 1<<27;
		d = new int[100];
		int[][] wf = new int[100][100], e = new int[100][100];
		double[] K = new double[100], res = new double[100];
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt(), p = sc.nextInt();
			if((n|m|p)==0)break;
			for(int[]a:wf)Arrays.fill(a, INF);
			for(int[]a:e)Arrays.fill(a, INF);
			for(int i=0;i<n;i++)wf[i][i]=0;
			for(int i=0;i<m;i++){
				int s = sc.nextInt(), t = sc.nextInt(), c = sc.nextInt();
				e[s][t] = e[t][s] = wf[s][t] = wf[t][s] = c;
			}
			for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)wf[i][j]=Math.min(wf[i][j], wf[i][k]+wf[k][j]);
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					return d[o1]-d[o2];
				}
			});
			Arrays.fill(K, 0);
			K[n-1] = 1;
			for(int i=0;i<n;i++){
				d[i] = -wf[0][i]; q.add(i);
			}
			while(!q.isEmpty()){
				int v = q.poll();
				for(int i=0;i<n;i++){
					if(i==v || e[i][v]==INF)continue;
					if(wf[0][n-1]==wf[0][i]+e[i][v]+wf[v][n-1]){
						K[i]+=K[v];
					}
				}
			}
			Arrays.fill(res, 0);
			res[0] = 1;
			for(int i=0;i<n;i++){
				d[i]=wf[0][i];
				q.add(i);
			}
			while(!q.isEmpty()){
				int v = q.poll();
				for(int i=0;i<n;i++){
					if(i==v || e[v][i]==INF)continue;
					if(wf[0][n-1]==wf[0][v]+e[v][i]+wf[i][n-1]){
						res[i]+=res[v]*K[i]/K[v];
					}
				}
			}
			while(p--!=0)System.out.printf("%.8f\n", res[sc.nextInt()]);
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	N, M := nextInt(), nextInt()

	H := nextInt64s(N)
	Hscores := map[int]bool{}

	for i := 0; i < M; i++ {
		a, b := nextInt()-1, nextInt()-1
		if H[a] >= H[b] {
			Hscores[b] = false
		}
		if H[b] >= H[a] {
			Hscores[a] = false
		}
	}
	fmt.Println(N - len(Hscores))

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i], _ = strconv.ParseInt(next(), 10, 64)
	}
	return ret
}

func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 7904
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>

//fast(?) Input
#define buf_sz 1<<24
char buf[buf_sz];
unsigned int nextint(){
	static int idx = 0;
	if(idx == 0)read(0, buf, buf_sz);
	unsigned int res = 0;
	while(idx<buf_sz && buf[idx]<'0' || '9'<buf[idx])idx++;
	while(idx<buf_sz && '0'<=buf[idx] && buf[idx]<='9'){
		res *= 10;
		res += buf[idx++] - '0';
	}if(idx>=buf_sz)exit(1);
	return res;
}

long data[1<<19];
void fen_add(int p, long x, int N){
	p++;
	while(p<=N){
		data[p-1] += x;
		p += p & -p;
	}
}
long fen_sum(int r){
	long s = 0;
	while(r > 0){
		s += data[r-1];
		r -= r & -r;
	}
	return s;
}
long fen_range(int l, int r){
	return fen_sum(r) - fen_sum(l);
}

int main(){
	int N = nextint(), Q = nextint();
	for(int i=0; i<N; i++)fen_add(i, nextint(), N);
	while(Q--){
		if(nextint() == 1)printf("%ld\n", fen_range(nextint(), nextint()));
		else fen_add(nextint(), nextint(), N);
	}
	return 0;
}

Measured memory_bytes: 21312
def main():
  N = int(input())
  S = input()
  ans=S.count('R')*S.count('G')*S.count('B')
  for i in range(N):
    for j in range(i+1, N):
      k = 2*j-i
      if k>=N:
        break
      if (S[i]!=S[j]) and (S[j]!=S[k]) and(S[i]!=S[k]):
        ans-=1      
  print(ans)

if __name__=='__main__':
  main()


Measured memory_bytes: 9192
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    public static int gcd(int a, int b){
        if(a % b == 0)return b;
        return gcd(b, a % b);
    }
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt();

        System.out.println(gcd(x, y));

    }
  
}


Measured memory_bytes: 26144
#include <iostream>
#include <string>
#include <deque>
#include <algorithm>

using namespace std;

deque<string> bubbleSort(int n, deque<string> a) {
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = n - 1; j >= 1; --j) {
            if (a[j][1] < a[j - 1][1]) {
                string t = a[j];
                a[j] = a[j - 1];
                a[j - 1] = t;
                flag = true;
            }
        }
    }
    for (int i = 0; i < n-1; ++i) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl << "Stable" << endl;
    return a;
}

deque<string> selectionSort(int n, deque<string> a) {
    for (int i = 0; i <= n - 1; ++i) {
        int minj = i;
        for (int j = i; j <= n - 1; ++j) {
            if (a[j][1] < a[minj][1]) {
                minj = j;
            }
        }
        if (i != minj) {
            string t = a[i];
            a[i] = a[minj];
            a[minj] = t;
        }
    }

    for (int i = 0; i < n-1; ++i) {
        cout << a[i] << " ";
    }
    cout << a[n-1];
    return a;
}

int main(int argc, char* argv[]) {
    deque<string> a;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string x;
        cin >> x;
        a.push_back(x);
    }
    deque<string> bubble = bubbleSort(n, a);
    deque<string> selectio = selectionSort(n, a);

    if (bubble == selectio) {
        cout << endl << "Stable" << endl;
    }
    else {
        cout << endl << "Not stable" << endl;
    }

    return 0;
}




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

#define MAX_N 8000
#define MAX_M 23994

pair<double, int>a[MAX_N]; 
pair<double, int>b[MAX_N]; 
pair<double, int>c[MAX_N];
pair<double, int>d[MAX_M];

void _cin(int p) {
	for (int i = 0; i < p; i++) {
		cin >> a[i].second >> a[i].first;
	}
	for (int i = 0; i < p; i++) {
		cin >> b[i].second >> b[i].first;
	}
	for (int i = 0; i < p; i++) {
		cin >> c[i].second >> c[i].first;
	}
}

void sort1(int p) {
	sort(a, a + p);
	sort(b, b + p);
	sort(c, c + p);
	for (int i = 0; i < 6; i++) {
		d[i].first = a[i + 2].first;
		d[i].second = a[i + 2].second;
	}
	for (int i = 0; i < 6; i++) {
		d[i + p - 2].first = b[i + 2].first;
		d[i + p - 2].second = b[i + 2].second;
	}
	for (int i = 0; i < 6; i++) {
		d[i + p + p - 4].first = c[i + 2].first;
		d[i + p + p - 4].second = c[i + 2].second;
	}
	sort(d, d + p * 3 - 6);
}

void print() {
	cout << a[0].second << ' ' << a[0].first << endl;
	cout << a[1].second << ' ' << a[1].first << endl;
	cout << b[0].second << ' ' << b[0].first << endl;
	cout << b[1].second << ' ' << b[1].first << endl;
	cout << c[0].second << ' ' << c[0].first << endl;
	cout << c[1].second << ' ' << c[1].first << endl;
	cout << d[0].second << ' ' << d[0].first << endl;
	cout << d[1].second << ' ' << d[1].first << endl;
}

int main() {
	_cin(8);
	sort1(8);
	print();
	return 0;
}

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


int main(){
  int n,m,i,j;
  char Kim[2][1000000],Jong[1000000];
  for(i=0;i<1000000;i++){
    Jong[i]=0;
    Kim[0][i]=0;
    Kim[1][i]=0;
  }

  while(1){

  cin >> n;
  if(n == 0)break;

  for(i=0;i<n;i++){
    cin >> Kim[0][i];
    cin >> Kim[1][i];
  }

  cin >> m;

  for(i=0;i<m;i++){
    cin >> Jong[i];
  }


  for(i=0;i<m;i++){
    for(j=0;j<n;j++){
      if(Jong[i] == Kim[0][j]){Jong[i]=Kim[1][j];
	break;
    }
      }
  }

  for(i=0;i<m;i++){
    cout << Jong[i];
    }
  cout<< endl;
  }
}

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

int main()
{
    int n;
    cin>>n;
    vector<pair<int,int> > edges[n];
    for(int i=0; i<n-1; i++)
    {
        int a,b,c; 
        cin>>a>>b>>c; a--; b--;
        edges[a].push_back(make_pair(b,c));
        edges[b].push_back(make_pair(a,c));
    }
    int c[n]={0}; bool v[n]={0};
    queue<int> q; q.push(0);
    v[0]=1;
    while(!q.empty())
    {
        int z=q.front(); q.pop();
        for(int i=0; i<edges[z].size(); i++)
        {
            if(!v[edges[z][i].first])
            {
                v[edges[z][i].first]=1;
                if(edges[z][i].second%2==0) c[edges[z][i].first]=c[z];
                else c[edges[z][i].first]=c[z]^1;
                q.push(edges[z][i].first);
            }
        }
    }
    for(int i=0; i<n; i++)
        cout<<c[i]<<endl;
    return 0;
}


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


using namespace std;

const int N = 2e3+5 , mod = 1000000007;
int n ,k;
int A[N];

int main(){

    cin>>n>>k;
    long long K = (1ll*k*(k-1)/2ll)%mod;
    for(int i = 0;i<n;i++)
    {
        cin>>A[i];
    }
    long long ans = 0;
    long long a = 0 , b =0;
    for(int i = 0;i<n;i++)
    {
        a = b = 0;
        for(int j = 0;j<n;j++)
        {
            if(A[j]<A[i])
            {
                if(j>i)
                    b++;
                a++;
            }
        }
        ans+=(b*k)%mod;
        ans%=mod;
        ans+=(a*K)%mod;
        ans%=mod;
    }
    cout<<ans%mod;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
using namespace std;
struct Solution {
public:
    bool isGuu(string s, int t) {
        string s1 = s.substr(0, t / 2);
        string s2 = s.substr(t / 2, t / 2);
        return s1 == s2;
    }
    void solve(std::istream& in, std::ostream& out) {
        string S;
        in >> S;
        int ans = 0;
        int len = S.size();
        reu(i, 1, len) {
            if ((len - i) % 2 == 0)
            {
                if (isGuu(S, (len - i))) {
                    ans = (len - i);
                    break;
                }
            }
        }
        out << ans << endl;
    }
};
void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int partition(int, int);

int A[MAX], n;

int main(){
  int i, q;

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

  q = partition(0, n-1);

  for(i=0; i<n; i++){
    if(i==q) printf("[");
    if(i<n-1&&i!=q) printf("%d ",A[i]);
    else if(i==q) printf("%d",A[i]);
    else if(i==n-1)printf("%d\n",A[i]);
    if(i==q) printf("] ");
}

return 0;
}

int partition(int p, int r){
int x, i, j, t;
x = A[r];
i = p-1;
for(j=p; j<r; j++){
  if(A[j]<=x){
  i++;
  t = A[i];
  A[i] = A[j];
  A[j] = t;
}
}
t = A[i+1];
A[i+1] = A[r];
A[r] = t;
return i+1;
}



Measured memory_bytes: 2084
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int N, X, T;
 cin >> N >> X >> T;
 int A;
 A=N/X;
 if(N%X!=0)A++;
 A*=T;
 cout << A << endl;
}


Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int n;string s;
  cin >> n;
  int ans[n];
  int wr[n];int er[n];
  int wl[n];int el[n];
  for(int i=0;i<n;i++) wr[i]=0;
  for(int i=0;i<n;i++) er[i]=0;
  for(int i=0;i<n;i++) wl[i]=0;
  for(int i=0;i<n;i++) el[i]=0;
  cin >> s;
  for(int i=1;i<n;i++){
    if(s[i-1]=='W'){
       wl[i]++;
    }
    else el[i]++;
    wl[i]+=wl[i-1];el[i]+=el[i-1];
  }
  for(int i=n-2;i>=0;i--){
    if(s[i+1]=='W'){
       wr[i]++;
    }
    else er[i]++;
    wr[i]+=wr[i+1];er[i]+=er[i+1];
  }
  for(int i=0;i<n;i++){
    ans[i]=(wl[i]+er[i]);
  }
  sort(ans,ans+n);
  cout << ans[0]<<endl;
}


Measured memory_bytes: 6532
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N, cnt = 0;

    cin >> N;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (s == "A") { cnt++; }
        else {
            cnt--;
            if (cnt < 0) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << (cnt == 0 ? "YES" : "NO") << endl;
    
    return 0;
}


Measured memory_bytes: 3152
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

int main(){
int N,K;
cin >> N >> K;
vector<long long> A(N);
for(int i = 0;i<N;i++)cin >> A[i];
cout << ((N-1)+(K-1-1))/(K-1) <<endl;
}



Measured memory_bytes: 1024
n = int(input())
a = [int(i) for i in input().split()]

import statistics
check = []
for i in range(n):
    check.append(a[i] - (i+1))
check = sorted(check)
b = statistics.median(check)

ans = 0
for i in range(n):
    ans += abs(a[i] -(b+i+1))
print(int(ans))

Measured memory_bytes: 26128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

int main()
{
    int n;
    std::string s;

    std::cin >> n;
    std::cin >> s;

    int dp[200010][2] = {};

    dp[0][0] = 0;
    dp[n][1] = 0;

    for(int i=1; i<=n; i++){
        dp[i][0] = dp[i-1][0];
        if(s[i-1]=='#')
            dp[i][0]++;
    }

    for(int i=n-1; i>=0; i--){
        dp[i][1] = dp[i+1][1];
        if(s[i]=='.'){
            dp[i][1]++;
        }
    }
    int ans = dp[0][0] + dp[0][1];
    for(int i=1; i<=n; i++)
        ans = std::min(ans,dp[i][0]+dp[i][1]);
 /*
    for(int i=0; i<=n;i++)
        std::cout << dp[i][0] << ",";
    std::cout <<  std::endl;

    for(int i=0; i<=n;i++)
        std::cout << dp[i][1] << ",";
    std::cout <<  std::endl;
*/
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 2180
q=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
N=int(input())
p={}
for i in range(N):
 n=i+1
 for j in range(25):
  if n==1 or n<q[j]:break
  while n%q[j]==0:p[q[j]]=1if q[j]not in p.keys()else p[q[j]]+1;n//=q[j]
n=[1,3,13,23,73]
m=[len([v for v in p.values()if v>k])for k in n]
print(m[1]*~-m[1]//2*(m[0]-2)+m[3]*~-m[0]+m[2]*~-m[1]+m[4])

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

#define ll long long
#define ull unsigned long long

string s, t;

void solve() {
    cin >> s >> t;
    int ans=0;
    for(int i=0; i<s.length(); ++i) {
        if(s[i]!=t[i])
            ans++;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

Measured memory_bytes: 3852
import java.util.*;
import java.io.*;

public class Main {
    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

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

        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

    static final FS sc = new FS();
    static final PrintWriter out = new PrintWriter(System.out);
    static final int mod = 1000000007;

    public static void main(String[] args) {

        solve();
        out.close();

    }

    static void solve() {
        long a = sc.nextInt();
        int b = sc.nextInt();
        if (a + b < 24) {
            out.println(a + b);
        } else {
            out.println((a + b) % 24);
        }

    }
}





Measured memory_bytes: 32856
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	loop(i,1,n+1)if(n%i==0){
		bool h=true;
		rep(j,n-i)if(in[j]!=in[j+i]){h=false;break;}
		if(h){cout<<n/i<<endl;return 0;}
	}
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int d, t, s;
    cin >> d >> t >> s;

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

    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
long long arr[2003][2003],cnt[2005];
int main()
{
	long long i,j,k,n,m,x,y,z,yy;
	cin>>n>>x>>y;
	for (i=1;i<=n;i++)
	{
		for (j=i+1;j<=n;j++)
		{
			arr[i][j]=j-i;
		}
	}
	z=arr[x][y]-1;
	for (i=1;i<=x;i++)
	{
		for (j=y;j<=n;j++)
		{
			arr[i][j]=arr[i][j]-z;
		}
	}
	for (i=1;i<=x;i++)
	{
		for (j=y-1;j>x;j--)
		{
			yy=arr[i][y]+y-j;
			arr[i][j]=min(yy,arr[i][j]);
		}
	}
	for (i=x;i<y;i++)
	{
		for (j=y;j<=n;j++)
		{
			yy=arr[x][j]+i-x;
			arr[i][j]=min(yy,arr[i][j]);
		}
	}
	for (i=x;i<=y;i++)
	{
		for (j=y;j>i;j--)
		{
			yy=i-x+y-j+1;
			arr[i][j]=min(yy,arr[i][j]);
		}
	}	
	for (i=1;i<=n;i++)
	{
		for (j=i+1;j<=n;j++)
		{
			//cout<<arr[i][j]<<" ";
			cnt[arr[i][j]]++;
		}
		//cout<<endl;
	}
	for (i=1;i<n;i++)
	{
		cout<<cnt[i]<<endl;
	}	
}

Measured memory_bytes: 31104
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

m, a, b = mi()

P = 10**9+7
N = 2*(10**5)+1
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

mca = mcb = 1

for i in range(1, a+1):
    mca *= (m-i+1) * inv_t[i]
    mca %= P

for i in range(1, b+1):
    mcb *= (m-i+1) * inv_t[i]
    mcb %= P

print(((2**m)-mca-mcb-1)%P)

Measured memory_bytes: 286284
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=2010;
int n,a[N];

int slow() {
    VI v;
    REP(i,1<<n) {
        int s=0;
        REP(j,n) if ( (i>>j)&1 ) s+=a[j];
        v.PB(s);
    }
    sort(ALL(v));
    // dump(v);
    return v[(1<<n)/2];
}

bitset<N*N> dp;
void main() {
    R(n);
    REP(i,n) R(a[i]);
    sort(a,a+n);
    dp[0]=1;
    REP(i,n) dp|=dp<<a[i];
    int s=0;
    REP(i,n) s+=a[i];
    s=(s+1)/2;
    while ( !dp[s] ) s++;
    W(s);
#ifdef SHIK
    int slow_ans=slow();
    dump(slow_ans);
    assert(s==slow_ans);
#endif
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


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

int V[102], C[102];

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;

    for(int i=1; i<=N; i++)
        cin >> V[i];

    for(int i=1; i<=N; i++)
        cin >> C[i];

    int ans = 0;

    for(int i=1; i<=N; i++)
        ans += max(0, V[i] - C[i]);

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int cnt;

void merge(int a[], int left, int mid, int right) {
    int L[MAX/2 + 2], R[MAX/2 + 2];
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = a[left + i];
    for (int i = 0; i < n2; i++) R[i] = a[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            a[k] = L[i++];
        } else {
            a[k] = R[j++];
        }
    }
}

void mergeSort(int a[], int n, int left, int right) {
    if (left+1 < right) {
        int mid = (left + right) / 2;
        mergeSort(a, n, left, mid);
        mergeSort(a, n, mid, right);
        merge(a, left, mid, right);
    }
}

int main() {
    int a[MAX], n;
    cnt = 0;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    mergeSort(a, n, 0, n);

    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;

    cout << cnt << endl;
}



Measured memory_bytes: 7000
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;

void sieve();

vector<bool> prime(300001, true);

int main()
{
    int n;
    sieve();
    while (cin >> n, n != 1) {
        cout << n << ":";
        for (int i = 2; i <= n; i++) {
            if (prime[i] && !(n % i)) {
                cout << " " << i;
            }
        }
        cout << endl;
    }
    return 0;
}

void sieve()
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i < 300001; i++) {
        if (prime[i]) {
            if (i % 7 == 1 || i % 7 == 6) {
                for (int j = 2; j * i < 300001; j++) {
                    prime[i*j] = false;
                }
            } else {
                prime[i] = false;
            }
        }
    }
}

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










const long int INF = 1e9+5;

int main()
{
int n,k;
cin >> n >> k;
vector <int> dp(n+1,INF),a(n+1);
for (int i=0; i<n; i++) cin >> a[i];
dp[0]=0;
for (int i=1; i<n; i++)
for (int  j=i-1; j>=max(0,i-k); j--)
    dp[i] = min(dp[i],  dp[j] + abs(a[i]-a[j]));
    //for (int i=0; i<=n; i++) cout << dp[i] << "\n"[i!=n];
cout << dp[n-1];

}

/*
10
10 3
1 2 3 4 5 6 7 8 9 10
3 3 4
*/



Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	std::string s,t;
	std::cin >> s >> t;
	int n,m;
	n=s.size();m=t.size();
	int min=m;
	rep(i,n-m+1) {
		int x=0;
		rep(j,m) {
			if(s[i+j]!=t[j]) x++;
		}
		min=std::min(min,x);
	}
	print(min);
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;
#define Test
const int MAX = 110000;
const int INF = 10000000;
vector<pair<int, int> > G[MAX];
int n;
int dis[MAX];
int vis[MAX];

void dij(int p) {
    for (int i = 0; i < n; i++) dis[i] = INF;
    memset(vis, false, sizeof(vis));
    dis[p] = 0;
    priority_queue<pair<int, int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push(make_pair(0, p));
    while (!pq.empty()) {
        pair<int, int> pr = pq.top();
        pq.pop();
        int point = pr.second;
        if (vis[point]) continue;
        dis[point] = pr.first;
        vis[point] = true;
        for (int i = 0; i < G[point].size(); i++) {
            int pt = G[point][i].second;
            int v = G[point][i].first;
            if (!vis[pt] && dis[pt] > dis[point]+v) {
                dis[pt] = dis[point] + v;
                pq.push(make_pair(dis[pt], pt));
            }
        }
    }
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int p, k;
        scanf("%d %d", &p, &k);
        while (k--) {
            int v, c;
            scanf("%d %d", &v, &c);
            G[p].push_back(make_pair(c, v));
        }
    }
    dij(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, dis[i]);
    }
    return 0;
}

Measured memory_bytes: 6248