akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  int n;
  cin >> n;

  vector<string> array(n);

  REP(i, n){
    cin >> array[i];
  }

  bool flag = true;

  REP(i, n-1) {
    if (*(array[i].end() - 1) != *array[i+1].begin()) {
      flag = false;
      //cout << *(array[i].end() - 1) << " " << array[i+1] << endl;
    }
  }

  for (int i = 1; i < n; i++){
    for (int j = 0; j < i; j++){
      if (array[i] == array[j]) flag = false;
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
	int N;
	char S[300000];
	cin >> N;
	rep(i,N){
		cin >> S[i];
	}
	int ans = 0;
	
	for (int i = 0; i <= 999 ; ++i) {
		bool ok = false;
		int a = i / 100;
		int b = (i / 10) % 10;
		int c = i % 10;
		int val[3] = {a,b,c};
		
		int f =0;
		rep(j,N){
			if (S[j] == '0' + val[f]){
				f++;
			}
			if (f == 3) break;
		}
		
		if (f == 3) ans++;
	}
	cout << ans << endl;
}



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

using namespace std;

int main() {
	int n, a;
	cin >> n;

	vector<int> nums(1e5 + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a;
		nums[a]++;
	}

	int ans = 0;
	for (int i = 2; i < nums.size(); i++) {
		ans = max(ans, nums[i-2] + nums[i-1] + nums[i]);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vl A(N);
	vl MP(100001, 0);
	ll res = 0;
	REP(i, N) {
		cin >> A[i];
		MP[A[i]] += 1;
		res += A[i];
	}
	int Q; cin >> Q;
	REP(i, Q) {
		ll B, C; cin >> B >> C;
		ll minus = MP[B] * B;
		ll plus = MP[B] * C;
		res = res + plus - minus;
		cout << res << endl;
		MP[C] += MP[B];
		MP[B] = 0;
	}
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 4660
#include <stdio.h>

#define MAX 100000
#define SENTINEL 2000000000

typedef struct{
  char suit;
  int value;
} Card;

Card L[MAX/2+2],R[MAX/2+2];

void merge(Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }
    else A[k]=R[j++];
  }
}

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

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

void quickSort(Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main()
{
  int n,i,v;
  Card A[MAX],B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit) stable=0;
  }
  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) printf("%c %d\n",B[i].suit,B[i].value);
  return 0;
}
  

Measured memory_bytes: 2952
n = int(input())
s = input()

c0 = [0] * n
c1 = [0] * n
for i in range(1, n):
  c0[i] = c0[i-1] + (s[i-1] == "#")
  c1[n-i-1] = c1[n-i] + (s[n-i] == ".")

min = n
for x, y in zip(c0, c1):
  if min > x + y:
    min = x + y
print(min)

Measured memory_bytes: 19108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int a,b,k; cin>>a>>b>>k;
    for(int i=min(a,b);i>0;i--){
        if(a%i==0&&b%i==0) k--;
        if(k==0){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
using Grid = vector<vector<char>>;
#define vc vector<char>
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
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;
}

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
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;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N;
    cin>>N;
    N=N%10;
    if(N==2||N==4||N==5||N==7||N==9)cout<<"hon"<<endl;
    else if(N==0||N==1||N==6||N==8)cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n;
	cin>>n;
	vector<int> w(n+1,0);
	FOR(i,0,n)cin>>w[i];
	int ans=mod,ss=0;
	w[n]=0;
	FOR(i,0,n)ss+=w[i];
	FOR(i,0,n+1){
		int s=0;
		FOR(j,0,i){
			s+=w[j];
		}
		int t=abs(ss-s-s);
		ans=min(ans,t);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char c[1201];
  int i;
  int ans[26];
  int b=1;
  for(i=0; i<26; i++)ans[i]=0;
  i=0;
  while(scanf("%c",&c[i])!=EOF){
      if(c[i]>='a'&&c[i]<='z')ans[c[i]-'a']++;
      if(c[i]>='A'&&c[i]<='Z')ans[c[i]-'A']++;
      i+=1;
  }
  for(i=0; i<26; i++)printf("%c : %d\n",'a'+i,ans[i]);
  return 0;
}



Measured memory_bytes: 2048
use proconio::input;
use std::cmp::max;

fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let mut m = a*c;
    m = max(m, a*d);
    m = max(m, b*d);
    m = max(m, c*b);
    println!("{}", m);
}


Measured memory_bytes: 2176
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//入力
		int N = sc.nextInt();

		List<String> SList = new ArrayList<String>();

		for (int i = 0; i < N; i++) {
			String S = sc.next();
			SList.add(S);
		}

		int flagM=0;
		int countM=0;

		int flagA=0;
		int countA=0;

		int flagR=0;
		int countR=0;

		int flagC=0;
		int countC=0;

		int flagH=0;
		int countH=0;

		Long answer = (long)0;

		for (int i = 0; i < N; i++) {
			if (SList.get(i).substring(0,1).equals("M")) {
				flagM = 1;
				countM++;
			}
			else if (SList.get(i).substring(0,1).equals("A")) {
				flagA = 1;
				countA++;
			}
			else if (SList.get(i).substring(0,1).equals("R")) {
				flagR = 1;
				countR++;
			}
			else if (SList.get(i).substring(0,1).equals("C")) {
				flagC = 1;
				countC++;
			}
			else if (SList.get(i).substring(0,1).equals("H")) {
				flagH = 1;
				countH++;
			}
			else {

			}
		}

		if (flagM + flagA + flagR + flagC + flagH >2) {
			answer = answer
					+ ((long)countM * (long)countA * (long)countR)
					+ ((long)countM * (long)countA * (long)countC)
					+ ((long)countM * (long)countA * (long)countH)
					+ ((long)countM * (long)countR * (long)countC)
					+ ((long)countM * (long)countR * (long)countH)
					+ ((long)countM * (long)countC * (long)countH)
					+ ((long)countA * (long)countR * (long)countC)
					+ ((long)countA * (long)countR * (long)countH)
					+ ((long)countA * (long)countC * (long)countH)
					+ ((long)countR * (long)countC * (long)countH);
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 62176
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
 int a,b;

 cin >> a >> b;

 if(a < b)
  cout << "a < b" << endl;
 else if(a > b)
  cout << "a > b" << endl;
 else
  cout << "a == b" << endl;

 return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005

int main()
{
    fio;
    int t,n,i,x;
    cin >> x >> n;
    int y;
    set<int> s;
    f(i,0,n)    
    {
        cin >> y;
        s.insert(y);
    }
    int ans = INT_MAX, res = INT_MAX;
    f(i,x, MAXN)
    {
        if(s.find(i) == s.end() && abs(x - i) <= res)
        {
            res = abs(x-i);
            ans = min(ans,i);
            break;
        }
    }
    for(int i = x;i>=0;i--)
    {
        if(s.find(i) == s.end() && abs(x-i) <= res)
        {
            res = abs(x-i);
            ans = min(ans,i);
            break;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N;
  string C;
  cin >> N;

  for (int i = 0; i < N; i++) {
  cin >> C;
    if(C=="Y"){
    cout << "Four" << endl;
    break;
    }
    if(i==N-1){
    cout << "Three" << endl;
    }
  }
}

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

int main() {
  int N; cin >> N;
  ll power = 1;
  for (int i=1; i<=N; i++){
    power *= i;
    power %= 1000000007;
  }
  cout << power << endl;
  return 0;
}

Measured memory_bytes: 3636
/*
	*	Created By: 'Present_Sir'
	*	Created On: Friday 14 August 2020 01:00:51 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;


void solve(){
    int k;
    cin>>k;

    int ans = 0;

    for(int i=1; i<=k; ++i){
        for(int j=1; j<=k; ++j){
            for(int t=1; t<=k; ++t){
                ans += (__gcd(i,__gcd(j,t)));
            }
        }
    }
    cout<<ans<<endl;
}

int32_t main(){
    IOS;
    //int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}



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

int main()
{
	int64_t N, A, B;
	scanf("%lld%lld%lld", &N, &A, &B);
	if (A > B) std::swap(A, B);
	int64_t diff{B - A};
	if (diff % 2 == 0) printf("%lld\n", diff / 2);
	else printf("%lld\n", std::min(N - B + (diff + 1) / 2, A - 1 + (diff + 1) / 2));

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N;
	cin >> N;
	VI A(N);
	int ma = 0;
	REP(i, N) {
		cin >> A[i];
		ma = max(ma, A[i]);
	}
	VI sumdp(ma + 1, 0);
	VI dp(N + 1);
	dp[0] = 1;
	sumdp[A[0]] += 1;
	eFOR(i, 1, N) {
		if (i < N&&A[i] == A[i - 1])continue;
		dp[i] = sumdp[A[i-1]];
		if (i < N) {
			sumdp[A[i]] += dp[i];
		}
		dp[i] %= mod;
		sumdp[A[i]] %= mod;
	}
	cout << dp[N] << endl;
	return 0;
}



Measured memory_bytes: 4992
c = [list(map(int, input().split())) for _ in range(3)]

for i in range(1, 3):
    d = c[i][0] - c[0][0]
    e = c[0][i] - c[0][0]
    for j in range(1, 3):
        if d != c[i][j] - c[0][j]:
            print("No")
            exit()
        if e != c[j][i] - c[j][0]:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 9220
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<stack>
#include<set>
#include<map>
#include<vector> 
#define ll long long
#define ms(x, n) memset(x,n,sizeof(x));
#define maxn 2010
#define mod 1000000007
using namespace std;
int a[maxn];
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	ll ans=0,x,y;
	for(int i=1;i<=n;i++){
		x=0,y=0;
		for(int j=1;j<i;j++){
			if(a[i]<a[j]) x++,y++;
		}
		for(int j=i+1;j<=n;j++){
			if(a[i]<a[j]) y++;
		}
		ans+=x*k%mod+((k-1)*k/2%mod)*y%mod;
		ans%=mod;
	}
	printf("%lld\n",ans);
    return 0;
}

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

using namespace std;

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int k = n / 2;
	if (n % 2 == 0 && s.substr(0, k) == s.substr(k, n)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3604
#include <cstdio>
#include <vector>

int main(){
    int n;
    std::scanf("%d", &n);
    std::vector<int> a(n, 0);
    std::vector<int> b(n, 0);
    int maxval = 0;
    for(int i = 0; i < n; ++i){
        std::scanf("%d", &a[i]);
        maxval = std::max(maxval, a[i]);
    }
    std::vector<int> c(maxval, 0);
    for(int i = 0; i < n; ++i){
        c[a[i]]++;
    }
    for(int i = 1; i <= maxval; ++i){
        c[i] += c[i - 1];
    }
    for(int i = n - 1; i >= 0; --i){
        b[c[a[i]] - 1] = a[i];
        c[a[i]]--;
    }
    std::printf("%d", b[0]);
    for(int i = 1; i < n; ++i){
        std::printf(" %d", b[i]);
    }
    std::printf("\n");
}


Measured memory_bytes: 17956
k, n = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
d_list = [a_list[i + 1] - a_list[i] for i in range(len(a_list) - 1)]
d_list.append(k + a_list[0] - a_list[-1])
sorted_d_list = sorted(d_list)
print(sum(sorted_d_list[:-1]))

Measured memory_bytes: 26060
#include<bits/stdc++.h>
using namespace std ;
 
int main() {
    int N;
    cin>>N;
    vector<int> V(N);
    vector<int> C(N);
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    for(int i=0;i<N;i++){
        cin>>C[i];
    }
    int res=0;
    for(int i=0;i<N;i++){
        int tem=V[i]-C[i];
        if(tem>0)
            res+=tem;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define sll stack<ll>
#define qll queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7 , MAX = 1e18;
ll dfs(vvll &adj,vll &dp,ll a)
{
    if(dp[a]!=-1) return dp[a];
    dp[a]=0;
    for(auto i: adj[a]) dp[a]=max(dp[a],dfs(adj,dp,i)+1);
    return dp[a];
}
int main() 
{
	fast_io;
	ll n,m,i,u,v,ans=0;
	cin>>n>>m;
	vll dp(n+1,-1);
	vvll adj(n+1);
	while(m--) cin>>u>>v , adj[u].pb(v);
	for(i=1;i<=n;i++) ans=max(ans,dfs(adj,dp,i));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9216
/*
 *	argorithms and data structures
 *	lectuire 5 
 *	The Number of Inversions
 */
#include <stdio.h>
#include <limits.h>

#define INFTY INT_MAX
#define N 200000

long long int count = 0;

void merge(int A[], int left, int mid, int right){
	int i, j, k;
	int L[N], R[N];
	int L_elements = mid - left;
	int R_elements = right - mid;

	for(i=0; i<L_elements; i++)
		L[i] = A[left + i];
	L[i] = INFTY;

	for(i=0; i<R_elements; i++)
		R[i] = A[mid + i];
	R[i] = INFTY;


	i = j = k = 0;
	for(k=left; k<right; k++){
		if( L[i] <= R[j] )
			A[k] = L[i++];
		else{
			A[k] = R[j++];
			if(L[i] < INFTY) count += L_elements - i;
		}
	}
}	

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

int main(void){
	int A[N], n, i;

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

	mergeSort(A, 0, n);

	printf("%llu\n", count);

	return 0;
}

Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <string>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

using namespace std;

int main(void){
  int n;
  char c;
  while(cin>>n,n){
    vector<vector<int> > dp(n,vector<int>(n));
    string s;
    rep(i,n){
      cin>>s;
      rep(j,n){
        if(s[j]=='*')dp[i][j]=0;
        else if(i == 0 || j == 0)dp[i][j]=1;
        else dp[i][j] = 1e9;
      }
    }

    loop(i,1,n){
      loop(j,1,n){
        if(dp[i][j]==0)continue;
        dp[i][j] = min(min(dp[i][j-1],dp[i-1][j]),dp[i-1][j-1])+1;
      }
    }

    int ret = 0;
    rep(i,n){
      rep(j,n){
        ret = max(ret,dp[i][j]);
      }
    }
    cout<<ret<<endl;
  }
}

Measured memory_bytes: 5036
a = int(input())
ar = list(input())
wc = 0
ec = ar.count("E")
br = []
for i in range(a):
    if ar[i] == "E":
        ec -= 1
    br.append(ec + wc)
    if ar[i] == "W":
        wc += 1
print(min(br))

Measured memory_bytes: 17540
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll A,B,C;
	cin>>A>>B>>C;
	FDS(i,10){
		cout<<C*A-B<<endl;
		C=C*A-B;
	}
}

Measured memory_bytes: 256
from itertools import product

N, M = map(int, input().split())

ks = [[int(i) for i in input().split()] for _ in range(M)]
p = [int(i) for i in input().split()]

res = 0

for i in product(range(2), repeat=N) :
    flag = True
    for j in range(M) :
        tmp = 0
        for s in ks[j][1:] :
            tmp += i[s-1]
        
        if tmp % 2 != p[j] :
            flag = False
            break
    if flag :
        res += 1

print(res)

Measured memory_bytes: 40176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
using graph = vector<vector<int>>;

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vector<int> a(n+1);
	rep(i,n) cin >> a.at(i+1);
	int tmp = a.at(1);
	for(int i = k+1; i <= n; i++){
		int nw = a.at(i);
		if(nw > tmp) cout << "Yes" << endl;
		else cout << "No" << endl;
		tmp = a.at(i-k+1);
	}
} 

Measured memory_bytes: 3988
#include<stdio.h>

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

int main()
{
    int n,a,max1=0,max2=0,max_idx;
    
    scanf("%d",&n);
    
    rep(i,n)
    {
        scanf("%d",&a);
        
        if(a > max1)
        {
            max2 = max1;
            max1 = a;
            max_idx = i;
        }
        else if(a > max2)
        {
            max2 = a;
        }
    }
    
    rep(i,n)
    {
        if(i == max_idx)
        {
            printf("%d\n",max2);
        }
        else
        {
            printf("%d\n",max1);
        }
    }
    
    return 0;
}


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

using namespace std;


// coins[i][j] : i枚目のコインまでで表j枚出る確率
// 答えは coins[N][N/2 + 1] ~ coins[N][N]までの和

vector<vector<double>> coins(3030, vector<double>(3030, 0));

int main(void){
    int n;
    cin >> n;
    
    vector<double> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    
    // 0枚目のコインで表が０枚出る確率は1.0である
    
    coins[0][0] = 1.0;
    
    // 次のコインが表のとき coins[i+1][j+1] += coins[i][j] * p
    // 次のコインが裏のとき coins[i+1][j] += coins[i][j] * (1-p)
    
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= i; j++){
            
            coins[i+1][j+1] += coins[i][j] * p[i]; // 次のコインが表のとき
            coins[i+1][j] += coins[i][j] * (1-p[i]); // 次のコインが裏のとき
        }
    }
    
    double ans = 0.0;
    
    for (int i = n/2 + 1; i <= n; i++){
        ans += coins[n][i];
    }
    
    cout << fixed << setprecision(15);
    cout << ans << endl;
}


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

ll pc(int n){
   if(n<=1) return 0;
   return (ll)n*(n-1)/2;
}

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

   map<int, int> cnt;
   rep(i, n){
      cnt[a[i]]++;
   }
   ll tot=0;
   repit(it, cnt){
      tot+=pc(it->second);
   }

   rep(k, n){
      int c=cnt[a[k]];
      ll ans=tot -pc(c) +pc(c-1);
      cout<<ans<<endl;
   }

   return 0;
}


Measured memory_bytes: 10092
#include <stdio.h>
#include <string.h>
#include <ctype.h>

void prnit(char str[], int a, int b)
{
    for (int i = a; i <= b; i++) {
        printf("%c", str[i]);
    }
    printf("\n");
}

void reverse(char str[], int a, int b)
{
    for (int i = 0; i < ((b - a + 1) / 2); i++) {
        char ch = str[a + i];
        str[a + i] = str[b - i];
        str[b - i] = ch;
    }
}

void replace(char str[], int a, int b, char p[])
{
    for (int i = 0; i < ((b - a) + 1); i++) {
        str[a + i] = p[i];
    }   
}


int main(int argc, char *argv[])
{
    int q;
    char str[1001];
    char op[20];
    int a, b;
    char p[1001];

    scanf("%s", str);
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%s", op);
        scanf("%d", &a);
        scanf("%d", &b);
        if (strcmp(op, "replace") == 0) {
            scanf("%s", p);
            replace(str, a, b, p);
        }
        if (strcmp(op, "print") == 0) {
            prnit(str, a, b);
        }
        if (strcmp(op, "reverse") == 0) {
            reverse(str, a, b);
        }
    }

    return 0;
}



Measured memory_bytes: 2100
N = int(input())
S = input()


ans = 0

cand = sorted(set(S), key=S.index)

for i in cand:
  index = S.find(i)
  newS = S[index+1:]

  newcand = sorted(set(newS), key=newS.index)

  for j in newcand:
    newindex = newS.find(j)
    newnewS = newS[newindex+1:]

    newnewcand = sorted(set(newnewS), key=newnewS.index)


    ans += len(newnewcand)

print(ans)

Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
N = int(input())
Ds = list(map(int, input().split()))
if em: sys.stdin = open('/dev/tty')
sum = 0
for i in range(len(Ds)):
  for j in range(i + 1, len(Ds)):
    sum += Ds[i] * Ds[j]
print(sum)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<set>
using namespace std;
#define rep(i,n) for(int i =0;i < n;i++)
int main() {
    string s, t;int n;set<string> ss;
    cin >> n >> s;ss.insert(s);
    for (int i = 1; i < n;i++) {
        cin >> t;int si = ss.size();
        ss.insert(t);
        if (ss.size() == si || t[0] != s[s.size() - 1]) {
            cout << "No" << endl;
            return 0;
        }
        s = t;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

// ceil of a/b
inline int ceildiv(int a, int b) { return (a+b-1)/b; }

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	int sum=0;
	rep(i,n) sum+=a[i];
	constexpr int N = 2e3;
	std::bitset<N*N+1> set;
	set[0]=1;
	rep(i,n) set|=set<<a[i];
	int x=ceildiv(sum,2);
	int j=0;
	for(int i=x;i<=N*N;i++) {
		if(!set[i]) continue;
		print(i);
		break;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   vector<double> v(n);
   for(int i=0;i<n;i++)cin >> v[i];
   sort(v.begin(),v.end());
   double ans = v[0];
   for(int i=1;i<n;i++){
       ans = (ans+v[i])/2;
   }
   cout << ans << endl;
}

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

int main(){
	int N;
	cin>>N;
	vector<vector<int>>table(N);
	vector<vector<int>>dp(N, vector<int>(3, INT_MIN));

	for(int i = 0; i < N; ++i){
		for(int j = 0; j < 3; ++j){
			int val;
			cin>>val;
			table[i].push_back(val);
		}
	}

	for(int i = 0; i < 3; ++i)
		dp[0][i] = table[0][i];

	for(int i = 0; i < table.size()-1; ++i){

		for(int j = 0; j < 3; ++j){		
			for(int k = 0; k < 3; ++k){
				if(j != k){
					dp[i+1][k] = max(dp[i+1][k], dp[i][j] + table[i+1][k]);
				}
			}

		}
	}
	int res = INT_MIN;
	for(int i = 0; i < 3; ++i){
		res = max(res, dp[N-1][i]);
	}
	cout<<res<<endl;
}



Measured memory_bytes: 14260
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    long long a, b, c, k;

    cin >> a >> b >> c >> k;

    if(k % 2 == 0){
        cout << a - b;
    }
    else{
        cout << b - a;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const ll INF = 1LL << 60;
const int MOD = 998244353;

int main() {
    ll N; cin >> N;
    vector<ll> D(N), vec(N);
    for(int i = 0; i < N; ++i){
        cin >> D[i];
        ++vec[D[i]];
    }
  
    if(D[0] != 0){
        cout << 0 << endl;
        return 0;
    }


    ll ans = 1;
    if(vec[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    for(ll i = 1; i < N; ++i){
        for(int j = 0; j < vec[i]; ++j){
            ans *= vec[i-1];
            ans %= MOD;
        }
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;
vl v,a;
ll dp[4000][4000];
ll sg(ll l,ll r){
    if(dp[l][r]!=0)return dp[l][r];
    if(l==r)return v[l];
    if(l==r-1)return max(v[l],v[r]);
    return dp[l][r]=max(v[l]+a[r+1]-a[l+1]-sg(l+1,r),v[r]+a[r]-a[l]-sg(l,r-1));
}

int main() {
    IOS;
    cin>>n;v.resize(n);cin>>v;
    a.assign(n+1,0);
    fo(i,n)a[i+1]=a[i]+v[i];
    cout<<2*sg(0,n-1)-a[n];
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (i > n) break;
    for (int j = 1; j < n; j++) {
      if (i * j >= n) break;
      else ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 1e9;
int N, M;
vector<int> res;

vector<int> simu(const vector<vector<bool>> &A){
  vector<int> ret(N+1);
  for(int i = 0; i < N+1; ++i) ret[i] = i;
  for(size_t j = 0; j < A[0].size(); ++j){
    for(size_t i = 0; i < ret.size(); ++i){
      if(A[i][j]) swap(ret[i],ret[i+1]);
    }
  }
  return ret;
}

int dfs(vector<int> &A, vector<int> &H, vector<vector<bool>> &B, int idx){
  int ret = INF;
  if(idx == A.size()){
    vector<int> s = simu(B);
    if(s == res) return *max_element(H.begin(),H.end());
    else return INF;
  }
  int a = A[idx];
  for(int i = H[a]+1; i < M; ++i){
    if(B[a+1][i] or B[a-1][i] or B[a][i]) continue;
    B[a][i] = true;
    int h = H[a];
    H[a] = i;
    ret = min(ret,dfs(A,H,B,idx+1));
    H[a] = h;
    B[a][i] = false;
  }
  return ret;
}

int main(){
  cin >> N >> M;
  vector<int> A(M);
  vector<vector<bool>> B(N+1,vector<bool>(M,false));
  for(int i = 0; i < M; ++i){
    cin >> A[i];
    B[A[i]][i] = true;
  }
  res = simu(B);
  vector<vector<bool>> B_(N+1,vector<bool>(M,false));
  vector<int> H(N,-1);
  cout << dfs(A,H,B_,0)+1 << endl;
}



Measured memory_bytes: 3120
// import kotlin.comparisons.*
// import kotlin.math.*
import java.util.*

const val mod = 1000000007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  readLine()
  val a = readIs().all { it % 2 == 1 || it % 3 == 0 || it % 5 == 0 }
  println(if (a) "APPROVED" else "DENIED")
}


Measured memory_bytes: 38308
#include <bits/stdc++.h>
#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)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i, a)cin >> p[i];
    rep(i, b)cin >> q[i];
    rep(i, c)cin >> r[i];
    sort(rall(p));
    sort(rall(q));
    sort(rall(r));
    rep(i, a-x)p.pop_back();
    rep(i, b-y)q.pop_back();
    reverse(all(p));
    reverse(all(q));
    ll ans, sum = 0, nowp = 0, nowq = 0;
    ans = accumulate(all(p), 0LL)+accumulate(all(q), 0LL);
    rep(i, c){
        ll now = inf;
        if(nowp < x && nowq < y){
            if(p[nowp] < q[nowq]){
                now = p[nowp];
                nowp++;
            }
            else{
                now = q[nowq];
                nowq++;
            }
        }
        else if(nowp < x){
            now = p[nowp];
            nowp++;
        }
        else if(nowq < y){
            now = q[nowq];
            nowq++;
        }
        else break;

        if(now < r[i]){
            ans -= now;
            ans += r[i];
        }
    }
    cout << ans << endl;
}      

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


vector<int> score;
Graph g;

void dfs(int v, int parent) {
    for (auto u: g[v]) {
        if (u == parent) continue;
        score[u] += score[v];
        dfs(u, v);
    }
}


int main() {
    int n, q; cin >> n >> q;
    score.assign(n, 0);
    g.assign(n, {});

    rep(i, n-1) {
        int a, b; cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        --p;
        score[p] += x;
    }
    dfs(0, -1);
    for (auto s: score) cout << s  << " ";
    cout << endl;
}

Measured memory_bytes: 23552
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//n ~ mの和
ll sigma(ll n, ll m)
{
  return ((n + m) * (m - n + 1) * 0.5);
}

void Main()
{
  vs flag = {"dream", "dreamer", "erase", "eraser"};
  rep(i, flag.size()) reverse(all(flag[i]));
  str s; cin >> s; reverse(all(s));
  for(ll i = 0;i < s.size();i++)
  {
    if(s.substr(i, 5) == flag[0]) i += 4;
    else if(s.substr(i, 7) == flag[1]) i += 6;
    else if(s.substr(i, 5) == flag[2]) i += 4;
    else if(s.substr(i, 6) == flag[3]) i+= 5;
    else fin("NO"); 
  }
  fin("YES");
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 512
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e3 + 6, M = 1e9 + 7;
ll a[N], b[N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, h;
    cin >> h >> n;
    for (ll i = 0; i < n; i++)
        cin >> a[i] >> b[i];
    vector<ll> dp(h + 1, M);
    dp[0] = 0;
    for (ll i = 0; i <= h; i++)
        for (ll j = 0; j < n; j++)
            dp[i] = min(dp[max(0L, i - a[j])] + b[j], dp[i]);
    cout << dp[h];
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int a,b,res;
	scanf("%d%d",&a,&b);
	if(a>=0&&a<=23&&b>=0&&b<=23)
	{
	res=a+b;
	if(a+b<=23)
		printf("%d\n",res);
	else
		printf("%d\n",res-24);
	}
	return 0;
}

Measured memory_bytes: 128
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int w[maxn];
int v[maxn];
ll dp[maxn];

int main(){
        _ios;

        int n,weight; cin >> n >> weight;
        for(int i = 0; i<n; i++){
            cin >> w[i] >> v[i];
        }
        for(int i = 0; i<n; i++){
            for(int j = weight; j>=0;j--){
                if(j+w[i]<=weight){
                    dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
                }
            }
        }

        ll res = 0;
        for(int i = 0; i<=weight; i++){
            res = max(dp[i], res);
        }
        cout<<res<<endl;

return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <stdint.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pi 3.1415926535897932
#define nui 100
using namespace std;

int main()
{

       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll n;
	cin >> n;
	ll a[n];
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	if (n == 1)
	{
		cout << a[0] << "\n";
	}
	else
	{
		ld sum = 0;
		for (ll i = 0; i < n; i++)
		{
			sum += float(1) / float(a[i]);
		}
		ld res = float(float(1) / float(sum));
		cout << fixed << setprecision(4) << res << "\n";
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    int C[N-1],S[N-1],F[N-1];
    rep(i,N-1){
        cin>>C[i]>>S[i]>>F[i];
    }
    rep(i,N-1){
        int t=S[i];
        int x=i;
        while(x<N-1){
                int w=max(0LL,(t-S[x]+F[x]-1)/F[x]);
                t=S[x]+F[x]*w;
                t+=C[x];
                x++;
        }
        cout << t << endl;
    }
    cout << 0 << endl;



}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int A, B; cin >> A >> B;
    string S; cin >> S;
    rep(i, A) {
        if (S.at(i) == '-') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (S.at(A) != '-') {
        cout << "No" << endl;
        return 0;
    }
    rep(i, B) {
        if (S.at(A + 1 + i) == '-') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define N 13

void print_missing_card(const vector<bool> &cards, char suit){
    for(int i = 0; i < N; i++){
        if(!cards[i]){
            printf("%c %d\n", suit, i + 1);
        }
    }
}

int main(void){
    int n = 0;
    string input;
    unordered_map<char, vector<bool>> cards;
    
    for(int i = 0; i < N; i++){
        cards['S'].push_back(false);
        cards['H'].push_back(false);
        cards['C'].push_back(false);
        cards['D'].push_back(false);
    }
    
    getline(cin, input);
    sscanf(input.c_str(), "%d\n", &n);
    
    for(int i = 0; i < n; i++){
        getline(cin, input);
        
        char suit = '\0';
        int num;
        
        sscanf(input.c_str(), "%c %d\n", &suit, &num);
        
        cards[suit][num - 1] = true;
    }
    print_missing_card(cards['S'], 'S');
    print_missing_card(cards['H'], 'H');
    print_missing_card(cards['C'], 'C');
    print_missing_card(cards['D'], 'D');
    
    return(0);
}



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

int main() {
    int inf = 1e5;
    int N, M;
    cin>>N>>M;
    int a, b, c;
    int map[N][N], map1[N][N];
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            if(i==j){
                map[i][j] = 0;
                map1[i][j] = 0;
            }
            else{
                map[i][j] = inf;
                map1[i][j] = inf;
            }
        }
    }
    for(int i=0;i<M;++i){
        cin>>a>>b>>c;
        a--;
        b--;
        map[a][b] = c;
        map[b][a] = c;
        map1[a][b] = c;
        map1[b][a] = c;
    }
    int ans = 0;
    for(int k=0;k<N;++k){
        for(int i=0;i<N;++i){
            for(int j=0;j<N;++j){
                if(map[i][j] > map[i][k] + map[k][j]){
                    if(map1[i][j]!=inf & map[i][j]==map1[i][j]){
                        ans++;
                    }
                    map[i][j] = map[i][k] + map[k][j];
                }
            }
        }
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 384