akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

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

  vector<ll> A(N), B(N);
  for(ll i=0; i<N; ++i) cin >> A[i] >> B[i];

  ll M = H+10010;
  ll INF = 1000000000;
  vector<ll> dp(M, INF);
  dp[0] = 0;
  for(ll x=1; x<M; ++x) {
    for(ll j=0; j<N; ++j) {
      if(x-A[j]<0) continue;
      dp[x] = min(dp[x], dp[x-A[j]]+B[j]);
    }
  }

  ll ans = INF;
  for(ll x=H; x<M; ++x) ans = min(ans, dp[x]);
  cout << ans << endl;

}


Measured memory_bytes: 384
use std::vec::Vec;
use std::cmp::*;
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let mut hash: HashSet<usize> = HashSet::new();
  let (n, m) = {
    let v: Vec<usize> = read_vec();
    (v[0], v[1])
  };
  let mut v: Vec<(usize, usize, i64)> = Vec::new();
  for _ in 0..m {
    let t: Vec<usize> = read_vec();
     v.push((t[0] - 1, t[1] - 1, t[2] as i64));
     hash.insert(t[0] - 1);
     hash.insert(t[1] - 1);
  }

  let mut posit: Vec<i64> = vec![std::i64::MAX; n];

  let g = Graph::new(n, &v);

  for i in hash {
    if posit[i] == std::i64::MAX {
      posit[i] = 0;
      g.dfs(i, &mut posit);
    }
  }

  let mut b = true;
  for &e in &v {
    if posit[e.1] - posit[e.0] != e.2 {
      b = false;
      break;
    }
  }

  if b {
    println!("Yes");
  } else {
    println!("No");
  }
}


#[derive(Debug, Clone)]
struct Graph {
  n: usize,                            // number of nodes
  graph: Vec<Vec<(usize, i64)>>,              // second: to node, third: cost
}

impl Graph {
  // constructor
  fn new(n: usize, v: &Vec<(usize, usize, i64)>) -> Graph {
    let mut g: Vec<Vec<(usize, i64)>>  = vec![Vec::new(); n];
    for &(from, to, cost) in v {
      g[from].push((to, cost));
      g[to].push((from, -cost));
    }

    Graph {
        n: n,
        graph: g,
    }
  }

  // depth first search
  fn dfs(&self, start: usize, v: &mut Vec<i64>) {
    let mut visit: Vec<bool> = vec![false; self.n];    // record already visit to node
    let mut stack: Vec<(usize, i64)> = Vec::new();

    // init
    visit[start] = true;
    stack.push((start, 0));

    while !stack.is_empty() {
      let node: usize = match stack.pop() {
        None => panic!("unifined"),
        Some(i) => i.0,
      };


      for &e in &self.graph[node] {
        if !visit[e.0] {
          stack.push(e);
          visit[e.0] = true;  // already visit node v, so mark
          v[e.0] = e.1 + v[node];
        }
      }
    }

  }
}


Measured memory_bytes: 28816
def main():
    a, b = map(int, input().split())
    s = input()
    all_l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    hyphen = ['-']

    answer = 'Yes'
    for i in range(len(s)):
        if i == a:
            if s[i] not in hyphen:
                answer = 'No'
        else:
            if s[i] not in all_l:
                answer = 'No'

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61808
from collections import *
import sys
inp = raw_input

def err(s):
    sys.stderr.write('{}\n'.format(s))

def ni():
    return int(inp())

def nl():
    return [int(_) for _ in inp().split()]

N, D = nl()
lo = 2*D + 1
print((N + lo - 1)/lo)


Measured memory_bytes: 2812
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i) 
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vlli vector<long long int>
#define pb push_back
#define mp make_pair
#define all(c)  ((c).begin()), ((c).end())
using namespace std;
int main(){
	int n;
	cin>>n;
	long long int p=1;
	FOR(i,1,n+1)
		p=(p*i)%1000000007;
	cout<<p;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int N;
	static long ans;
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	N=sc.nextInt();
    	luca(2,1,0);
    	System.out.println(ans);

	}
	public static void luca(long a,long b,int n) {
		if(n>=N) {
			ans=a;
			return;
		}
		luca(b,a+b,n+1);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
    cout << (n + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
h,w = map(int, input().split( ))
a = []
for i in range(h):
    ai = list(map(int, input().split( )))
    a.append(ai)
for i in range(h):
    bi = list(map(int, input().split( )))
    for j in range(w):
        a[i][j]-=bi[j]
        a[i][j] = abs(a[i][j])
###差のmaxまでをlistで確保する代わりに可能な値をsetで保持
###値が小さいのでsetからbitで保持に変更
dp = [[0 for j in range(w)] for i in range(h)]
a2 = [a[i][j] for i in range(h) for j in range(w)]
mxa = max(a2)
###中心を取る
###間違えやすいし最大値決め打ちか
tmp=1<<mxa*(h+w)+10

dp[0][0]|=tmp<<a[0][0]
dp[0][0]|=tmp>>a[0][0]

for j in range(1,w):
    dp[0][j]=dp[0][j-1]<<a[0][j]
    dp[0][j]|=dp[0][j-1]>>a[0][j]

for i in range(1,h):
    for j in range(w):###ループ一つ抜けてるわw
        dp[i][j]=dp[i-1][j]<<a[i][j]
        dp[i][j]|=dp[i-1][j]>>a[i][j]
        if j:
            dp[i][j]|=dp[i][j-1]<<a[i][j]
            dp[i][j]|=dp[i][j-1]>>a[i][j]

tmp1 = dp[h-1][w-1]

tmp1>>=mxa*(h+w)+10

###mxa=0でrange(0)になる式だと答えが出ない
for k in range(mxa*(h+w)+10):
    if tmp1&1:
        print(k)
        exit()
    tmp1>>=1


Measured memory_bytes: 20084
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    long long x[200000] = {}, y[200000] = {};
    long long xs = 0, ys = 0;
    for(int i=0; i<n; i++){
        xs += a[i];
        x[i] = xs;
        ys += a[n-i];
        y[n-i] = ys;
    }

    long long ans = 200000000000000;
    for(int i=0; i<n-1; i++){
        ans = min(ans, abs(x[i] - y[i+1]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4096
n = int(input())
X = []
Y = []
ans = 0
for _ in range(n):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
for i in range(n):
    for j in range(n):
        ans  += ((X[i]-X[j])**2 + (Y[i]-Y[j])**2)**0.5
print(ans/n)

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

int main () {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int>C(N);
  vector<vector<int>> data(N, vector<int>(M));
  vector<int>skills(M,0);
 
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> data.at(i).at(j);
      skills.at(j) += data.at(i).at(j);
    }
  }
  
  for (int i = 0; i < M; i++) {
    if (skills.at(i) < X){
      cout << -1 << endl;
      return 0;
    }
  }
  
  int Min = 10000000;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 12); tmp++) {
    bitset<12> s(tmp);  // 最大20個なので20ビットのビット列として扱う
    
    if (N < 12 && s.test(N)) {
      break;
    }

    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int price = 0;
    vector<int>skill(M,0);
    
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        for (int j = 0; j < M; j++) {
          skill.at(j) += data.at(i).at(j);
        }
        price += C.at(i);
      }    
    }
    for (int i = 0; i < M; i++) {
      if (skill.at(i) < X){
        break;
      }
      else if (i == M-1){
        if (price < Min){
          Min = price;
        }
      }
    }
  }
  
  cout << Min << endl;
}

  

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<char,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

vector<vector<int>> nx(const string &s){
    int n = s.length();
    vector<vector<int>> ret(n+1,vector<int> (26,n));
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            ret[i][j] = ret[i+1][j];
        }    
        ret[i][s[i]-'a'] = i;
    }
    return ret;
}

int main(){
    string s;cin >> s;
    int n = s.length();
    auto p = nx(s);
    vector<int> dp(n+2,INF);
    vector<P> res(n+2,mp(',',0));
    for (int i = 0; i <= 26; i++) {
        res[n+1] = mp('a',1);
    }
    dp[n+1] = 0;
    for (int i = n; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            int t = n;
            if(i!=n) t = p[i][j];
            if(dp[i] > dp[t+1] + 1){
                dp[i] = dp[t+1] + 1;
                res[i] = mp('a'+j,t+1); 
            }
        }
    }
    int idx = 0;
    while(idx<n){
        cout << res[idx].fs;
        idx = res[idx].sc;
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 29316
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define MAX 25

int N;
int POW[MAX];
bool is_dead[1024*1024];

int main(){

	POW[0] = 1;
	for(int i = 1; i < MAX; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d",&N);

	int tmp;
	int ans = 0;

	for(int state = 0; state < POW[N]; state++){

		scanf("%d",&tmp);
		is_dead[state] = (tmp==1);

		if(is_dead[state]){

			//部分集合が全て生きか調べる
			bool FLG = true;

			for(int i = 0; i < N; i++){

				if(state & POW[i]){
					if(is_dead[state-POW[i]]){
						FLG = false;
						break;
					}
				}
			}

			//初めての死→穴が全て塞がれた肺あり
			if(FLG)ans++;

		}else{ //生き

			//部分集合に死がないか調べる

			for(int i = 0; i < N; i++){

				if(state & POW[i]){
					if(is_dead[state-POW[i]]){

						printf("-1\n");
						return 0;
					}
				}
			}
		}
	}

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

	return 0;
}



Measured memory_bytes: 4248
a = []
while True:
    try:
        a.append(int(input()))
    except:
        break

def time(at):
    t = 0
    while t < at:
        t += 10
    return t, t - at

st = 0
max_d = 0
for i in a:
    t, d = time(i)
    st += t
    if max_d < d:
        max_d = d

print(st - max_d)

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

using LL = long long;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

	string s; cin >> s;
    int ans = -1;
    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;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m;
bool jfsort(PII a, PII b) {
	return a.first > b.first;
}
bool jssort(PII a, PII b) {
	return a.second < b.second;
}

// index が条件を満たすかどうか vector<>maeに検索したいvectorを入れる keyを超える最小の要素番号を返す
bool isOK(int index, long long key, deque<PII>&mae) {
	if (mae[index].second >= key) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(long long key, deque<PII>&mae) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)mae.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key, mae)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

int main() {
	cin >> n >> m;
	long long ans = 0;
	vector<PII>job(n);
	for (int i = 0; i < n; i++)
	{
		cin >> job[i].first >> job[i].second;//fir日sec報酬
	}
	sort(job.begin(), job.end(),jfsort);
	deque<PII>temp;
	int iter = n - 1;
	for (int i = 0; i < m; i++)
	{
		while (iter+1) {
			if (job[iter].first == i + 1) {
				int a = binary_search(job[iter].second, temp);
				temp.insert(temp.begin()+a,job[iter]);
				iter--;
			}
			else {	
				break;
			}
		}
		int siz = temp.size();
		if (siz - m + i>0) {  temp.erase(temp.begin(), temp.begin() + (siz - m + i)); }//
		if (temp.size()) {
			ans += temp.back().second;
			temp.pop_back();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::{min, max};
fn main() {
    input!{
        k: i32,
        x: i32,
    }
    for i in max(-1000000, x - k + 1)..min(1000000, x + k - 1) + 1 {
        println!("{}", i);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
 
int main()
{
  string s;
  cin>>s;
  
  sort(s.begin(), s.end());
  if(s[0]!=s[2])
    	cout<<"Yes\n";
  else
    cout<<"No\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e2+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s;
	cin >> s;
	for (auto i : s)
	{
		if (i == '7')
			return cout << "Yes", 0;
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 1048576
bool p[N] = {1,1};
vl v;

int main(){
	REP(i, N){
		if(p[i]) continue;
		for(int j = i*2; j < N; j+=i) p[j]=true;
		for(ll j = i; j <= 1'000'000'000'000LL; j *= i) v.EB(j);
	}
	sort(ALL(v));

	ll n; scanf("%lld", &n);
	ll ans = 0;
	for(ll i : v){
		if(n % i == 0){
			n /= i;
			ans++;
		}
	}
	REP(i, N) if(!p[i]) while(n%i==0) n/=i;
	if(n>1) ans++;
	printf("%lld\n", ans);
}


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

string s;

int main(void)
{
	int i, j, ans = 0;

	cin >> s;

	for (i = 0; i < 3; i++)
	{
		for (j = i; j < 3; j++)
			if (s[j] != 'R')
				break;

		ans = max(ans, j - i);

		if (i == j)
			i = j;
		else
			i = j - 1;
	}

	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a,b,c,f=0;
	cin>>a>>b>>c;
	r(i,1000)if((a*i)%b==c)f++;
	cout<<(f?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
# C
import collections
n = int(input())
lst = list(map(int, input().split()))
lst1 = lst[::2]
lst2 = lst[1::2]
dct1 = sorted(dict(collections.Counter(lst1)).items(), key=lambda x:-x[1])
dct2 = sorted(dict(collections.Counter(lst2)).items(), key=lambda x:-x[1])


ans = 0
if (len(dct1) == 1 and len(dct2) == 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = dct1[0][1]
	else:
		ans = 0
elif (len(dct1) == 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = n // 2 - dct2[1][1]
	else:
		ans = n // 2 - dct2[0][1]
elif (len(dct2) == 1 and len(dct1) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = n // 2 - dct1[1][1]
	else:
		ans = n // 2 - dct1[0][1]
elif (len(dct1) > 1 and len(dct2) > 1):
	if (dct1[0][0] == dct2[0][0]):
		ans = n - max(dct1[0][1] + dct2[1][1], dct1[1][1] + dct2[0][1])
	else:
		ans = n - dct1[0][1] - dct2[0][1]
print(ans)

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int s, w;
  cin >> s >> w;
  if(w >= s){
    cout << "unsafe";
  }else{
    cout << "safe";
  }
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    // double xm = 0, ym = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        // xm += x[i];
        // ym += y[i];
    }
    double ret = 1e10;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            double r  = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) / 2.0;
            double mx = (x[i] + x[j]) / 2;
            double my = (y[i] + y[j]) / 2;
            bool ok   = true;
            for (int k = 0; k < n; ++k) {
                double dist = sqrt((x[k] - mx) * (x[k] - mx) + (y[k] - my) * (y[k] - my));
                if (dist > r + 1e-10) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                chmin(ret, r);
                continue;
            }
            for (int k = 0; k < n; ++k) {
                if (k == i || k == j)
                    continue;
                double a  = x[i];
                double b  = y[i];
                double c  = x[j];
                double d  = y[j];
                double e  = x[k];
                double f  = y[k];
                double aa = a * a;
                double bb = b * b;
                double cc = c * c;
                double dd = d * d;
                double ee = e * e;
                double ff = f * f;
                double py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee - ff)) /
                            (2 * (e - a) * (b - d) - 2 * (c - a) * (b - f));
                double px = 0;
                if (c == a)
                    px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a));
                else
                    px = (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a));
                double rn = sqrt((x[i] - px) * (x[i] - px) + (y[i] - py) * (y[i] - py));
                bool ok   = true;
                for (int l = 0; l < n; ++l) {
                    double distn = sqrt((x[l] - px) * (x[l] - px) + (y[l] - py) * (y[l] - py));
                    if (distn > rn + 1e-10) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    chmin(ret, rn);
                    continue;
                }
            }
        }
    }
    cout << fixed << setprecision(10) << ret << "\n";

    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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


    lint h,w;
    cin >> h >> w;

    lint ans, tmp;

    ans = h * w / 2 + (h * w) % 2;

    if(h==1||w==1){
        cout << 1 << "\n";
        return 0;
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[3];
  bool test=true;
  long long k,a[3]={};
  cin>>s[0]>>k;
  for(int j=1; j<s[0].length(); j++) if(s[0][j]!=s[0][j-1]) test=false;
  for(size_t i=0;i<2;++i) s[i+1]=s[i]+s[0];
  for(size_t i=0;i<3;++i) for(size_t j=0;j<s[i].length()-1;++j) if(s[i][j]==s[i][j+1]) ++a[i],++j;
  if(test) cout << s[0].length() * k / 2;
  else cout<<a[0]+(k-1)*(a[1]-a[0])<<std::endl;
}


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {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};

int main() {
	int a;
	cin >> a;
	int b[a];
	int ans = 0;
	for (int i = 0;i < a;i++) {
		cin >> b[i];
		ans+=b[i];
	}
	sort(b,b+a);
	cout << ans - b[a-1] / 2;
}

Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}

int log(int x) {
    int i;
    for(i=0;(1<<i)<=x;i++);
    return i;
}

vector<int> osci(vector<int> v) {
	vector<int> v1;
	int n=v.size();
	int i=0,j=n-1;
	for(int k=0;k<n;k++) {
		if(k%2==0)
			v1.pb(v[i++]);
		else
			v1.pb(v[j--]);
	}
	reverse(all(v1));
	return v1;
} 
 
int32_t main() {
    fio
	cout << fixed << setprecision(15);
    
    //int n;cin >> n;
    string s;cin>>s;
    map<char,int> m;
    //int x=0,c=0;
    for(auto i:s) {
        if(m[i]==1) {
            cout << "no";
            return 0;
        }
        m[i]=1;
    }
    
    cout << "yes";
	return 0;
    
}

Measured memory_bytes: 8832
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;

int main(){
    string S;
    cin >> S;
    int year = atoi(S.substr(0,4).c_str());
    int month = atoi(S.substr(5,7).c_str());
    int day = atoi(S.substr(8,10).c_str());
    
    if(year < 2019){
        cout << "Heisei" << endl;
    }else if(year > 2019){
        cout << "TBD" << endl;
    }else{
        if(month <= 4){
            if(day <= 30){
                cout << "Heisei" << endl;
            }else{
                cout << "TBD" << endl;
            }
        }else{
            cout << "TBD" << endl; 
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    static Scanner sc;
    static final double th = Math.PI * 60.0 / 180.0;

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

        Point a = new Point(0, 0);
        Point b = new Point(100, 0);
        int n = sc.nextInt();

        System.out.printf("%.8f %.8f\n", a.x, a.y);
        koch(n, a, b);
        System.out.printf("%.8f %.8f\n", b.x, b.y);
    }

    static void koch(int n, Point a, Point b) {
        if(n == 0) return ;
        Point s = new Point((2.0 * a.x + b.x) / 3.0, (2.0 * a.y + b.y) / 3.0);
        Point t = new Point((2.0 * b.x + a.x) / 3.0, (2.0 * b.y + a.y) / 3.0);

        double ux = (t.x - s.x) * Math.cos(th) -
                            (t.y - s.y) * Math.sin(th) + s.x;
        double uy = (t.x - s.x) * Math.sin(th) +
                            (t.y - s.y) * Math.cos(th) + s.y;
        Point u = new Point(ux, uy);

        koch(n-1, a, s);
        System.out.printf("%.8f %.8f\n", s.x, s.y);
        koch(n-1, s, u);
        System.out.printf("%.8f %.8f\n", u.x, u.y);
        koch(n-1, u, t);
        System.out.printf("%.8f %.8f\n", t.x, t.y);
        koch(n-1, t, b);
    }
}

class Point {
    public double x;
    public double y;

    public Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
}



Measured memory_bytes: 42184
#include <stdio.h>

int main(void) {

  int h, w, i, j;
  while(1) {
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0) break;

    for(i =1; i <= h; i++) {
      for(j = 1; j <= w; j++) {
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
 
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int n,m,c[100];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		int t; scanf("%d",&t);
		for (int j=1;j<=t;j++) {
			int x; scanf("%d",&x);
			c[x]++;
		}
	}
	int ans=0;
	for (int i=1;i<=m;i++) 
		if (c[i]==n) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int l, r, d; cin >> l >> r >> d;
	int ans = r / d - l / d;
	if (l % d == 0) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

V = list(map(int, input().split()))
C = list(map(int, input().split()))

V_minus_C = []

for i in range(N):
    V_minus_C.append(V[i]-C[i])

V_minus_C.sort(reverse=True)

ans = 0
for i in range(len(V_minus_C)):
    if V_minus_C[i] > 0:
        ans += V_minus_C[i]

print(ans)

Measured memory_bytes: 38256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
 
#define N 3
#define M 5
 
int n, m, s[5];
char c[5];  

int main(){
    scanf("%d %d",&n, &m);
    for (int i = 0; i < m; i++){
        scanf("%d %c",&s[i], &c[i]);     
    }
    
    char ans[3]={'n','n','n'};
    for (int i = 0; i < m; i++){
        if(ans[s[i]-1]=='n'){
            ans[s[i]-1] = c[i];
        }
        else if(ans[s[i]-1]!=c[i]){
            printf("-1\n");
            return 0;
        }
    }
    for (int j = 0; j < n; j++){
        if(ans[j]=='n'){
            if(j==0 && n!=1){
                ans[j] = '1';
            }
            else{
                ans[j] = '0';
            }
        }
    }
    if( n!=1 && atoi(ans)<pow(10,n-1) ){
        printf("-1\n");
        return 0;
    }
    printf("%d\n",atoi(ans));  
    return 0;
}


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

int main(){
    int m, f, r;
    char g;
    while(1){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        if (m == -1 || f == -1) {g = 'F';}
        else if (m + f >= 80) {g = 'A';}
        else if (m + f < 80 && m + f >= 65) {g = 'B';}
        else if (m + f < 65 && m + f >= 50) {g = 'C';}
        else if (m + f < 50 && m + f >= 30) {
            g = (r >=50)? 'C':'D';
        }
        else if (m + f < 30) g = 'F';
        cout << g << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
# coding: utf-8

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]

N = int(input())

va, vb = 1, 1
for i in range(N):
    pa, pb = [int(x) for x in input().split(" ")]
    r = int(max((va + pa - 1) // pa, (vb + pb - 1) // pb))
    va = pa * r
    vb = pb * r
print(va + vb)


Measured memory_bytes: 5204
s=int(input())
m=[0]*100000
m[s]+=1

mm=0
while 1:
  mm+=1
  if s%2==0:
    s=s//2
    m[s]+=1
  else:
    s=s*3+1
    m[s]+=1
  #print(s)
  if m[s]==2:
    print(mm+1)
    break

    

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	map <string,int> score;
	int n=read();
	string s;
	rep(i,0,n)
	{
		cin>>s;
		score[s]++;
	}
	int m=read();
	rep(i,0,m)
	{
		cin>>s;
		score[s]--;
	}
	int ans=0;
	Forenska(it,score)
	{
		ans=max(ans,it->se);
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int H, A[500001];
void maxHeapify(int i) {
	int l, r, largest,n;
	l = 2 * i;
	r = 2 * i + 1;
	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= H && A[r] > A[largest]) largest = r;
	if (largest != i) {
		n = A[i];
		A[i] = A[largest];
		A[largest] = n;
		maxHeapify(largest);
	}
}

int main() {
	int i;
	scanf("%d", &H);
	for (i = 1; i <= H; i++) scanf("%d", &A[i]);
	for (i = H / 2; i >= 1; i--) maxHeapify(i);
	for (i = 1; i <= H; i++) printf(" %d", A[i]);
	printf("\n");
}


Measured memory_bytes: 3684
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
const int INF = 1e9 + 7;
int n, m, ans = 0;
vvi v;
vi p;
vi cur;
void rec(int ind){
    if(ind == n+1){
        bool all=true;
        for(int i = 1; i <= m; i++){
            int cnt = 0;
            for(int j = 0; j < v[i].size(); j++){
                if(cur[v[i][j]]) cnt++;
            }
            if(cnt%2!=p[i]) all=false;
        }
        if(all) ans++;
        return;
    }
    cur[ind] = 1;
    rec(ind+1);
    cur[ind] = 0;
    rec(ind+1);
}
int main(){
    cin>>n>>m;
    v = vvi(m+1,vi());
    p = vi(m+1);
    cur = vi(n+1);
    for(int i = 1; i <= m; i++){
        int k; cin>>k;
        for(int j = 0; j < k; j++){
            int t; cin>>t;
            v[i].pb(t);
        }
    }
    for(int i = 1; i <= m; i++) cin>>p[i];
    rec(1);
    cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
//
//class UnionFind {
//private:
//    int sz;
//    vector<int> par, size_;
//public:
//    UnionFind(){}
//    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
//        iota(par.begin(), par.end(), 0);
//    }
//    int find(int x){
//        if(par[x] == x) return x;
//        else return par[x] = find(par[x]);
//    }
//    void unite(int x, int y){
//        x = find(x); y = find(y);
//        if(x == y) return;
//        if(size_[x] < size_[y]) swap(x,y);
//        par[y] = x;
//        size_[x] += size_[y];
//    }
//    int size(int x){
//        x = find(x);
//        return size_[x];
//    }
//    bool same(int x, int y){
//        return find(x) == find(y);
//    }
//};
//void no(){
//    cout << "Impossible" << endl;
//    exit(0);
//}
//int main(){
//    cin.tie(nullptr);
//    ios::sync_with_stdio(false);
//    int n, m;
//    cin >> n >> m;
//    vector<vector<int>> g(n);
//    vector<int>a(n);
//    rep(i,n)cin >> a[i];
//    rep(i,m){
//        int x, y;
//        cin >> x >> y;
//        x--;y--;
//        g[x].push_back(y);
//        g[y].push_back(x);
//    }
//    if(m == n - 1){
//        cout << 0 << endl;
//        return 0;
//    }
//    if(n / 2 < n - m - 1){
//        no();
//    }
//}
int main(){
    string s;
    cin >> s;
    rep(i,s.size())if(s[i] == '?')s[i] = 'D';
    cout << s << endl;
}


Measured memory_bytes: 3736
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

void solve()
{
	string str;
	int data[100][100] = {0};
	int count1 = 0;
	int count2 = 0;
	while(getline(cin, str))
	{
		str += ',';
		int n = str.size();
		string temp;
		int size = 0;
		for(int i = 0; i < n; ++i)
		{
			if(str[i] == ',')
			{
				char* c = new char[size];
				for(int j = 0; j < size; ++j)
				{
					c[j] = temp[j];
				}
				data[count1][count2] = atoi(c);
				delete c;
				++count2;
				size = 0;
				temp.clear();
			}
			else
			{
				temp += str[i];
				++size;
			}
		}
		++count1;
		count2 = 0;
		str.clear();
	}
	int Ans[100][100] = {0};
	Ans[0][0] = data[0][0];
	for(int i = 1; i < (count1 + 1) / 2; ++i)
	{
		for(int j = 0; j < i; ++j)
		{
			Ans[i][j]     = max(data[i][j] + Ans[i - 1][j], Ans[i][j]);
			Ans[i][j + 1] = max(data[i][j + 1] + Ans[i - 1][j], Ans[i][j + 1]);
		}
	}
	for(int i = (count1 + 1) / 2; i < count1; ++i)
	{
		for(int j = 0; j < count1 - i; ++j)
		{
			Ans[i][j] = max(data[i][j] + Ans[i - 1][j], data[i][j] + Ans[i - 1][j + 1]);
		}
	}
	cout << Ans[count1 - 1][0] << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int Maxn=55;
int a[Maxn],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
		if(a[i]>a[i+1]) goto B;
	printf("YES");
	return 0;
	B:;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			swap(a[i],a[j]);
			for(int k=1;k<n;k++)
				if(a[k]>a[k+1]) goto A;
			printf("YES");
			return 0;
			A:swap(a[i],a[j]);
		}
	printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

struct graph{
private:
	int n;
	vector<vector<int>> G, rG;
	vector<bool> used;
	vector<int> vs;

	int mk;
	vector<vector<int>> fG;
	vector <vector<int>> ori;
	vector<int> trans;

	vector<ll> cost;
	vector<ll> memo;

public:
	graph(int sz) {
		n = sz;
		G.resize(n);
		rG.resize(n);
		used.resize(n);

		fG.resize(n);
		trans.resize(n, -1);
		ori.resize(n);
	}
	void add_edge(int a, int b) {
		G[a].push_back(b);
		rG[b].push_back(a);
	}
	void dfs(int v) {
		used[v] = true;
		rep(i, G[v].size()) {
			if (!used[G[v][i]])dfs(G[v][i]);
		}
		vs.push_back(v);
	}
	void rdfs(int v, int k) {
		used[v] = true;
		queue<int> q; q.push(v);
		vector<int> c;
		while (!q.empty()) {
			int id = q.front(); q.pop();
			ori[k].push_back(id);
			rep(j, rG[id].size()) {
				int to = rG[id][j];
				if (used[to]) {
					if (trans[to] >= 0)c.push_back(trans[to]);
					continue;
				}
				used[to] = true;
				q.push(to);
			}
		}
		sort(c.begin(), c.end());
		int len = unique(c.begin(), c.end()) - c.begin();
		rep(i, len) {
			fG[c[i]].push_back(k);
		}
		rep(i, ori[k].size()) {
			trans[ori[k][i]] = k;
		}
	}
	void scc() {
		fill(used.begin(), used.end(), false);
		rep(i, n) {
			if (!used[i])dfs(i);
		}
		fill(used.begin(), used.end(), false);
		int k = 0;
		per(i, (int)vs.size()) {
			if (!used[vs[i]]) {
				rdfs(vs[i], k); k++;
			}
		}
		mk = k;
	}
	void give_val(vector<ll> &v) {
		cost.resize(mk);
		rep(i, v.size()) {
			cost[trans[i]] += v[i];
		}
	}
	ll qdfs(int id) {
		if (used[id])return memo[id];
		used[id] = true;
		ll ret = 0;
		rep(j, fG[id].size()) {
			int to = fG[id][j];
			ll nex = qdfs(to);
			ret = max(ret, nex);
		}
		return memo[id]=ret + cost[id];
	}
	ll query() {
		fill(used.begin(), used.end(),false);
		memo.resize(mk);
		int sta = trans[0];
		return qdfs(sta);
	}
};
void solve() {
	int n, m;
	cin >> n >> m;
	vector<ll> c(n);
	rep(i, n)cin >> c[i];
	graph g(2*n);
	rep(i, m) {
		int a, b; cin >> a >> b;
		g.add_edge(a, b + n);
		g.add_edge(a + n, b);
	}
	g.scc(); g.give_val(c);
	ll ans = g.query();
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 55592
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;
typedef long long ll;

int N;
int h[100005];

int abs(int i){
    if(i>=0) return i;
    return -i;
}

int min(int x,int y){
    if(x>=y) return y;
    return x;
}

int memo[100005];

int dp(int i){
    if(memo[i]!=-1) return memo[i];
    if(i==0){
        memo[0]=0;
        return 0;
    }
    if(i==1){
        memo[1]=abs(h[0]-h[1]);
        return abs(h[0]-h[1]);
    }
    memo[i]=min(dp(i-2)+abs(h[i-2]-h[i]),dp(i-1)+abs(h[i-1]-h[i]));
    return min(dp(i-2)+abs(h[i-2]-h[i]),dp(i-1)+abs(h[i-1]-h[i]));
}

int main(){
    for(int j=0;j<=100004;j++){
        memo[j]=-1;
    }
    int i;
    cin>>N;
    
    for(i=0;i<N;i++){
        cin>>h[i];
    }
    cout<<dp(N-1)<<endl;
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int N;
    scanf("%lld",&N);
    vector<int>A(N);
    rep(i,N)scanf("%lld",&A[i]);
    vint B=A;
    sort(all(B));
    B.erase(unique(all(B)),B.end());
    rep(i,N)A[i]=lower_bound(all(B),A[i])-B.begin();

    int cnt=0;
    rep(i,N){
        if(i%2)continue;
        if(A[i]%2)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using Graph = vector<vector<int>>;
using P = pair<int, int>;



int main() {
    int n,x; cin >> n >> x;
    vector<int> m(n);
    rep(i, n) cin >> m[i];

    sort(m.begin(), m.end());
    int ans = n;
    rep(i, n) {
        x -= m[i];
    }

    int i = 0;
    while(x > 0 && i < n) {
        if(x >= m[i]) {
            x -= m[i];
            ans++;
        } else i++;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::HashSet;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    mut n: u128
    }

    let mut tmp = 26;
    let mut l = 1;
    while n > tmp {
        n -= tmp;
        tmp *= 26;
        l += 1;
    }
    n -= 1;

    let mut vec = vec![];

    for _ in 0..l {
      let amari = n % 26;
      n = n / 26;
      vec.push((amari as u8 + b'a') as char);
    }

     println!("{}", vec.iter().rev().collect::<String>());
}


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

int main() {
	int k,a,b;
    cin >> k;
    cin >> a >> b;
    string s = "NG";
    for(int i=a;i<=b;i++){
    	if(i%k==0){
          s = "OK";
          break;
        }
    }
    cout << s << endl;
}


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

int main() {
  int N;
  cin >> N;
  map<string, int> dict;
  int max_cnt = 0;
  for (int i = 0; i < N; ++i) {
    string si;
    cin >> si;
    auto itr = dict.find(si);
    if (itr != dict.end()) {
      ++dict[si];
    } else {
      dict[si] = 0;
    }
    max_cnt = max(max_cnt, dict[si]);
  }
  vector<string> v;
  for(auto itr = dict.begin(); itr != dict.end(); ++itr) {
    if (itr->second == max_cnt) {
      v.push_back(itr->first);
    }
  }
  sort(v.begin(), v.end());
  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    cout << *itr << endl;
  }
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b,c; cin>>a>>b>>c;
	cout<<a+b+c-max(max(a,b),c)<<"\n";
	return 0;
}















Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 4000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;

const int maxn = 1e6+5;
struct Edge {
    int to,next,w;
    bool operator < (const Edge& rhs)const{
        return w>rhs.w;
    }
} e[maxn<<1];
int cnt, head[maxn];
void add(int u, int v, int w) {
    e[cnt] = Edge{v, head[u], w};
    head[u] = cnt++;
}
bool vis[maxn];
int dis[maxn];
void SPFA(int st, int ed) {
    priority_queue<Edge> q;
    memset(dis,INF,sizeof(dis));
    memset(vis,false,sizeof(vis));
    dis[st] = 0;
    q.push(Edge{st, 0, 0});
    while (!q.empty()) {
        Edge u = q.top();
        q.pop();
        if(vis[u.to]) continue;
        vis[u.to] = 1;

        for (int i = head[u.to]; ~i; i = e[i].next) {
            int to = e[i].to;
            if (dis[to] > dis[u.to] + e[i].w) {
                dis[to] = dis[u.to] + e[i].w;
                q.push(Edge{to, 0, dis[to]});
            }
        }
    }
    printf("%d\n", dis[ed] == INF?-1:dis[ed]/2);
}
map<int, int>mp[maxn];
int allPoint;
int getPoint(int x,int y) {
    if (!mp[x][y])
        mp[x][y]=++allPoint;
    return mp[x][y];
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    allPoint=n;
    for (int i=1; i<=m; i++) {
        int x,y,w;
        scanf("%d%d%d",&x,&y,&w);
        int newX=getPoint(x,w);
        int newY=getPoint(y,w);

        add(newX,newY,0);
        add(newY,newX,0);
        add(x,newX,1);
        add(newX,x,1);
        add(y,newY,1);
        add(newY,y,1);
    }
    SPFA(1,n);

    return 0;
}


Measured memory_bytes: 93044