akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}



const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int now = 1;
	int ans = 0;
	rep(i, n) {
		if (a[i] == now) {
			now++; ans++;
		}
	}
	if (ans == 0)cout << -1 << endl;
	else cout << n-ans << endl;
	return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define mod (ll)1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, 0, n) {
    int a;
    cin >> a;
    mp[a] = 1;
  }
  int ans = 0;
  rep(i, 0, 101) {
    if(mp[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php
    fscanf(STDIN, "%d %d", $a, $b);
    $aButton = $a + ($a - 1);
    $bButton = $b + ($b -1);
    $abButton = $a + $b;
    if($aButton > $bButton){
        if($aButton > $abButton){
            echo $aButton;
        }else{
            echo $abButton;
        }
    }else{
        if($bButton > $abButton){
            echo $bButton;
        }else{
            echo $abButton;
        }

    }
?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    string s;
    int cnt = 0, ans = 0;
    cin >> s;
    REP(i, s.size()){
        if (s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T'){
            cnt += 1;
            ans = max(ans, cnt);
        }
        else cnt = 0;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;
class Main{


	static char[][] map;

	static long[][] c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		long ans = 0;
		long mod = 1000_000_007;

		c = new long[n + 2][n + 2];
		c[0][0] = 1;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= i; j++) {
				c[i + 1][j] = (c[i + 1][j] + c[i][j]) % mod;
				c[i + 1][j + 1] = (c[i + 1][j + 1] + c[i][j]) % mod;
			}
		}
		for(int i = 1;i <= k;i++){
			System.out.println((c[n-k+1][i] * c[k-1][i-1])%mod );
		}

		
	}


	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   end- otherpair.end;
	}







	static int find(int index,int current,int[] students,int ans,int[][] memo){
		if(current == index){
			return 1;
		}

		if(memo[current][index] != 0){
			return memo[current][index];
		}

		memo[current][index] = find(index, students[current]-1, students, ans+1, memo)+1;

		return memo[current][index];
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}






Measured memory_bytes: 80980
#include <stdio.h>  
#include <string.h>  
#include<math.h>
int main()
{
	long long int i,num,n,m,s;
    	while(~scanf("%lld %lld",&n,&m))
	  {
	  	if(m==0&&n==0)
	  	break;
	  	else
	  	{
		  s=0;num=0;
		  if(m>n)
	  	{
		  s=m-n*2;
	  	num=n+s/4;
	  }
	  else if(n>=m)
	  {
	  	if(m<2)
	  	num=0;
	  	else
	  	{
	  		num=m/2;
		  }
	  }
	
	  	printf("%lld\n",num);
	  }
	}
		
}

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

int main() {
  int a[5];
  for (int i=0; i<5; i++) {
    cin >> a[i];
  }
  sort(a, a+5, greater<int>());
  for (int i=0; i<4; i++) {
    cout << a[i] << " ";
  }
  cout << a[4] << endl;
  return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int l=s.length();
    int ans=0;
    for(int i=0;i<=l;i++){
      string t=s;
      int p=0;
      for(int j=0;j<l;j++){
	int x=n-1+(i==j);
	(p+=x)%=(int)t.size();
	t.erase(t.begin()+p);
	//cout<<p<<endl;
	//p++;
	p%=(int)t.size();
	int g=0,b=0;
	for(int k=0;k<(int)t.size();k++){
	  g+=t[k]=='G';
	  b+=t[k]=='B';
	}
	//cout<<s<<" "<<t<<endl;
	if(g*b) continue;
	ans=max(ans,b);
	break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#define ll long long
using namespace std;
int main () {
	int q,p = 0,n; cin >> q; ll ans = 0;
	while (q--){
		cin >> n;
		if (n<p) ans += p-n;
		else p=n;
	} cout << ans << "\n";
	return 0;
}

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


int MOD=1000000007;

int main(void){
    int K,X;
    cin >> K >> X;
    for(int i=X+1-K; i<=X-1+K; i++){
        cout << i  << ' ' ;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e3+10;
const int mod=1e9+7;
int siz[maxn],n;
int g[maxn],dp[maxn][maxn],tmp[maxn];
struct edge{int v,nxt;}e[maxn<<1];
int head[maxn],ecnt=0;
void add(int u,int v)
{
	e[++ecnt]=(edge){v,head[u]},head[u]=ecnt;
	e[++ecnt]=(edge){u,head[v]},head[v]=ecnt;
}
void dfs(int u,int pre)
{
	siz[u]=1,dp[u][1]=1;
	for(int t=head[u];~t;t=e[t].nxt)
	{
		int v=e[t].v;
		if(v==pre)continue;
		dfs(v,u);
		for(int i=0;i<=siz[u]+siz[v];i++)tmp[i]=0;
		for(int i=0;i<=siz[u];i++)
		for(int j=0;j<=siz[v];j++)tmp[i+j]=(tmp[i+j]+dp[u][i]*1LL*dp[v][j])%mod;
		siz[u]+=siz[v];
		for(int i=0;i<=siz[u];i++)dp[u][i]=tmp[i];
	}
	for(int i=2;i<=siz[u];i+=2)dp[u][0]=(dp[u][0]+mod-dp[u][i]*1LL*g[i]%mod)%mod;
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2)g[i]=g[i-2]*1LL*(i-1)%mod;
	dfs(1,0);
	printf("%d\n",mod-dp[1][0]);
}

Measured memory_bytes: 97280
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;

class uft{
public:
  int par[1000];//親
  int rank[1000];//木の深さ
  int size[1000];//木の大きさ
  uft(int N);//コンストラクタ
  int find(int x);
  void unite(int x,int y);
  bool same(int x,int y);
  int usize(int x);
};
uft::uft(int N){//コンストラクタ
  for(int i=0;i<N;i++){
    par[i]=i;
    rank[i]=0;
    size[i]=1;
  }
}
int uft::find(int x){//xの根を返す
  if(par[x]==x) return x;//根の親は自分自身
  else return par[x]=find(par[x]);//再起で親を辿る
}
void uft::unite(int x,int y){//x,yを併合
  x=find(x);
  y=find(y);
  if(x==y) return ;//根が同じなら併合する必要なし

  if(rank[x]<rank[y]){//木の深い方に浅い方をつける
    par[x]=y;
    size[y]+=size[x];
  }
  else{
    par[y]=x;
    size[x]+=size[y];
    if(rank[x]==rank[y]) rank[x]++;//同じ深さなら深さを増やす
  }
}
bool uft::same(int x,int y){//x,yが同じグループにいるかどうかを返す
  return find(x)==find(y);//根が同じかどうかを判断する
}
int uft::usize(int x){
  return size[find(x)];
}
int n,m;
int a[55],b[55];
int main(){
  scan(n);scan(m);
  rep(i,m){
    scan(a[i]);scan(b[i]);
  }
  int ans=0;
  rep(i,m){
    uft uf(n);
    rep(j,m){
      if(j!=i){
	uf.unite(a[j]-1,b[j]-1);
      }
    }
    if(!uf.same(a[i]-1,b[i]-1)){
      ans++;
    }
  }
  prin(ans);
    
  
  return 0;
}


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

bool check(int n,vector<int>&ans){
  for(int i=0;i<ans.size();i++)
    if(ans.at(i)==n)
      return false;
  return true;
}
  
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  vector<int>ans;
  for(int i=0;i<k;i++)
    if(a+i<=b)
      ans.push_back(a+i);
  for(int i=0;i<k;i++)
    if(b-i>=a&&check(b-i,ans))
      ans.push_back(b-i);
  sort(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++)
    cout << ans.at(i) << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B, K;
    std::cin >> A >> B >> K;

    std::set<int> ans;
    for (int i = A; i < A+K; i++) {
        ans.insert(i);
        if (i >= B) {
            break;
        }
    }

    for (int i = B; i > B-K; i--) {
        ans.insert(i);
        if (i <= A) {
            break;
        }
    }

    for (auto itr = ans.begin(); itr != ans.end(); itr++) {
        std::cout << *itr << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let b: Vec<i64> = (1..n).map(|_| sc.cin()).collect();
    let mut ans = 0;
    for i in 0..n {
        let a = if i == 0 {
            b[0]
        } else if i == n - 1 {
            b[n - 2]
        } else {
            min!(b[i - 1], b[i])
        };
        ans += a;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int par[160010];
int a[160010]={0};
int b[160010]={0};
int n,m;
char c[410][410];
int d1[4]={0,0,1,-1};
int d2[4]={1,-1,0,0};
inline int pare(int x)
{
	if (par[x]==x) return x;
	else return pare(par[x]);
}
void join(int x,int y)
{
	x=pare(x),y=pare(y);
	if (x==y) return;
	par[x]=y;
	a[y]+=a[x];
	b[y]+=b[x];
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			cin >>c[i][j];
			(c[i][j]=='.' ? a[i*m+j] : b[i*m+j])=1;
			par[i*m+j]=i*m+j;
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
	        int t=i*m+j;
	        for (int k=0;k<4;k++)
	        {
	        	int xi=i+d1[k];
	        	int yi=j+d2[k];
	        	if (xi>=0 && yi>=0 && xi<n && yi<m && c[xi][yi]!=c[i][j])
	        	    join(t,xi*m+yi);
			}
		}
	}
	long long res=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
	        int t=i*m+j;
	        if (par[t]!=t) continue;
	        res+=(long long)a[t]*b[t];
		}
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

int main(void)
{
    int n, h, w, count=0, n1, n2;
    scanf("%d%d%d",&n, &h, &w);

    for(int i=0; i<n; i++){
      scanf("%d%d",&n1, &n2);
      if(h <= n1 && w <= n2){
        count++;
      }
    }
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,h[100000],i,j,cnt,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&h[i]);
	cnt=0; x=0;
	for(i=0;i<n-1;i++){
		if(h[i]>=h[i+1])	cnt++;
		else{
			if(x<cnt)	x=cnt;
			cnt=0;
		}
	}
	if(x<cnt)	x=cnt;
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2128
#include<stdio.h>
int main(){
    int i,t,u,H[100],W[100];
    for(i=0;;i+=1){
        scanf("%d %d",&H[i],&W[i]);
        if(H[i]==0&&W[i]==0){
            break;
        }
        for(t=1;t<=H[i];t+=1){
            for(u=1;u<=W[i];u+=1){
                if(u<W[i]){
                    printf("#");
                }
                else if(u==W[i]){
                    printf("#\n");
                }
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 20;

int a[N], res;
int x[N][N], y[N][N];
bool ok[N], okk[N];

int main()
{
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		for (int j = 0; j < a[i]; j++){
			cin >> x[i][j] >> y[i][j];
		}
	}
	for (int i = 0; i < 1 << n; i++){
		int sum = 0;
		bool tag = true;
		for (int j = 0; j < n; j++){
			ok[j] = (i >> j) & 1;
			if (ok[j])	sum++;
		}
		for (int j = 0; j < n && tag; j++){
			if (ok[j]){
				for (int k = 0; k < a[j] && tag; k++){
					if (y[j][k]){
						if (!ok[x[j][k]-1]) tag = false;
					}
					else{
						if (ok[x[j][k]-1]) tag = false;
					}
				}
			}
		}
		/*
		for (int j = 0; j < n && tag; j++){
			if (ok[j] != okk[j]){
				tag = false;
			}
		}
		*/
		if (tag) res = max(res, sum);
	}
	cout << res;
	return 0;
}

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

using namespace std;

//0-1 Knapsack: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B
void printDP(const int n, const int c, vector<vector<int> >& dp){
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int solve_a(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, 0));
    
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }
        }
    }
    //printDP(n, c, dp);
    return dp[n][c];
}

int solve_b(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, 0));
    
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
            }
        }
    }
    //printDP(n, c, dp);
    return dp[0][c];
}

int solve_c_rec(int i, int j, vector<vector<int>>& dp,
        const vector<int>& v, const vector<int>& w) {
    if (i == 0 || j == 0) {
        return 0;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    int result = solve_c_rec(i - 1, j, dp, v, w);
    if (j >= w[i - 1]) {
        result = max(result, solve_c_rec(i - 1, j - w[i - 1], dp, v, w) + v[i - 1]);
    }
    dp[i][j] = result;
    return result;   
}

int solve_c(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, -1));
    return solve_c_rec(n, c, dp, v, w);
}

int solve_d_rec(int i, int j, vector<vector<int>>& dp, const int n,
        const vector<int>& v, const vector<int>& w) {
    if (i == n || j == 0) {
        return 0;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    int result = solve_d_rec(i + 1, j, dp, n, v, w);
    if (j >= w[i]) {
        result = max(result, solve_d_rec(i + 1, j - w[i], dp, n, v, w) + v[i]);
    }
    dp[i][j] = result;
    return result;   
}

int solve_d(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, -1));
    return solve_d_rec(0, c, dp, n, v, w);
}

int main() {
    int n, c;
    cin >> n >> c;
    vector<int> v(n, 0);
    vector<int> w(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> w[i];
    }
    int ans = solve_d(n, c, v, w);
    cout << ans << endl;
}

Measured memory_bytes: 6740
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Asia2010_B().doIt();
//		new NY2015_C().doIt();
	}
	class Asia2010_B{
		int MAX = Integer.MAX_VALUE / 2;
		void solve(int Move[],int Time[],int n){
			int DP[][][] = new int[n+1][101][4];
			for(int i = 0;i < n+1;i++){
				for(int j = 0;j < 101;j++){
					for(int k = 0;k < 4;k++){
						DP[i][j][k] = MAX;
					}
				}
			}
			for(int i = 0;i < n;i++){
				Move[i] = sc.nextInt();
				Time[i] = sc.nextInt();
			}
			DP[0][0][0] = 0;
			int time = 0;
			for(int i = 0;i < n;i++){
				boolean check = false;
				for(int j = 0;j < 101;j++){
					for(int k = 0;k < 4;k++){
						if(DP[i][j][k] == MAX)continue;
						else{
							int move = Math.abs(j - Move[i]) * (k + 1) + time;
							if(move <= Time[i] && k < 3){
								check = true;
								DP[i+1][Move[i]][k + 1] = Math.min(DP[i+1][Move[i]][k + 1], DP[i][j][k] + Math.abs(j - Move[i]));
//								System.out.print(DP[i+1][Move[i]][k + 1]+" : "+Move[i]+" ");
							}
							move = j * (k + 1) + Move[i] + time;
							if(move <= Time[i]){
								check = true;
								DP[i+1][Move[i]][1] = Math.min(DP[i+1][Move[i]][1], DP[i][j][k] + j + Move[i]);
//								System.out.print(DP[i+1][Move[i]][1]+" : "+Move[i]+" ");
							}
						}
					}
				}
				time = Time[i];
				if(!check){
					System.out.println("NG "+(i+1));
					return;
				}
//				System.out.println("check:"+i);
			}
			int min = MAX;
			for(int i = 0;i < 101;i++){
				for(int j = 0;j < 4;j++){
					if(DP[n][i][j] != MAX)min = Math.min(min, DP[n][i][j] + i);
				}
			}
			System.out.println("OK "+min);
		}
		void doIt(){
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int Move[] = new int[n];
				int Time[] = new int[n];
				solve(Move,Time,n);
			}
		}
	}
	class NY2015_C{
		long MOD = 1000000000;
		long [][] mul(long A[][],long B[][]){
			long C[][] = new long[2][2];
			for(int i = 0;i < 2;i++){
				for(int j = 0;j < 2;j++){
					for(int k = 0;k < 2;k++){
						C[i][k] = (C[i][k] + A[i][j] * B[k][j]) % MOD;
					}
				}
			}
			return C;
		}
		long[][] pow(long A[][],long n){
			long B[][] = new long[2][2];
			B[0][0] = 1;B[1][1] = 1;
			while(n > 0){
				long bool = n & 1;
//				System.out.println(bool);
				if(bool == 1)B = mul(A,B);
				A = mul(A,A);
				n >>= 1;
			}
			return B;
		}
		long solve(long cnt){
			long A[][] = new long [2][2];
			A[0][0] = 1;A[0][1] = 1;
			A[1][0] = 1;A[1][1] = 0;
			A = pow(A, cnt);
			return A[1][0];
		}
		void doIt(){
			int n = sc.nextInt();
			for(int i = 0;i < n;i++){
				int num = sc.nextInt();
				long cnt = sc.nextLong();
				System.out.println(num+" "+solve(cnt));
			}
		}
	}
}

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

#define i64 long long int
#define ran 4044

int n;
char s[ran];
int tot[3][ran];

int trans(char ch) {
	if(ch=='R') return 0;
	if(ch=='G') return 1;
	return 2;
}

int main() {
	scanf("%d%s", &n, s);
	for(int i=n-1;i>=0;i--) {
		for(int j=0;j<3;j++) tot[j][i] = tot[j][i+1];
		
		int id = trans(s[i]);
		tot[id][i] ++;
	}
	
	i64 ans = 0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++) {
			if(s[i]==s[j]) continue;
			
			ans += tot[3-trans(s[i])-trans(s[j])][j+1];
			int k = j*2-i;
			if(k<n && s[k]!=s[i] && s[k]!=s[j])
				ans--;
		}
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 3868
#include <stdio.h>

int main( void ) {
	int q;

	scanf( "%d", &q );

	while ( q-- ) {
		double x0, y0, x1, y1, x2, y2, x3, y3;
		double a, b, c, d, x, y;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3 );

		if ( x0 != x1 ) {
			a = ( y0 - y1 ) / ( x0 - x1 );
			b = ( x0 * y1 - x1 * y0 ) / ( x0 - x1 );
		}

		if ( x2 != x3 ) {
			c = ( y2 - y3 ) / ( x2 - x3 );
			d = ( x2 * y3 - x3 * y2 ) / ( x2 - x3 );
		}

		if ( x0 == x1 ) {
			x = x0;
			if ( x2 == x3 )
				y = y0 == y2 || y0 == y3 ? y0 : y1;
			else
				y = c * x + d;
		} else {
			if ( x2 == x3 )
				x = x2;
			else if ( a == c )
				x = x0 == x2 || x0 == x3 ? x0 : x1;
			else
				x = ( -b + d ) / ( a - c );
			y = a * x + b;
		}

		printf( "%.8f %.8f\n", x, y );
	}

	return 0;
}

Measured memory_bytes: 668
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    public void Slove()
    {
        var array =
            Enumerable.Range(0, 5)
            .Select(x => int.Parse(Console.ReadLine()))
            .ToArray();
        int k = int.Parse(Console.ReadLine());
        bool result = 
            array.Max() - array.Min() <= k;
        Console.WriteLine(result ? "Yay!" : ":(");
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  cout<<A*B*C/2/max({A,B,C})<<endl;
return 0;}

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
using namespace std;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> arr(n);
	for(int& x : arr) {
		scanf("%d", &x);
	}
	vector<bool> dp(k+1);
	for(int stones = 0; stones <= k; ++stones) {
		for(int x : arr) {
			if(stones >= x && !dp[stones - x]) {
				dp[stones] = true;
			}
		}
	}
	puts(dp[k] ? "First" : "Second");
	return 0;
}


Measured memory_bytes: 3684
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	patters := make([]string, 0)
	for i := 0; i <= len(s)-len(t); i++ {
		ss := s[0:i] + t + s[i+len(t):]
		patters = append(patters, ss)
	}

	matches := make([]string, 0)
	for _, ss := range patters {
		ok := true
		for i, c := range s {
			if c != '?' && string(c) != string(ss[i]) {
				ok = false
				break
			}
		}
		if ok {
			matches = append(matches, ss)
		}
	}

	if len(matches) == 0 {
		fmt.Println("UNRESTORABLE")
		return
	}

	sort.Strings(matches)
	for _, c := range matches[0] {
		if c == '?' {
			fmt.Print("a")
		} else {
			fmt.Print(string(c))
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 512
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi Pv(n);
  VIN(Pv)
  int minE = INF;

  // REP(i,n){
  //   REP(j,i){
  //     if(Pv[i] > Pv[j]) Bv[i] = false;
  //   }
  // }

  // REP(i,n){
  //   if(Bv[i]) c++;
  // }

  REP(i,n){
    if(minE >= Pv[i]){
      c++;
    }
    minE = min(minE, Pv[i]);
  }

  OUT(c);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;


ll divisibleCount(ll n, ll d){
    ll ans = 0;
    while(n % d == 0){
        ans++; 
        n /= d;
    }  
    return ans;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), c(n);
    vector<pair<ll, ll>> b(n);
    rep(i, n){
        string s;
        cin >> s;
        if(s.find('.') == string::npos)s += "000000000";
        else{
            int f = s.find('.');
            s.erase(s.find('.'), 1);
            while(s.size()-f < 9)s += "0";
        }
        a[i] = stoll(s);
        b[i] = {divisibleCount(a[i], 2), divisibleCount(a[i], 5)};
        c[i] = b[i].first;
    }
    sort(all(b));
    sort(all(c));
    vector<vector<ll>> sum(n, vector<ll>(19, 0LL));
    for(int i = n-1; i >= 0; i--){
        for(int j = min(18LL, b[i].second); j >= 0; j--){
            sum[i][j] += 1;
        }
        if(i!=n-1)rep(j, 19)sum[i][j] += sum[i+1][j];
    }
    ll ans = 0;
    rep(i, n){
        int it = c.end() - lower_bound(all(c), 18LL-b[i].first);
        //cout << b[i].first << " " << b[i].second << endl;
        //cout << "it -> " << max((ll)i, n-it) << endl;
        int now = max((ll)i+1, n-it);
        if(now < n){
            ans += sum[now][max(0LL, 18-b[i].second)];
        }
    }

    /*rep(i, 19){
        rep(j, n)cout << sum[j][i] << " ";
        cout << endl;
    }*/

    cout << ans << endl;
}

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

int a[673] = {0}; //2019/3 = 673

int main(void)
{
    int l, r;
    cin >> l >> r;
    
    int min = 2018;
    if (l + 673 <= r){
        min = 0;
        cout << min << endl; 
        return 0;  
    }
    
    for (size_t i = l; i <= r; i++)
    {
       a[i-l] = i % 2019;
    }

    min = 2018;
    for (size_t i = l; i < r; i++)
    {
       for (size_t j = i + 1; j <= r; j++)
       {
            int temp = a[i-l] * a[j-l];
            while(temp >= 2019)
            {
                temp -= 2019;
            }
            
            if(temp < min){
                min = temp;
            }
       }

    }
    cout << min << endl; 
    return 0;   
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n;LL a[55];
int main()
{
	get1(n);for(int i=1;i<=n;i++)get1(a[i]);
	int mx=1;for(int i=1;i<=n;i++)if(abs(a[i])>abs(a[mx]))mx=i;
	printf("%d\n",n+n-2);
	for(int i=1;i<=n;i++)if(mx!=i)printf("%d %d\n",mx,i);
	if(a[mx]>0)for(int i=1;i<n;i++)printf("%d %d\n",i,i+1);
	else for(int i=n;i>1;i--)printf("%d %d\n",i,i-1);
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  var list = List.fill(n)(sc.nextInt)

  var aliceSum = 0
  var bobSum = 0
//  list.sorted.reverse.zipWithIndex.foreach{
//    v =>
//      if(v._2 % 2 == 0) aliceSum += v._1
//      else bobSum += v._1
//  }
  var index = 0
  list.sortWith((x, y) => x > y).foreach {
    v =>
      if (index % 2 == 0) {
        aliceSum += v
      } else {
        bobSum += v
      }
      index += 1
  }

  println(aliceSum - bobSum)
}

Measured memory_bytes: 25632
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String s = sc.next();
    int b = sc.nextInt();
    if(s.equals("+")){
      System.out.println(a+b);
    }
    else
      System.out.println(a-b);
  }
}


Measured memory_bytes: 23252
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <array>
#include <complex>

#define endl '\n'

using namespace std;

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

    int n;
    cin >> n;

    vector<long long> v(n);

    long long answer = 1;

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

        if (v[i] == 0)
            answer = 0;
    }

    if (answer == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        for (auto u : v)
        {
            if (answer <= 1000000000000000000 / u)
            {
                answer *= u;
            }
            else
            {
                cout << -1 << endl;
                return 0;
            }
        }

        cout << answer << endl;
    }

    return 0;
}


Measured memory_bytes: 3620
// ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES";
	}else { 
		cout << "NO";
	}
}

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

using namespace std;
using uint = unsigned int;
using int64 = long long;
using i64 = int64;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
template<typename T>
using p_que = priority_queue<T>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

template<typename T>
vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

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

template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << e << " ";
	return os << "}";
}

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Cut from here! */

//#define int long long

void Main() {
	int f; cin >> f;
	cout << (f - 30) / 2 << endl;
}


Measured memory_bytes: 3196
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import queue
import copy

INF = float("inf")

def getlist():
	return list(map(int, input().split()))

def Bellman_Ford(N, E, G, dist):
	for i in range(N):
		for a, b, w in G:
			if dist[b] > dist[a] + w:
				dist[b] = dist[a] + w

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = queue.Queue()
		self.Q.put(s)
		self.dist = [INF] * N
		self.dist[s] = 0
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.Q.put(i)
					self.visit[i] = "Yes"

#処理内容
def main():
	N, M, P = getlist()
	dist = [INF] * N
	dist[0] = 0
	G = []
	D = Graph()
	Drev = Graph()
	for i in range(M):
		a, b, w = getlist()
		G.append([a - 1, b - 1, P - w])
		D.add_edge(a - 1, b - 1)
		Drev.add_edge(b - 1, a - 1)
	
	#BFS 0→N-1の経路判定
	BF = BFS(D, 0, N)
	BFrev = BFS(Drev, N - 1, N)
	check1 = BF.visit
	check2 = BFrev.visit
	judge = ["No"] * N
	for i in range(N):
		if check1[i] == "Yes" and check2[i] == "Yes":
			judge[i] = "Yes"

	#NM回、2NM回処理
	Bellman_Ford(N, M, G, dist)
	d1 = copy.copy(dist)
	Bellman_Ford(N, M, G, dist)
	d2 = dist

	#判定、出力

	judge_ans = "No"
	for i in range(N):
		if judge[i] == "Yes" and d1[i] != d2[i]:
			judge_ans = "Yes"
			break
	if judge_ans == "Yes":
		print(-1)
	else:
		print(max(-dist[-1] , 0))

if __name__ == '__main__':
	main()

Measured memory_bytes: 62036
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    g = [[] for _ in range(n)]

    for i in range(m):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        g[a].append(b)
        g[b].append(a)

    res = [1] * n

    for x in range(n):
        for y in g[x]:
            if h[y] < h[x]:
                continue
            else:
                res[x] = 0
                break
    print(sum(res))
if __name__ == '__main__':
    main()


Measured memory_bytes: 30212
#include <iostream>
#include <map>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
struct RollingHash {
    typedef long long int_type;
    typedef pair<int_type, int_type> hash_type;

    int_type base1, base2;
    int_type mod1, mod2;
    vector<int_type> hash1, hash2;
    vector<int_type> pow1, pow2;
    RollingHash() : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) {}

    void init(vector<int> s) {
        int n=s.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        pow1.assign(n+1, 1);
        pow2.assign(n+1, 1);

        rep(i,n) {
            hash1[i+1] = (hash1[i]+s[i]) * base1 % mod1;
            hash2[i+1] = (hash2[i]+s[i]) * base2 % mod2;
            pow1[i+1] = pow1[i] * base1 % mod1;
            pow2[i+1] = pow2[i] * base2 % mod2;
        }
    }

    hash_type get(int l,int r) {
        auto t1 = ((hash1[r]-hash1[l]*pow1[r-l])%mod1+mod1)%mod1;
        auto t2 = ((hash2[r]-hash2[l]*pow2[r-l])%mod2+mod2)%mod2;
        return make_pair(t1, t2);
    }
};

int N;
vector<int> S;
RollingHash rh;
void dump (int l,int r) {
    for(int i=l;i<r;i++) cout<<S[i]<<" ";
    cout<<endl;
}
bool ok(int t) {
    bool ret=true;
    for(int i=t;i<N;i+=t) {
        ret &= rh.get(0,t) == rh.get(i,i+t);
    }

    return ret;
}
int main() {
    cin>>N;
    S.resize(N);
    rep(i,N) cin>>S[i];
    rh.init(S);
    int ans=1;
    rep(t,N+1) if(t&&N%t==0) {
        if(ok(t)) ans=max(ans,N/t);
    }
    cout<<ans<<endl;
    return 0;
}

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

int MOD = 998244353;
using mint = modint998244353;

vector<mint> repunit;
vector<mint> ten;

tuple<mint, int, int> op(tuple<mint, int, int> a, tuple<mint, int, int> b){
    if(get<1>(a) == -1) return b;
    if(get<1>(b) == -1) return a;
    if(get<1>(b) < get<1>(a)){
        swap(a, b);
    }
    tuple<mint, int, int> p = make_tuple(get<0>(b)*ten[get<1>(b) - get<1>(a)] + get<0>(a), get<1>(a), get<2>(a) + get<2>(b));
    return p;
}

tuple<mint, int, int> e(){
    return make_tuple(mint(0), -1, 0);
}

tuple<mint, int, int> mapping(int f, tuple<mint, int, int> x){
    if(f == -1) return x;
    mint num = repunit[get<2>(x)-1] * f;
    tuple<mint, int, int> p = make_tuple(num, get<1>(x), get<2>(x));
    return p;
}

int composition(int f, int g){
    if(f == -1) return g;
    return f;
}

int id(){
    return -1; // ?
}


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

    int n, q;
    cin >> n >> q;
    vector<tuple<mint, int, int>> s(n);
    for(int i=0; i<n; i++){
        s[i] = make_tuple(mint(1), n-i-1, 1);
    }

    vector<mint> v(n), w(n);
    v[0] = 1;
    w[0] = 1;
    for(int i=1; i<n; i++){
        v[i] = v[i-1] * 10 + 1;
        w[i] = w[i-1] * 10;
    }

    repunit = v;
    ten = w;

    lazy_segtree<tuple<mint, int, int>, op, e, int, mapping, composition, id> lsg(s);


    for(int i=0; i<q; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        lsg.apply(l, r+1, d);
        tuple<mint, int, int> p = lsg.all_prod();
        cout << get<0>(p).val() << endl;
    }
        
    return 0;
}

Measured memory_bytes: 15964
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int hen(vector<ll> p){
    int ans = 1;
    ll mi = p[1];
    rep(i,2){
        if (mi > p[i+2]){
            mi = p[i+2];
            ans = i+2;
        }
    }
    return ans;
}

int main() {
    int n, k; cin >> n >> k;
    vector<ll> ar(n);
    rep(i,n) cin >> ar[i];
    sort(ar.begin(),ar.end());
    ll ans = inf;
    rep(i,n-k+1){
        ans = min(ans,ar[i+k-1]-ar[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4032
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

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

const int mod=1e9+7;
int n,cnt;
vector<int> ans;
int pow6[7]={1,6,36,216,1296,7776,46656};
int pow9[6]={1,9,81,729,6561,59049};
void dfs(int n,int cnt){
    int dMin=INT_MAX,p=0;
    if(n==0){
        ans.push_back(cnt);
        return;
    }
    for(int i=0;i<7;i++){
        if(n-pow6[i]>=0&&n-pow6[i]<dMin){
            dMin=n-pow6[i];
            p=i;
        }
    }
    dfs(n-pow6[p],cnt+1);
    dMin=INT_MAX;
    p=0;
    for(int i=0;i<6;i++){
        if(n-pow9[i]>=0&&n-pow9[i]<dMin){
            dMin=n-pow9[i];
            p=i;
        }
    }
    dfs(n-pow9[p],cnt+1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cnt=0;
    dfs(n,cnt);
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 132188
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll a = in(), b = in(), c = in();
	ll mx = max({ a,b,c });
	cout << (
		a == mx ? b * c / 2
		: b == mx ? c * a / 2
		: a * b / 2
		) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BC114
{
    class Program
    {
        static void Main(string[] args)
        {
            var obj = new Q1();
            obj.Solver();

        }
    }
    class Q1
    {

        public void Solver()
        {
            long amswer = 753;
            var s = Console.ReadLine().Select(x => long.Parse(x.ToString())).ToArray();
            long diff = 1000;

            for (int i = 0; i < s.Count() - 2; i++)
            {
                long temp = s[i] * 100 + s[i + 1] * 10 + s[i + 2];
                diff = Math.Min(diff, Math.Abs(amswer - temp));
            }

            Console.WriteLine(diff);

        }
    }

    //class Q1
    //{
    //    public void Solver()
    //    {
    //        var age = int.Parse(Console.ReadLine());

    //        Console.WriteLine((age == 3 || age == 5 || age == 7) ? "YES" : "NO");

    //    }
    //}
}


Measured memory_bytes: 13396