akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

//  ????????????????????????
std::string Replace(std::string String1, std::string String2, std::string String3)
{
	std::string::size_type  Pos(String1.find(String2));

	while (Pos != std::string::npos)
	{
		String1.replace(Pos, String2.length(), String3);
		Pos = String1.find(String2, Pos + String3.length());
	}

	return String1;
}

int main() {
	int N; cin >> N;
	string st;
	getline(cin, st);
	while (N--) {
		getline(cin, st);
		st = Replace(st, "Hoshino", "Hoshina");
		cout << st << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
int main(){
    int n;cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    bool flag=true;
    for(int i=n-1;i>0;i--){
        if(v[i]>=v[i-1])continue;
        else v[i-1]--;
        if(v[i]<v[i-1]){
            flag=false;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a,int b)
{
	if(b==0)
	return a;
	
	return gcd(b,a%b);
}
int power(int x,int y,int p)
{
	int res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
		res=(res*x)%p;
		
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
int modInverse(int n,int p)
{
	return power(n,p-2,p);
}
int main() {
	// your code goes here
	 ios_base::sync_with_stdio(0);
	 cin.tie(0);
	 int n;
	 cin>>n;
	 vector<int> v(n);
	 for(int i=0;i<n;i++)
	 {
		 cin>>v[i];
	 }
	 sort(v.begin(),v.end());
	 int max=v[n-1];
	 int ans=0;
	 vector<bool> visited(max+5,true);
	 for(int i=0;i<n;i++)
	 {
		 if(i!=0 && v[i]==v[i-1])
		 visited[v[i]]=false;
		 
		 for(int j=v[i]*2;j<=max;j+=v[i])
		 visited[j]=false;
		 
	 }
	 for(int i=0;i<n;i++)
	 {
		 if(visited[v[i]])
		 ans++;
	}
	 cout<<ans<<'\n';
	 return 0;
}


Measured memory_bytes: 4348
#include<stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if(a+b==c+d){
    printf("Balanced\n");
  }else if(a+b>c+d){
    printf("Left\n");
  }else{
    printf("Right\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main(){
    int H , A , Ans;
    scanf( "%d%d" , &H , &A );

    if( H % A == 0 ) Ans = H / A;
    else Ans = ( H / A ) + 1;
    printf( "%d\n" , Ans );
    return 0;
}

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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    int rx = ( r + x ), ry = ( r + y );
    if(W >= rx && H >= ry && rx > 0 && ry > 0) 
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int main() {
 int a,b; cin >> a >> b;
   if(b==1)cout << 0 << endl;
   else{
   for(int i=0;i<50;i++){
     if(i*(a-1)+a>=b){
       cout << i+1 << endl;
       break;
     }
   }
 }

}


Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        a: [usize;n],
    }

    let mut max_height = 0;
    let mut sum = 0;
    for i in 0..n {
        if a[i] < max_height {
            sum += max_height - a[i];
        }
        max_height = max(max_height, a[i]);
    }

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


Measured memory_bytes: 5564
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()

    if N % 2 == 0:
        first = S[:N // 2]
        second = S[N // 2:]
        if first == second:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61924
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) { a += b, a %= MOD; }

int main() {
  // Input
  int N;
  std::cin >> N;
  assert(1 <= N and N <= 20);
  std::vector<int> H(1 + N);
  for (int i = 1; i <= N; ++i) {
    std::cin >> H[i];
    assert(1 <= H[i] and H[i] <= 100);
  }

  // Main
  int currentMax = -1;
  int res = 0;
  for (int i = 1; i <= N; ++i) {
    if (currentMax <= H[i])
      res += 1;
    chmax(currentMax, H[i]);
  }

  // Output
  std::cout << res << std::endl;

  return 0;
}


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

int A, B, C, K;

int main(){
  cin >> A >> B >> C >> K;
  if (K <= A) cout << K << endl;
  else if (K - A <= B) cout << A << endl;
  // K <= A + B + C なので残りのケースではCからK-A-B枚選ぶことになる
  else cout << A - (K - A - B) << endl;
}

Measured memory_bytes: 3604
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	char[] S;

	public void solve() {
		S = next().toCharArray();

		int[] a = new int[26];
		for(char c : S){
			a[c-'a']++;
		}

		for(int i : a){
			if(i > 1){
				out.println("no");
				return;
			}
		}
		out.println("yes");
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 23252
import java.util.Arrays;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        long sumOfP = sc.nextLong();
        long countP = 0;
        long sumOfM = sumOfP;
        long countM = 0;

        if (sumOfP <= 0) {
            countP = -sumOfP + 1;
            sumOfP = 1;
        }

        if (sumOfM >= 0) {
            countM = sumOfM + 1;
            sumOfM = -1;
        }

        for (int i = 1; i < n; i++) {
            long a = sc.nextLong();

            if (sumOfP > 0) {
                if (sumOfP + a >= 0) {
                    countP += sumOfP + a + 1;
                    sumOfP = -1;
                } else {
                    sumOfP += a;
                }
            } else {
                if (sumOfP + a <= 0) {
                    countP += -(sumOfP + a) + 1;
                    sumOfP = 1;
                } else {
                    sumOfP += a;
                }
            }

            if (sumOfM > 0) {
                if (sumOfM + a >= 0) {
                    countM += sumOfM + a + 1;
                    sumOfM = -1;
                } else {
                    sumOfM += a;
                }
            } else {
                if (sumOfM + a <= 0) {
                    countM += -(sumOfM + a) + 1;
                    sumOfM = 1;
                } else {
                    sumOfM += a;
                }
            }
        }

        System.out.println(Math.min(countP, countM));
    }
}


Measured memory_bytes: 50288
// Vicfred
// https://atcoder.jp/contests/abc176/tasks/abc176_c
// greedy
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    long n = readln.chomp.to!long;
    long[] a = readln.split.map!(to!long).array;

    long last = a[0];
    long ans = 0;

    for(int i = 1; i < n; i++)
        if(a[i] < last)
            ans += last - a[i];
        else
            last = a[i];

    ans.writeln;
}



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

int main()  {
    int n;
    cin>>n;
    int a[n];
    
    for(int i=0; i<n;i++){
        cin>>a[i];
        }
    int c=0;
    for(int i=1; i<n-1;i++){
        if((a[i]<a[i-1]&&a[i]>a[i+1])||(a[i]>a[i-1] && a[i]<a[i+1]))
            c++;
        }
        cout<<c;
}

Measured memory_bytes: 3592
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	s := nextString()
	n, _ := strconv.Atoi(s)
	i := n
	var sn int
	for i > 0 {
		sn += i % 10
		i = i / 10
	}
	if n%sn == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int ans = Math.max(0, a - b * 2);
        System.out.println(ans);
    }
}

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

int main() {
	string s,t;
	cin>>s>>t;
	int n=s.length(),m=t.length();
	int ans=m;
	for(int i=0;i<=n-m;i++){
	    int dis=0;
	    for(int j=0;j<m;j++){
	        if(s[i+j]!=t[j]){
	            dis++;
	        }
	    }
	    if(dis<ans)
	    ans=dis;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)

int main(){
  int n,k;
  cin >> n >> k;
  VI l(k),r(k);
  VLL dp(n+10,0);
  REP(i,0,k){
    cin >> l[i] >> r[i];
  }
  dp[1] = 1;
  dp[2] = -1;
  
  REP(i,1,n+1){
    dp[i] += dp[i-1];
    dp[i] %= 998244353;
    if(dp[i]<0){dp[i] += 998244353;}
    REP(j,0,k){
      if(i+l[j] <= n){
        dp[i+l[j]] += dp[i];
        dp[i+l[j]] %= 998244353;
      }
      if(i+r[j]+1 <= n){
        dp[i+r[j]+1] -= dp[i];
      }
    }
  }
  
  cout << dp[n] << endl;
  
  return 0;
}


Measured memory_bytes: 4828
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int n;
LL a[MAX];

int main(void) {
    scanf("%d", &n);
    int four = 0, two = 0;
    int other = 0;
    REP(i, n) {
        scanf("%lld", a + i);
        if (a[i] % 4 == 0) {
            four++;
        } else if (a[i] % 2 == 0) {
            two++;
        } else {
            other++;
        }
    }
    if (n == 1 && four == 0) {
        cout << "No" << endl;
        return 0;
    }
    if (two == n) {
        cout << "Yes" << endl;
        return 0;
    }
    if (n / 2 <= four) {
        cout << "Yes" << endl;
    } else {
        n -= two + 1;
        four -= 1;
        if (n / 2 <= four) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 1024
struct T{int a,b;}A[3333];
comp(a,b)struct T*a,*b;{return a->a-b->a?:a->b-b->b;}
long h,w,dp[3333],mod=1e9+7,fac[2<<17],inv[2<<17];
long p(long a,long b){return b?p(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long f(long a,long b){return fac[a+b]*inv[a]%mod*inv[b]%mod;}
i;
main()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<2<<17;i++)fac[i]=fac[i-1]*i%mod,inv[i]=p(fac[i],mod-2);
	for(;~scanf("%d%d",&A[i].a,&A[i].b);i++)i||gets(dp);
	qsort(A,i,sizeof(struct T),comp);
	for(int j=0;j<i;j++)
	{
		long now=f(A[j].a-1,A[j].b-1);
		for(int k=j;k--;)
		{
			int x=A[j].a-A[k].a,y=A[j].b-A[k].b;
			if(x>=0&y>=0)
			{
				now=(now-dp[k]*f(x,y)%mod+mod)%mod;
			}
		}
		dp[j]=now;
	}
	printf("%d",dp[i-1]);
}

Measured memory_bytes: 4476
#include<iostream>
#include<map>
#include<queue>
#include<cstring>
using namespace std;

typedef pair<int,int> P;
priority_queue<P> que;
void bfs(int wa,int hu);
int res[1000002];

int main(){
	int n,q,a,v;
	cin >> n >> q;
	memset(res,0,n+2);
	for(int i=0;i<q;i++){
		cin >> a >> v;
		res[a] += v;
		bfs(res[a],-a);
	}
}

void bfs(int wa,int hu){
	que.push(P(wa,hu));
	int tmp,po;
	while(1){
		P p = que.top();
		po = p.first;
		tmp = -p.second;
		if(res[tmp] == po){
			break;
		}
		que.pop();
	}
	cout << tmp << " " << po << endl;
}

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

int main(){
    double n; cin>>n;
    vector<int> x(n);
    rep(i,n) cin>>x[i];
    double ave;
    double sum=0;
    rep(i,n) sum+=x[i];
    ave=sum/n;
    //cout<<ave<<" ";
    if((ave-int(ave))<0.5) ave=int(ave);
    else ave=int(ave)+1;
    //cout<<ave<<endl;
    int ans=0;
    rep(i,n) ans+=pow(abs(x[i]-ave),2);
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> v(n + 1);
    for(int i = 1; i < n; i++)
    {
        int num;
        cin >> num;
        v[num]++; 
    }

    for(int i = 1; i <= n; i++)
        cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 4052
use std::collections::HashSet;
use std::collections::VecDeque;

fn main(){
  let hw: Vec<usize> = read_vec();
  let h = hw[0];
  let w = hw[1];

  let mut vm: Vec<Vec<u32>> = Vec::new();

  for _ in 0 .. h {
    let s: String = read();
    vm.push(s.chars().map(|c| if c == '.' {0} else {c.to_digit(10).unwrap()}).collect());
  }

  let mut sc: HashSet<(usize, usize)> = HashSet::new();
  
  for i in 1 .. h-1 {
    for j in 1 .. w-1 {
      if vm[i][j] > 0 {
        sc.insert((i, j));
      }
    }
  }
  
  let mut ct = 0;

  loop {
    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    
    for &(i, j) in sc.iter() {
      if vm[i][j] > 0 {
        let an = [(i+1,j),(i+1, j+1),(i, j+1),(i-1,j+1),(i-1,j),(i-1, j-1),(i,j-1),(i+1,j-1)];
        let cn: u32 = an.iter().map(|&(y, x)| {if vm[y][x] == 0 {1} else {0}}).sum();
        if cn >= vm[i][j] {
          q.push_back((i, j));
        }
      }
    }

    if q.is_empty() { break; }
    
    let mut snc: HashSet<(usize, usize)> = HashSet::new();
    
    for &(i, j) in q.iter() {
      vm[i][j] = 0;

      let an = [(i+1,j),(i+1, j+1),(i, j+1),(i-1,j+1),(i-1,j),(i-1, j-1),(i,j-1),(i+1,j-1)];

      for &(ni, nj) in an.iter() {
        if vm[ni][nj] > 0 {
          snc.insert((ni, nj));
        }
      }
    }

    sc = snc;
    
    ct += 1;
  }

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

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 82620
n=gets.to_i
s=gets.split.map &:to_i
a=s.reverse
ans=[]
ans1=[]
ans2=[]
ans1[0]=s[0]
ans2[0]=a[0]
sum1=s[0]
sum2=a[0]
for i in 1..n-2
    ans1 << sum1=sum1.gcd(s[i])
    ans2 << sum2=sum2.gcd(a[i])
end
ans << ans2[n-2]
ans << ans1[n-2]
ans2.delete_at(n-2)
ans1.delete_at(n-2)
ans2.reverse!
for i in 0..n-3
  ans << ans1[i].gcd(ans2[i])
end
puts ans.max


Measured memory_bytes: 24028
#include <stdio.h>

int main(void) {
	int N;
	if (scanf("%d", &N) != 1) return 1;
	switch (N % 10) {
		case 2: case 4: case 5: case 7: case 9:
			puts("hon");
			break;
		case 0: case 1: case 6: case 8:
			puts("pon");
			break;
		case 3:
			puts("bon");
			break;
		default:
			puts("you are an idiot");
			break;
	}
	return 0;
}


Measured memory_bytes: 1620
import std.stdio;
import std.string;
import std.array; // split
import std.conv; // to

void main()
{
   string s1 = chomp(readln());
   string s2 = chomp(readln());
   int a = to!int(s1); // 第0要素を整数に変換
   int b = to!int(s2); // 第1要素を整数に変換
   a *= a;
   writeln(a-b); // 表示
}

Measured memory_bytes: 256
function main(input){
input=input.split("\n");
	var S=input[0];
  var a=S.substr(2,1);
	var b=S.substr(3,1);
	var c=S.substr(4,1);
	var d=S.substr(5,1);
	if (a==b && c==d){
  console.log("Yes");
	}else{
	console.log("No");
	}
	



}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29532
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<bool> flag(N);
	vector<int> num(N, 1);
	flag[0] = true;
	
	for (auto i = 0; i < M; ++i)
	{
		int x, y;
		cin >> x >> y;
		--x;
		--y;

		if (flag[x])
		{
			flag[y] = true;
		}
		++num[y];
		--num[x];
		if (num[x] <= 0)
		{
			flag[x] = false;
		}
	}

	auto ans = 0;
	for (auto i = 0; i < N; ++i)
	{
		if (flag[i])
		{
			++ans;
		}
	}
	cout << ans << endl;

	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_H 10
#define MAX_W 1'000
#define MAX_K 10'000
i64 H, W, K;
i64 G[MAX_H][MAX_W];
i64 C[MAX_H + 1][MAX_W + 1];

bool cond(i64 bit, i64 x1, i64 x2) {
    // [y1, x1] [y2, x2] の区画 が K以下か
    // O(H);
    i64 y1 = 0;
    REP(y2, H) {
        if ((bit & (1 << y2)) || y2 == (H - 1)) {
            i64 n = C[y2 + 1][x2 + 1] - C[y2 + 1][x1] - C[y1][x2 + 1] + C[y1][x1];
            if (n > K) return false;
            y1 = y2 + 1;
        }
    }

    return true;
}

int main() {
    cin >> H >> W >> K;
    char c;
    REP(y, H) REP(x, W) {
        cin >> c;
        G[y][x] = c - '0';
    }

    REP(y, H + 1) REP(x, W + 1) C[y][x] = 0;
    REP(y, H) REP(x, W) {
        C[y + 1][x + 1] = C[y][x + 1] + C[y + 1][x] - C[y][x] + G[y][x];
    }

    i64 min_cnt = 10000000000;
    for (i64 bit = 0; bit < (1 << (H - 1)); bit++) {
        i64 n_row = __builtin_popcount(bit) + 1;

        i64 x2 = 0;
        i64 x1 = 0;
        i64 n_col = 1;
        bool ok = true;
        while (x2 < W) {
            if (cond(bit, x1, x2)) {
                x2++;
            } else if (x2 - x1 > 0){
                x1 = x2;
                n_col++;
            } else {
                ok = false;
                break;
            }
        }
        if (ok) {
            chmin(min_cnt, (n_col - 1) + (n_row - 1));
        }
    }

    cout << min_cnt << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;
 
int n, mx;
string s;

int main(){

    cin >> n;

    map<string, int> m;

    vector<pair<int, string> > v;

    vector<string> g;

    for(int i = 0; i < n; i++){
        cin >> s;
        if(m.find(s) != m.end()){
            m[s]++;
        } else{
            m[s] = 0;
        }
    }

    map<string, int>::iterator it;

    for(it = m.begin(); it != m.end(); it++){
        v.push_back(make_pair(it->second, it->first));
    }

    sort(v.rbegin(), v.rend());

    mx = v[0].first;

    for(int i = 0; i < v.size(); i++){
        if(v[i].first == mx){
            g.push_back(v[i].second);
        }
    }

    sort(g.begin(), g.end());

    for(int i = 0; i < g.size(); i++){
        cout << g[i] << nl;
    }




 
}
 
//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 32752
n = int(input())
mons = sorted(list(map(int, input().split())))

while(len(mons) > 1):
    mons = sorted([mons[0]] + list(map(lambda x:x%mons[0], mons[1:])))
    while mons[0]==0: del mons[0]
print(mons[0])

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

int main(){
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i,n) cin >> a[i];
  int s[n];
  rep(i,k) {
    rep(j,n) s[j] = 0;
    rep(j,n) {
      s[max(j-a[j],0)]++;
      if(j+a[j]+1 < n) s[j+a[j]+1]--;
    }
    bool f = true;
    for(int j = 1; j < n; j++) s[j] += s[j-1];
    rep(j,n) {
      if(s[j] != n) f = false;
    }
    rep(j,n) a[j] = s[j];
    if(f) break;
  }
  rep(i,n) cout << a[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 5156
import std.stdio : readln, writeln, writefln;
import std.array : array, split;
import std.conv  : to;
import std.range.primitives;
import std.range : enumerate, iota, repeat, retro, assumeSorted;
import std.algorithm.searching  : all, any, canFind, count, countUntil;
import std.algorithm.comparison : max, min, clamp;
import std.algorithm.iteration  : each, group, filter, map, reduce, permutations, sum, uniq;
import std.algorithm.sorting    : sort;
import std.algorithm.mutation   : reverse, swap;

void main() {
    int n, y;
    scan(n, y);

    foreach (i ; 0 .. n + 1) {
        foreach (j ; 0 .. n + 1 - i) {
            int k = n - i - j;

            if (10000*i + 5000*j + 1000*k == y) {
                writeln(i, ' ', j, ' ', k);
                return;
            }
        }
    }

    writeln(-1, ' ', -1, ' ', -1);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.array : split;
    import std.conv  : to;
    import std.range.primitives;

    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true){
			int n=in.nextInt();
			if(n==0)break;
			String name[]= new String[n];
			int P[]=new int[n];//種の値段
			int S[]=new int[n];//実の値段
			int M[]=new int[n];//何回実がなるか
			int F[]=new int[n];//累計何個実が出来るか
			plants pp[] = new plants[n];
			Name nn[] = new Name[n];
			for(int i=0;i<n;i++){
				int mim = 0;
				int time=0;
				name[i]=in.next();
				P[i]=in.nextInt();
				time+=in.nextInt();//A
				time+=in.nextInt();//B
				time+=in.nextInt();//C
				mim+=in.nextInt();//D
				mim+=in.nextInt();//Eこれらは
				F[i]=in.nextInt();
				S[i]=in.nextInt();
				M[i]=in.nextInt();
				for(int s=0;s<M[i];s++){
					time+=mim;
				}
				double c = 1.000*((F[i]*S[i]*M[i])-P[i])/time;
				nn[i] = new Name(name[i],c);
			}
			Arrays.sort(nn);
			for(int i=0;i<n;i++){
				pp[i] = new plants(nn[i].name,nn[i].cost);//名前順にソートしなきゃいけない。
			}
			Arrays.sort(pp);
			for(int i=0;i<n;i++){
				System.out.println(pp[i].name);
			}
			System.out.println("#");
		}
	}
	static class plants implements Comparable<plants>{
		String name;
		double cost;
		plants(String name,double cost){
			this.name=name;
			this.cost=cost;
		}
		public int compareTo(plants o) {
			return Double.compare(o.cost,this.cost);//降順
			/*
			 if(this.cost==o.cost){
				 return 0;
			 }else if(this.cost>o.cost){
				 return -1;
			 }else{
				 return 1;
			 }*/
		}
	}
	static class Name implements Comparable<Name>{
		String name;
		double cost;
		Name(String name,double cost){
			this.name=name;
			this.cost=cost;
		}
		public int compareTo(Name o) {
			return this.name.compareTo(o.name);
		}
		
	}
}

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

int main() {
  int N; cin>>N;
  vector<ll> A(N);
  ll ans=0;
  for(int i=0; i<N; ++i) cin>>A[i];
  for(int i=1; i<N; ++i) {
    // 一個前の人間と身長を比較
    if(A[i]>=A[i-1]) continue;
    else {
      ans+=A[i-1]-A[i];
      A[i]=A[i-1];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w,n;
int x[200005],y[200005];
vector<int> vec[200005];
set<P> se;

int main(void){
    scanf("%d%d%d",&h,&w,&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&x[i],&y[i]);
        vec[y[i]-1].push_back(x[i]-1);
        se.insert(P(x[i]-1,y[i]-1));
    }
    for(int i=0;i<w;i++){
        sort(vec[i].begin(),vec[i].end());
    }
    int ans=h;
    int cx=0;
    for(int i=0;i<w;i++){
        for(int j=0;j<vec[i].size();j++){
            int pos=vec[i][j];
            if(pos>=ans)break;
            if(cx<pos){
                ans=pos;
                break;
            }
        }
        cx++;
        if(se.find(P(cx,i))!=se.end())break;
        bool ng=false;
        //printf("%d %d\n",cx+1,i+1);
        while(se.find(P(cx,i+1))!=se.end()){
            cx++;
            if(se.find(P(cx,i))!=se.end())ng=true;
        }
        if(ng)break;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 19712
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<unordered_set>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
void solve()
{
    ll N;
    cin>>N;
    unordered_set<ll>ans;  
    if(N-1>1)
    ans.insert(N-1);
    for(ll k=2;k*k<=N-1;k++){
        if((N-1)%k==0){
            ans.insert(k);
            ans.insert((N-1)/k);
        }
    }
    ans.insert(N);
    for(ll k=2;k*k<=N;k++){
        if(N%k==0){
            ll t=N;
            while(t%k==0)t/=k;
            if(t%k==1)ans.insert(k);
        }
    }
    cout<<ans.size()<<'\n';
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

using namespace std;

int main()
{
    #ifdef HOME
    freopen("input.txt", "rt", stdin);
    #endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a;
    a.resize(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector <int> m2, m4, m;
    for (int i = 0; i < n; i++){
        if (a[i] % 4 == 0)
            m4.push_back(a[i]);
        else
        if (a[i] % 4 == 2)
            m2.push_back(a[i]);
        else
            m.push_back(a[i]);
    }
    int k = (m2.size() == 0) ? 0 : 1;
    if (m4.size() + 1 >= m.size() + k)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int a,b; cin >> a >> b;
  std::cout << max(a-2*b,0) << '\n';
}


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


using S = set<int>;
S U;
map<char, S> m;

string s;
int N;
int c;

S expr();
S factor();
S num();

void debug(string text){
	return;
	cout << text + " " + s << endl;
	for(int i = 0; i < text.size() + 1 + N; i++){
		if(i == text.size() + 1 + c) cout << "*";
		else cout << " ";
	}
	cout << endl;
}

S Union(S s1, S s2){
	for(auto v : s2){
		s1.insert(v);
	}
	return s1;
}

S Intersection(S s1, S s2){
	S ret;
	for(auto v : s2){
		if(s1.count(v)) ret.insert(v);
	}
	return ret;
}

S Diff(S s1, S s2){
	S ret;
	for(auto v : s1){
		if(!s2.count(v)) ret.insert(v);
	}
	return ret;
}

S SymDiff(S s1, S s2){
	S ret;
	for(auto v : s1){
		if(!s2.count(v)) ret.insert(v);
	}
	for(auto v : s2){
		if(!s1.count(v)) ret.insert(v);
	}
	return ret;
}

S Comp(S s1){
	S ret;
	for(auto v : U){
		if(!s1.count(v)) ret.insert(v);
	}
	return ret;
}

S expr(){
	debug("expr");
	S x = factor();
	while(c < N){
		if(s[c] == 'u'){
			c++;
			x = Union(x, factor());
		}
		else if(s[c] == 'i'){
			c++;
			x = Intersection(x, factor());
		}
		else if(s[c] == 'd'){
			c++;
			x = Diff(x, factor());
		}
		else if(s[c] == 's'){
			c++;
			x = SymDiff(x, factor());
		}
		else break;
	}
	return x;
}

S factor(){
	debug("factor");
	bool rev = false;
	if(s[c] == 'c'){
		rev = 1;
		c++;
	}

	if(s[c] == '('){
		c++;
		S ret = expr();
		assert(s[c] == ')');
		c++;
		if(rev) ret = Comp(ret);
		return ret;
	}
	S ret = num();
	if(rev) ret = Comp(ret);
	return ret;
}

S num(){
	debug("num");
	S ret = m[s[c]];
	c++;
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	while(true){
		m.clear();
		U.clear();
		char name;
		int n;
		while(true){
			if(!(cin >> name >> n)) return 0;
			if(name == 'R') break;
			for(int i = 0; i < n; i++){
				int a;
				cin >> a;
				U.insert(a);
				m[name].insert(a);
			}
		}
		//m['U'] = U;
		cin >> s;
		N = s.size();
		c = 0;
		S ans = expr();
		if(ans.size()){
			vector<int> v(ans.begin(), ans.end());
			for(int i = 0; i < v.size(); i++){
				cout << v[i];
				if(i != v.size() - 1) cout << " ";
			}
			cout << endl;
		}
		else{
			cout << "NULL" << endl;
		}
	}
}

Measured memory_bytes: 3020
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 200000;
const int MAX_M = 200000;

int main() {
  ll a, b, c, x, y, ans = 0;
  cin >> a >> b >> c >> x >> y;
  ll tmp = min(x, y);
  ans += min(tmp*(a+b), 2*tmp*c);
  x -= tmp; y -= tmp;
  ans += min(a*x + b*y, 2*(x+y)*c);
  cout << ans << endl;
  return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<tuple<int, int, int, int>>> v(H, vector<tuple<int, int, int, int>>(W, make_tuple(0, 0, 0, 0)));
    vector<string> s(H);
    REP(i, H) {
        cin >> s[i];
    }
    REP(i, H) {
        int left = -1;
        REP(j, W) {
            if(s[i][j] == '#') {
                left = j;
            }else{
                v[i][j] = make_tuple(left, 0, 0, 0);
            }
        }
        int right = W;
        for(int j = W - 1;0 <= j;j--) {
            if(s[i][j] == '#') {
                right = j;
            }else{
                int l;
                tie(l, ignore, ignore, ignore) = v[i][j];
                v[i][j] = make_tuple(l, right, 0, 0);
            }
        }
    }

    REP(j, W) {
        int up = -1;
        REP(i, H) {
            if(s[i][j] == '#') {
                up = i;
            }else{
                int l, r;
                tie(l, r, ignore, ignore) = v[i][j];
                v[i][j] = make_tuple(l, r, up, 0);
            }
        }
        int down = H;
        for(int i = H - 1;0 <= i;i--) {
            if(s[i][j] == '#') {
                down = i;
            }else{
                int l, r, u;
                tie(l, r, u, ignore) = v[i][j];
                v[i][j] = make_tuple(l, r, u, down);
            }
        }
    }

    int res = -1;
    REP(i, H) {
        REP(j, W) {
            int l, r, u, d;
            tie(l, r, u, d) = v[i][j];
            if(l < r && u < d) {
                res = max(res, (r - l) + (d - u) - 3);
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 66944
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
  int n;
  vector<long long> a, b;

  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    b.push_back(x);
  }

  vector<long long> c;
  for (int i = 0; i < n; i++) {
    c.push_back(a[i] - b[i]);
  }

  sort(c.rbegin(), c.rend());
  long long ans = 0;
  long long sum1 = 0;
  long long sum2 = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] > 0) {
      sum1 += c[i];
    }
    if (c[i] < 0) {
      ans++;
      sum2 += -c[i];
    }
  }
  if (sum1 < sum2) {
    cout << -1 << endl;
    return 0;
  }
  int i = 0;
  while (true) {
    if (sum2 <= 0) {
      break;
    }
    if (c[i] > 0) {
      sum2 -= c[i];
      ans++;
    }
    i++;
  }
  cout << ans << endl;

  return 0;
}

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

#define ll long long
#define mk make_pair
#define pb push_back


using namespace std;


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

   string s; cin >> s;
   
   bool ans = false;
   for(int i = 0; i < s.size(); i++){
      if(s[i] == '7'){
         ans = true;
         break;
      }
   }

   if(ans) cout << "Yes";
   else cout << "No";
   return 0;
}


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

typedef long long ll;
const int MAX_N = 50;

int main() {
  int N, K, V[MAX_N];
  std::cin >> N >> K;
  for(int i = 0; i < N; ++i) {
    std::cin >> V[i];
  }

  int ans = 0;
  for(int L = 0; L <= std::min(N, K); ++L) {
    for(int R = 0; L + R <= std::min(N, K); ++R) {
      int sum = 0;
      std::priority_queue<int, std::vector<int>, std::greater<int>> selected;
      for(int i = 0; i < L; ++i) {
        sum += V[i];
        selected.push(V[i]);
      }
      for(int i = 0; i < R; ++i) {
        sum += V[N - 1 - i];
        selected.push(V[N - 1 - i]);
      }

      int cnt = 0;
      while(!selected.empty() and cnt < K - L - R) {
        if(selected.top() >= 0) break;
        sum -= selected.top(); selected.pop();
        ++cnt;
      }
      ans = std::max(ans, sum);
    }
  }

  std::cout << ans << std::endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int top, S[1000];

void push(int x)
{
  S[++top] = x;
}

int pop()
{
  return S[top--];
}

int main(){
  int a, b;
  top = 0;
  char s[100];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      b = pop();
      a = pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }
    else if(s[0] == '*'){
      b = pop();
      a = pop();
      push(a*b);
    }
    else push(atoi(s));
  }

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

  return 0;
}




Measured memory_bytes: 3232
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,c = map(int,readline().split())
xv = []
l1 = []
for i in range(n):
    x,v = map(int,readline().split())
    xv.append([x,v])
    l1.append(v)
l2 = l1[::]
r1 = l1[::-1]
r2 = r1[::]


for i in range(1, n) :
    l1[i] += l1[i-1]
    l2[i] += l2[i-1]
    r1[i] += r1[i-1]
    r2[i] += r2[i-1]

for i in range(n) :
    x = xv[i][0]
    l1[i] -= x
    l2[i] -= 2 * x
    r1[n-1-i] -= c - x
    r2[n-1-i] -= 2 * (c - x)
 
for i in range(1, n) :
    l1[i] = max(l1[i], l1[i-1])
    r1[i] = max(r1[i], r1[i-1])
 
res = max(l1[-1], r1[-1])
for i in range(n-1) :
    res = max(res, l2[i] + r1[n-2-i])
    res = max(res, r2[i] + l1[n-2-i])
    
print(max(res, 0))

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

int main(){
    int n;
    while(cin>>n){
        if(n==0)
            break;
        int a[n];
        for(int i=0; i<n; i++) cin >> a[i];
        int Max = a[0];
        
        for(int i=0; i<n; i++){
            int sum=0;
            for(int j=i; j<n; j++){
                sum+=a[j];
                if(Max < sum) Max = sum;
            }
        }
        cout << Max << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> w(n);
  map<string, int> mp;
  for(int i = 0; i < n; i++){
  	cin >> w.at(i);
  	mp[w.at(i)]++;
  }
  
  bool ans = true;
  for(int i = 0; i < n-1; i++){
  	if(w.at(i).at(w.at(i).size()-1) != w.at(i+1).at(0)){
    	ans = false;
    }
  }
  for(auto p : mp){
  	if(p.second > 1){
    	ans = false;
    }
  }
  if(ans){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int solve(){
  int n;
  cin >> n;
  int odd = 0;
  rep(i,n){
    int tmp;
    cin >> tmp;
    if(tmp % 2 != 0)odd++;
  }
  if(odd % 2 == 0)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h> 
#include <stack>
#include <bitset>
#include <map>
#include <cmath>
#include <climits>
#include <queue>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	int n, m, A, B;
	scanf("%d %d", &n, &m);
	vector<int> height(n);
	vector<bool> ok(n, true);
	rep(i, n) scanf("%d", &height[i]);

	rep(i, m) {
		scanf("%d %d", &A, &B);
		A--; B--;
		if (height[A] <= height[B]) ok[A] = false;
		if (height[B] <= height[A]) ok[B] = false;
	}

	A = 0;
	rep(i, n) if (ok[i]) A++;

	printf("%d\n", A);
}

Measured memory_bytes: 3820
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <algorithm>
#include <math.h>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#endif

#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
/*#define NUMTOSTR(x)  (unsigned char)((x) + 48);*/
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;
using namespace std;

bool isok(int n) {
	unordered_multiset<char> ums;
	for (auto& i : to_string(n)) ums.insert(i);
	if (ums.count(n % 10 + '0') == ums.size()) return true;
	return false;
}

int main(){
	fastIO;
	int n;
	cin >> n;
	if (n % 1000 == 0) cout << 0;
	else
	cout << 1000 - (n % 1000);
	return 0;
}



Measured memory_bytes: 3584
import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + (10**4))
dp[0] = 0
for a, b in AB:
    for n in range(H):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

print(min(dp[H:]))


Measured memory_bytes: 41196
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int N, M, score,max1 = 0;
  cin >> N;
  
  vector<string> s(N);
  for (int i = 0; i<N; i++){
  	cin>>s[i];
  }
  
  cin>>M;
  vector<string> t(M);
  for(int i = 0; i<M; i++){
    cin>>t[i];
  }
  
  for(int i = 0; i<N; i++){
    score = 0;
  	for(int j = 0; j<N; j++){
      if(s[i] == s[j]){
      	score++;
      }
    }
    
    for(int k = 0; k<M; k++){
    	if(s[i] == t[k]){
      	score--;
        }
    }
    max1 = max(max1,score);
  }
  
  cout<<max1<<endl;
}

Measured memory_bytes: 256