akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <map>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  int N;
  while (scanf("%d", &N) != EOF) {
    vector<int> v(N);
    map<int, int> mp;
    for (int i : range(N)) {
      scanf("%d", &v[i]);
      mp[v[i]] = -1;
    }
    int cnt = 1;
    for (auto& it : mp) {
      it.second = cnt++;
    }
    for (int i : range(N)) {
      v[i] = mp[v[i]];
      assert(v[i] >= 1);
    }

    int res = 0;
    for (int i : range(N)) {
      if (i % 2 == 0 && v[i] % 2 == 0) res++;
    }
    printf("%d\n", res);
  }
}


Measured memory_bytes: 5376
n, k = [int(x) for x in input().split()]
p = [1/2 + int(x)/2 for x in input().split()]
sum_p =[]
buf = 0
for i in p:
    buf += i
    sum_p.append(buf)
max_t = 0
for i in range(n - k + 1):
    buf = sum_p[i+k-1]
    if i > 0:
        buf -= sum_p[i-1]
    if max_t < buf:
        max_t = buf
print(max_t)

Measured memory_bytes: 23588
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  if(s=="Rainy"){
    cout<<"Sunny"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a,const void* b);

int main(void)
{
    int n=0,flag=1;
    long int array[200000]={};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%ld",&array[i]);
    }
    qsort(array,n,sizeof(long int),compare);
    for(int i=0;i<n-1;i++){
        if(array[i]==array[i+1]){
            flag=0;
            break;
        }
    }
    if(flag==1){
        printf("YES");
    } else {
        printf("NO");
    }
    return 0;
}

int compare(const void* a,const void* b){
    long *A=(long*)a;
    long *B=(long*)b;
    if(*A-*B<0) return -1;
    if(*A-*B>0) return 1;
    return 0;
}


Measured memory_bytes: 4624
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 200000
string Last,Now;
char str[MAXN+5];

int main(){
    scanf("%s",str+1);
    int Ans=0,N=strlen(str+1),flag=0;
    for(int i=1;i<=N;i++){
        Now+=str[i];
        if(Now!=Last){
            Last=Now;
            Now="";
            Ans++;
        }
    }
    printf("%d",Ans);
}


Measured memory_bytes: 384
using System;
using System.Linq;

namespace _177_a
{
    internal class DontBeLate
    {
        private static void Main(string[] args)
        {
            var dts = Console.ReadLine()?.Split(' ').Select(int.Parse).ToArray();
            if (dts == null) return;

            var d = dts[0];
            var t = dts[1];
            var s = dts[2];

            Console.WriteLine(d <= t * s ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 28272
# abc144
def test(a):
    return 1 <= a and a <= 9
def sol(a,b):
    if test(a) and test(b):
        return a*b
    else :
        return -1
# in your code
read = input 
rn = lambda :list(map(int, read().split()))
def reverse_range(r):return range(r-1, -1, -1)
a,b = rn()
print(sol(a,b))

Measured memory_bytes: 3064
import sys
import numpy as np
input = sys.stdin.readline

MOD=10**9+7
N, K = map(int, input().split())
grid = np.empty((0,N), dtype='O')
for i in range(N):
  array = list(map(int, input().strip().split()))
  array2 = np.array(array)
  grid = np.append(grid,[array2],axis=0)
#print(grid)
dp=[[grid]]
gridsave=np.eye(N,dtype="O")
#print(gridsave)
i=1
while K:
  if K & 1:
    gridsave=np.dot(grid,gridsave) % MOD
  grid=np.dot(grid,grid) % MOD
  K>>=1
ans=np.sum(gridsave)%MOD
#print(gridsave)
print(ans)

Measured memory_bytes: 14508
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define int long long
#define INF 1<<40
#define N 100
using namespace std;
signed main() {
	string s, t; cin >> s >> t;
	int a, b; cin >> a >> b;
	string u; cin >> u;
	if (s == u) a--;
	else b--;
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N,D;
	cin >> N >> D;
	cout << (N+2*D)/(2*D+1) << endl;
}

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






int main() {
  int N;
  cin>>N;
  int max=0;
  int count =0;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    if(max<=x){
      count++;
      max=x;
    }
  }
  cout<<count<<endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int>pref(n+1);

    
    for(int i = 0;i<n-1;i++){
        if(s[i] == 'A' && s[i+1] == 'C')pref[i+2] = pref[i+1] + 1;
        else pref[i+2] = pref[i+1];
    }
    for(int i = 0;i<q;i++){
        int l,r;
        cin >> l >> r;
        cout << pref[r] - pref[l] << '\n';
    }
    return 0;
}


Measured memory_bytes: 1408
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=200005;
int a[N],n,m;
bool check(int mid)
{
	int rest=(n-mid)<<1;
	for(int i=0;i<rest;++i) if(a[i+(mid<<1)]+a[(n<<1)-i-1]<m) return false;
	return true;
}
int main()
{
	read(n,m);
	for(int i=0;i<n<<1;++i) read(a[i]);
	std::sort(a,a+(n<<1));
	int l=0,r=n;
	while(l<r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	int ans=0;
	for(int i=0;i<l<<1;++i) chmax(ans,a[i]+a[(l<<1)-i-1]);
	int rest=(n-l)<<1;
	for(int i=0;i<rest;++i) chmax(ans,a[i+(l<<1)]+a[(n<<1)-i-1]-m);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4452
#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;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#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
//priority_queue<int,vector<int>, greater<int> > q2;

int A[110];
int N, K; 
int dp[100010][2];
//残り石がiで手番がjの時に勝つ人

int f(int K, int a) {

	if (dp[K][a] != -1)return dp[K][a];

	if (K == 0)return dp[K][a] = a ^ 1;

	REP(i, N) {
		if (K - A[i] < 0)break;
		if (f(K - A[i], a ^ 1) == a)return dp[K][a] = a;
	}
	return dp[K][a] = a ^ 1;
}

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

	cin >> N >> K;
	eREP(i, K)dp[i][0] = dp[i][1] = -1;
	REP(i, N)cin >> A[i];
	if (f(K, 0) == 0)cout << "First" << endl;
	else cout << "Second" << endl;

	return 0;
}



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

int main(){
    int V, E;
    cin >> V >> E;
    vector<vector<int> > edge(10001);
    vector<int> state(V, 0);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        edge[s].push_back(t);
        state[t]++;
    }
    vector<int> ans;
    for (int i = 0; i < V; i++) {
        if (state[i] == 0) ans.push_back(i);
    }
    for (int i = 0, s = ans.size(); i < s; i++) {
        int a = ans[i];
        for (int j = 0, ss = edge[a].size(); j < ss; j++) {
            int t = edge[a][j];
            state[t]--;
            if (state[t] == 0) {
                ans.push_back(t);
                s++;
            }
        }
        cout << a << endl;
    }

    return 0;
}



Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int a, b;
  cin >> a >> b;
  b--;

  int ans = 0;
  while (b > 0) {
    ans++;
    b -= a-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	priority_queue<long double>pq;
	for(int i=0;i<n;i++){
		long double a;
		cin>>a;
		pq.push((-1)*a);
	}
	while(pq.size()!=1){
		long double a=pq.top();
		pq.pop();
		long double b=pq.top();
		pq.pop();
		long double c=(a+b)/(long double)2;
		pq.push(c);
	}
	long double ans=pq.top();
	cout<<abs(ans)<<endl;
}

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


int main() {
  int X, Y;
  cin >> X >> Y;
  for (int c = 0; c <= X; ++c) {
    int t = X - c;
    int asi = c * 2 + t * 4;
    if (asi == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {

	char S[4], T[4];
	scanf("%s%s", &S, &T);
	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) {
			count++;
		}
	}
	printf("%d", count);



	return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
using namespace std;
const int N=2e5+5;
int n,val[N],divp[N],divn[N];
lint pval[N];

namespace utils{
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

inline lint diffv(int s1,int s2,int s3){
	lint v1=pval[s2]-pval[s1-1];
	lint v2=pval[s3]-pval[s2];
	return v1<v2?v2-v1:v1-v2;
}

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
		pval[i]=val[i]+pval[i-1];
	}
	divp[2]=1;
	for(int i=3; i<n; ++i){
		divp[i]=divp[i-1];
		while(diffv(1,divp[i],i)>diffv(1,divp[i]+1,i)){
			++divp[i];
			assert(divp[i]<i);
		}
	}
	divn[n-2]=n-1;
	for(int i=n-3; i>1; --i){
		divn[i]=divn[i+1];
		while(diffv(i+1,divn[i],n)>diffv(i+1,divn[i]-1,n)){
			--divn[i];
			assert(divn[i]>i);
		}
	}
	lint ans=1e12;
	for(int i=2; i<n-1; ++i){
		lint v[4]={pval[divp[i]],pval[i]-pval[divp[i]],
			pval[divn[i]]-pval[i],pval[n]-pval[divn[i]]};
		sort(v,v+4);
		apn(ans,v[3]-v[0]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 7604
#include<stdio.h>
    int main(void){
    
    int x;
    int y;
    int w;
    
    while(1){
    scanf("%d %d",&x,&y);
        if(x==0&&y==0){
        break;
        }
        if(x>y){
        w=x;
        x=y;
        y=w;
        }
        printf("%d %d\n",x,y);
    }
    
    return 0;
    }


Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef pair<ll,ll> pii;
typedef vector<pi> vpi;
typedef set<ll> si;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define f first
#define s second
ll INF = 1e9;
ll MOD = 1e9+7;
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()

ll ans;
char c;
ll N,a,t,out;
vpi V;

int main(){
  // freopen("in.txt","r",stdin);
  cin >> N;
  cin >> ans;
  for (int i=1;i<N;++i){
    cin >> c >> a;
    if (SZ(V) == 0 && c == '+'){
      ans += a;
      continue;
    }
    ans += a;
    if (SZ(V) && V.back().f && c == '+'){
      V.back().s += a;
      continue;
    }
    V.pb(mp(c == '+', a));
  }
  if (SZ(V)) ans -= 2*V[0].s;
  if (SZ(V) < 2){
    cout<<ans;
    return 0;
  }
  if (V[1].f == 0){
    // If second one is negative
    cout << ans;
    return 0;
  }
  out = max(out, ans - 2*V[1].s);
  int T = SZ(V);
  V.pb(mp(0,0));
  for (int i=1; i<T; ++i){
    // cout<<i<<'\n';
    if (V[i].f == 1)continue;
    if (V[i+1].f == 0){
      // cout<<"Case A " << i << '\n';
      out = max(out, ans - 2 * V[i].s);
      break;
    }
    else{
      // cout<<"Case B " << i << '\n';
      out = max(out, ans - 2 * V[i].s - 2*V[i+1].s);
    }
    ans -= 2*V[i].s;
  }
  cout<<out;
}


Measured memory_bytes: 2420
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE StrictData #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

main = do
    (n,m) <- (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    as <- VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let ans = n - VU.sum as
    print $ if ans < 0 then -1 else ans

Measured memory_bytes: 5268
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  string a, b, c;
  cin >> a >> b >> c;
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]) co("YES");
  else co("NO");

  return 0;
}

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

using namespace std;

int main(int argc, char* argv[])
{
    int N, M; cin >> N >> M;

    vector<pair<long long, long long>> student, checkpoint;
    for (int i = 0; i < N; i++) {
        long long a, b; cin >> a >> b;
        student.push_back(make_pair(a, b));
    }

    for (int i = 0; i < M; i++) {
        long long c, d; cin >> c >> d;
        checkpoint.push_back(make_pair(c, d));
    }

    for (int i = 0; i < N; i++) {    
      unsigned long long distance = -1;
      int pos = -1;
      for (int j = 0; j < M; j++) {
	int cur = abs(student[i].first-checkpoint[j].first)+abs(student[i].second-checkpoint[j].second);
	if (cur < distance) {
	  distance = cur;
	  pos = j;
	}
      }
      cout << pos+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,a[200005];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int mx=a[1],ans=0;
	for(int i=2;i<=n;i++)
	{
		if(mx>a[i])
		{
			ans+=mx-a[i];
		}
		else
			mx=max(mx,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5180
n = map(int,input().split())
a = list(map(int,input().split()))
newa=[a[0]]
for i in range(1,len(a)):
    if a[i]!=a[i-1]:
        newa.append(a[i])
check=[]
for i in range(1,len(newa)):
    if newa[i]>newa[i-1]:
        check.append(i)
        
stock=0
money=1000
if len(check)>=1:
    kau1=min(newa[0:check[0]])#最初のやすい値段
    stock=money//kau1
    money=money%kau1
    money+=newa[check[0]]*stock
    
    

    for i in range(len(check)-1):
        kau=min(newa[check[i]:check[i+1]])
        stock=money//kau
        money=money%kau
        money+=newa[check[i+1]]*stock
    
print(money)

Measured memory_bytes: 62084
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int r,d,x;
	cin >> r >> d >> x;
  	rep(i, 10)
    	cout << (x=r*x -d)<< endl;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

const int64_t MOD = 1e9 + 7;

int64_t dpow(int64_t x, int64_t y) {
  if (y == 0) {
    return 1;
  }
  if (y % 2 == 0) {
    return dpow(x * x % MOD, y / 2);
  } else {
    return x * dpow(x, y - 1) % MOD;
  }
}

int64_t inv(int64_t x) { return dpow(x, MOD - 2); }

vector<int64_t> fact;

int64_t solve(const int64_t r, const int64_t c) {
  int64_t result =
      (fact[r + c + 2] * inv(fact[r + 1]) % MOD * inv(fact[c + 1]) % MOD - 1 +
       MOD) %
      MOD;
  return result;
}

int main() {
  int64_t r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  fact.resize(r2 + c2 + 3);
  irep(i, r2 + c2 + 2) {
    if (i == 0) {
      fact[i] = 1;
    } else {
      fact[i] = fact[i - 1] * i % MOD;
    }
  }

  int64_t result = (((solve(r2, c2) - solve(r2, c1 - 1) + MOD) % MOD -
                     solve(r1 - 1, c2) + MOD) %
                        MOD +
                    solve(r1 - 1, c1 - 1)) %
                   MOD;
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 15872
#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(){
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	rep(i,n) cin >> p[i];
	rep(i,n) cin >> q[i];
	vector<int> a(n);
	rep(i,n){
		a[i] = i+1;
	}
	int counts = 1;
	map<vector<int>, int> cnt;
	do{
		cnt[a] = counts;
		counts++;
	}while(next_permutation(a.begin(),a.end()));
	int ans = abs(cnt[p] - cnt[q]);
	cout << ans << endl;
}

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

typedef pair<int, int> P;

int n;

vector<int> dijkstra(int s, vector<vector<P>> &G){
    vector<int> dist(n, 1e9);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(!que.empty()){
        int ccost, cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[cv] < ccost) continue;

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;
            
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

int main(){
    cin>>n;
    vector<vector<P>> G(n);
    for(int i=0; i<n-1; i++){
        int s, t, w; cin>>s>>t>>w;
        G[s].emplace_back(t, w);
        G[t].emplace_back(s, w);
    }

    vector<int> dist1 = dijkstra(0, G);
    int v1 = max_element(dist1.begin(), dist1.end()) - dist1.begin();
    vector<int> dist2 = dijkstra(v1, G);
    int v2 = max_element(dist2.begin(), dist2.end()) - dist2.begin();
    vector<int> dist3 = dijkstra(v2, G);

    for(int i=0; i<n; i++){
        cout << max(dist2[i], dist3[i]) << endl;
    }
}


Measured memory_bytes: 3840
package main

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

func main() {
	var N int
	fmt.Scan(&N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, N)
	b := make([]int, N)
	c := make([]int, N)
	for i := 0; i < N; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	for i := 0; i < N; i++ {
		sc.Scan()
		b[i], _ = strconv.Atoi(sc.Text())
	}
	for i := 0; i < N; i++ {
		sc.Scan()
		c[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(sort.IntSlice(a))
	sort.Sort(sort.IntSlice(c))

	sum := 0
	for i := 0; i < N; i++ {
		ac := LowerBound(a, b[i])
		cc := N - UpperBound(c, b[i])
		sum += ac * cc
	}
	fmt.Println(sum)
}
func UpperBound(a []int, x int) int {
	return sort.Search(len(a), func(i int) bool { return a[i] > x })
}
func LowerBound(a []int, x int) int {
	return sort.Search(len(a), func(i int) bool { return a[i] >= x })
}


Measured memory_bytes: 6016
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    ArrayList<Integer> list = new ArrayList<Integer>();
    int s = sc.nextInt();
    list.add(s);
    int ans = 1;

    while (true) {
      ans++;
      int next = 0;
      if ((s % 2) == 1) {
        next = (3 * s) + 1;
      } else {
        next = s / 2;
      }
      if (list.contains(next)) {
        System.out.println(ans);
        return;
      } else {
        s = next;
        list.add(next);
      }
    }

  }
}

Measured memory_bytes: 35884
s=input()
alp="".join([chr(i) for i in range(97,97+26)])
if len(s)<26:
    for i in alp:
        if i not in s:
            print(s+i)
            exit()
else:
    if s=="".join([chr(i) for i in range(97,97+26)][::-1]):
        print(-1)
        exit()
    else:
        for i in range(24,-1,-1):
            for j in range(25,i,-1):
                if s[i]<s[j]:
                    print(s[:i]+s[j])
                    exit()


Measured memory_bytes: 3064
num = int(input())
W = list(map(int, input().split()))
res = -1

for i in range(0, num):
    S1 = sum(W[:i])
    S2 = sum(W[i:])
    if res == -1 or res > abs(S1-S2):
        res = abs(S1-S2)
    if res == 0:
        break
print(res)


Measured memory_bytes: 2940
#include <stdio.h>
#include <inttypes.h>

int N;
int B[128];

int main(void) {
	int i;
	int64_t horieyui = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 1; i <= N - 1; i++) {
		if (scanf("%d", &B[i]) != 1) return 1;
	}
	B[0] = 99999999;
	B[N] = 99999999;
	for (i = 1; i <= N; i++) {
		int tomatu = B[i - 1];
		if (B[i] < tomatu) tomatu = B[i];
		horieyui += tomatu;
	}
	printf("%" PRId64 "\n", horieyui);
	return 0;
}


Measured memory_bytes: 128
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! {
        s: Bytes,
        t: Bytes,
    }
    let slen = s.len();
    let ok = (t.len() == s.len()+1) && s[0..slen] == t[0..slen];

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



Measured memory_bytes: 2088
#include <iostream>
#include <vector>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

static const int N = 100;
static const int INFTY = (1 << 21);

int n, m[N][N];
int dist[N];

void bfs(int idx)
{
	for (int i = 0; i < n; ++i) dist[i] = INFTY;

	queue<int> q;
	q.push(idx);
	dist[idx] = 0;

	while (!q.empty())
	{
		int u = q.front(); q.pop();
		for (int v = 0; v < n; ++v)
		{
			if (m[u][v] == 0) continue;
			if (dist[v] != INFTY) continue;

			dist[v] = dist[u] + 1;
			q.push(v);
		}
	}
	for (int i = 0; i < n; ++i)
		cout << i + 1 << " " << ((dist[i] == INFTY) ? (-1) : dist[i]) << endl;
}

int main()
{
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			m[i][j] = 0;
		}
	}
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 0; j < d; ++j)
		{
			int v; cin >> v;
			m[u-1][v-1] = 1;
		}
	}

	bfs(0);

	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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 ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  cout << n * n - a << endl;

  return 0;
}


Measured memory_bytes: 3584
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
if n==1:
    print(0)
    exit()
elif n==2:
  print(0)
  exit()
m=math.ceil(n/((n-1)**0.5+1))
ans=0
for i in range(1,m):
    if n%i==0:
        ans+=(n//i-1)
print(ans)

Measured memory_bytes: 67040
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    ll d = gcd(a, b);
    return a / d * b;
}

int main() {
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    ll l = lcm(n, m);
    ll x = l / n, y = l / m;

    for (int i = 0; i < n; ++i) {
        if (i * x % y == 0) {
            if (s[i] != t[i * x / y]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    cout << l << endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
	int cut=0;
	int a;
	int b;
	while(1){
	cin>>a;
		cut=0;
		if(a==0){
			break;
		}
	b=1000-a;
	cut+=b/500;
	b=b%500;
	cut+=b/100;
	b=b%100;
	cut+=b/50;
	b=b%50;
	cut+=b/10;
	b=b%10;
	cut+=b/5;
	b=b%5;
	cut+=b;
	cout<<cut<<endl;
	}
	return 0;
}

Measured memory_bytes: 3024
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias P = Tuple!(int, "x", int, "y");

void main()
{
    auto N = readln.chomp.to!int;
    P[] RS, BS;
    foreach (_; 0..N) {
        auto ab = readln.split.to!(int[]);
        RS ~= P(ab[0], ab[1]);
    }
    foreach (_; 0..N) {
        auto cd = readln.split.to!(int[]);
        BS ~= P(cd[0], cd[1]);
    }
    sort!"a.x > b.x"(RS);
    sort!"a.y < b.y"(BS);
    auto rb = new bool[](N);
    int res;
    foreach (b; BS) {
        foreach (j, r; RS) {
            if (!rb[j] && r.x < b.x && r.y < b.y) {
                rb[j] = true;
                ++res;
                break;
            }
        }
    }
    writeln(res);
}

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

int N;

int main(){
cin >> N;
int C[N];
for(int i=0;i<N;i++) cin >> C[i];
int ans = 0,keep;

for(int i=0;i<N;i++){
	if((C[i-1] >= C[i]) && i) continue;
	keep = 0;
	for(int j=i;j<N-1;j++){
		if(C[j] < C[j+1]) break;
		keep++; 
	}
ans = max(ans,keep);
}

cout << ans << endl;
}



		


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;


ll N, A[MAXN], K;
vector<int> v;

bool vis[MAXN];
void f(int x) {
	vis[x] = 1;
	if(vis[A[x]]) {
		int cur = A[x];
		v.push_back(x);
		while(cur != x) {
			v.push_back(cur);
			cur = A[cur];
		}
		return;
	}
	K--;
	if(K == 0) {
		cout << A[x];
		exit(0);
	}
	f(A[x]);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	for(int i=1; i<=N; i++) cin >> A[i];
	f(1);
	cout << v[K % v.size()];
}

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

int main(){
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k)
    cout<<s<<endl;
  else{
    for(int i=0;i<k;i++)
      cout<<s.at(i);
  cout<<"..."<<endl;
  }
}


Measured memory_bytes: 3632
s = input()
s = s[::-1]
a = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(4):
    a[i] = a[i][::-1]

while len(s) > 0:
    #print(s)
    if s[:3] == 'rem' and s[:len(a[1])] == a[1]:
        s = s[len(a[1]):]
    elif s[:3] == 'res' and s[:len(a[3])] == a[3]:
        s = s[len(a[3]):]
    elif s[0] == 'e' and s[:len(a[2])] == a[2]:
        s = s[len(a[2]):]
    elif s[0] == 'm' and s[:len(a[0])] == a[0]:
        s = s[len(a[0]):]
    else:
        print("NO")
        raise SystemExit

print("YES")

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

int main() {
    int r,g,b;
    cin >>r >>g >> b;
    if((g*10 + b) % 4 == 0){
        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 < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
    
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    if (V <= W) cout << "NO" << endl;
    else if (V > W && abs(A-B) <= (V-W)*T) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

int main(){
  int N,X;
  cin >> N >> X;
  int L[N];
  int now = 0;
  int i = 0;
  for(int j = 0; j < N; j++){
    cin >> L[j];
  }
  while(now <= X){
    now += L[i];
    i++;
  }
  cout << i << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
   	int W, H, N;
    cin >> W >> H >> N;
  	int a[3];
  	int ans = 0;
  	int table[H][W] = {0};
    for(int i = 0; i < N; ++i){
      cin >> a[0];
      cin >> a[1];
      cin >> a[2];
      if(a[2] == 1){
        for(int j = 0; j < H; ++j){
          for(int k = 0; k < a[0]; ++k){
            table[j][k] = 1;
        	}
        }
      }
      
      else if(a[2] == 2){
        for(int j = 0; j < H; ++j){
          for(int k = a[0]; k < W; ++k){
            table[j][k] = 1;
        	}
        }
      }
      
      else if(a[2] == 3){
        for(int j = H - a[1]; j < H; ++j){
          for(int k = 0; k < W; ++k){
            table[j][k] = 1;
        	}
        }
      }
      
      else if(a[2] == 4){
        for(int j = 0; j < H - a[1]; ++j){
          for(int k = 0; k < W; ++k){
            table[j][k] = 1;
        	}
        }
      }
    }
  
  
  
  	for(int j = 0; j < H; ++j){
       for(int k = 0; k < W; ++k){
          if(table[j][k] == 0) ans++;
       }
    }
   
    cout << ans << endl;
}

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

const int INF = (1<<21);

int main(){
  int n,m=INF;
  while(cin >> n){
    for(int i=1;i<3;i++){
      int a;
      cin >> a;
      n = min(a,n);
    }
    for(int i=0;i<2;i++){
      int a;
      cin >> a;
      m = min(a,m);
    }
    cout << n + m -50 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn scan_split<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_split_with<T: std::str::FromStr>(ch: char) -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split(ch)
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_lines<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| scan::<T>()).collect()
}

#[allow(unused_macros)]
macro_rules! scan_as_tuple {
    ( $t:ty ) => {
        (scan::<$t>(),)
    };
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok();
            let v = s.trim().split_whitespace();
            let mut it = v;
            let ret = ( $(it.next().unwrap().parse::<$t>().ok().unwrap()),* );
            assert!(it.next() == None, "not all tokens consumed");
            ret
        }
    };
}

fn main() {
    let (s, t) = scan_as_tuple![String, String];
    println!("{}", if s == t { "H" } else { "D" });
}

Measured memory_bytes: 4352
n=int(input())
s=input()
words="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
add=[]
for i in s:
    add.append(words.index(i)+n)

ans=""
for i in add:
    ans +=words[i]
print(ans)

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

int main(){
 int X,Y;
  cin >> X >> Y;
  
  if(2*X<=Y&&Y<=4*X&&Y%2==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
  
}

  
    


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

int main(){
  
 int a,c,b;
  cin>>a>>c>>b;
  a=c*10+b;
    if(a%4==0){
cout<<"YES"<<endl;
  }
    else{
   cout<<"NO"<<endl;
    }
  }
 



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

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

	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max(max(a*c, b*d),max(a*d,b*c)) << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
void solve()
{
	static int dp[2001][2001] = {0};
	for (int c = 0; c <= 2000; c++)
		dp[c][0] = 1;
	for (int c = 0; c <= 2000; c++)
		for (int c1 = 1; c1 <= c; c1++)
		{
			dp[c][c1] = (dp[c - 1][c1] + dp[c - 1][c1 - 1]) % mod;
		}
	int S;
	cin >> S;
	ll res = 0;
	for (int c = 1; 3 * c <= S; c++)
	{
		(res += dp[S - 2 * c - 1][S - 3 * c]) %= mod;
	}
	cout << res << endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	for (int tt = 1; tt <= t; tt++)
	{

		solve();
	}
	return 0;
}

Measured memory_bytes: 17424
import java.util.Scanner;

public class Main {

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

        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        int count4 = 0;

        for (int i = 0; i < 6; i++) {
            int x = sc.nextInt();
            if (x == 1) count1++;
            if (x == 2) count2++;
            if (x == 3) count3++;
            if (x == 4) count4++;
        }

        if (count1 > 2 || count2 > 2 || count3 > 2 || count4 > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d) ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
#include "stdio.h"
#include "stdlib.h"
int n,m;
int map[15][15];
char str[100];
char dir[]={' ','U','D','R','L'};
int sx,sy;
int c;
int ans[100];
bool dfs(int x,int y,int step)
{
	if(step==c) return true;
	if(map[x][y]!=2)
	for(int i=x-1;i>=0;i--)
		if(!map[i][y])
		{
			ans[step]=1;
			map[i][y]=1;
			if(dfs(i,y,step+1))return true;
			map[i][y]=0;
			break;
		}
	if(map[x][y]!=1)
	for(int i=x+1;i<n;i++)
		if(!map[i][y])
		{
			ans[step]=2;
			map[i][y]=2;
			if(dfs(i,y,step+1))return true;
			map[i][y]=0;
			break;
		}
	if(map[x][y]!=4)
	for(int i=y+1;i<m;i++)
		if(!map[x][i])
		{
			ans[step]=3;
			map[x][i]=3;
			if(dfs(x,i,step+1))return true;
			map[x][i]=0;
			break;
		}
	if(map[x][y]!=3)
	for(int i=y-1;i>=0;i--)
		if(!map[x][i])
		{
			ans[step]=4;
			map[x][i]=4;
			if(dfs(x,i,step+1))return true;
			map[x][i]=0;
			break;
		}
		return false;
}
int main(int argc, char const *argv[])
{
	scanf("%d %d",&n,&m);
	c=0;
	for(int i=0;i<n;i++)
	{
		scanf("%s",str);
		for(int j=0;j<m;j++)
			if(str[j]=='.') map[i][j]=-1;
		else if(str[j]=='o') {map[i][j]=0;c++;}
		else{
			sx=i;
			sy=j;
			if(str[j]=='U')map[i][j]=1;
			else if(str[j]=='D')map[i][j]=2;
			else if(str[j]=='R')map[i][j]=3;
			else if(str[j]=='L')map[i][j]=4;
		}
	}
	//while(1){}
	dfs(sx,sy,0);
	for(int i=0;i<c;i++)
		printf("%c",dir[ans[i]]);
	printf("\n");
	return 0;
}

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

const int N = 100010; 
int n, sz[N]; string s; 
int main() {
    cin >> s; 
    n = s.length();
    string s1 = s.substr(0, n-1); 
    if (!count(s1.begin(), s1.end(), '1')) return puts("-1"), 0;
    string t = s1; reverse(t.begin(), t.end());
    if (t != s1) return puts("-1"), 0;
    if (s[n - 1] == '1' || s[0] == '0') return puts("-1"), 0;

    vector <int> pos; 
    for (int i = 0; i < n; i++) if (s[i] == '1')
        pos.push_back(i + 1);

    int ps = pos.size() + 2;
    int nowadd = 1;

    for (int i = 0; i < n; i++) if (s[i] == '1') {
        sz[nowadd] = sz[nowadd - 1] + 1;

        while (sz[nowadd] < i + 1) sz[nowadd]++, cout << nowadd << " " << (ps++) << endl;
        cout << nowadd << " " << nowadd + 1 << endl;
        ++nowadd;  
    }


    return 0; 
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1e9 + 7;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    ll m = max({a, b, c});
    int left = a + b + c - m;
    for (int i = 0; i < k; ++i) {
        m <<= 1;
    }
    cout << m + left << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 384
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int x,y;cin>>x>>y;
	int a1=x+y;
	int a2=x*y;
	int a3=x-y;
	cout<<max(a1,max(a2,a3));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <unordered_map>
using namespace std;

int main(){
    int n, m, d;
    double ans;
    int count = 0;
    cin >> n >> m >> d;
    
    if(d == 0){
        count += n;
    }else{
        count += (n-d)*2;
    }
    
    
    ans = (double)(m-1) * count / n / n;
    
    printf("%.10lf", ans);
}


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int c[3][3] = {0};

  rep(i,3)
  rep(j,3)
  {
    cin >> c[i][j];
  }

bool g;
rep(i,c[0][0] + 1)
rep(j,c[1][1] + 1)
rep(k,c[2][2] + 1)
{
  // cout << "yes";
  int a[3];
  int b[3];
  a[0] = i;
  a[1] = j;
  a[2] = k;
  b[0] = c[0][0] - i;
  b[1] = c[1][1] - j;
  b[2] = c[2][2] - k;
  
  g = true;
  rep(p,3)
  rep(q,3)
  {
    if(c[p][q] != a[p] + b[q])
    {
      g = false;
    }
  }

  if(g) 
  {
    goto LBL;
  }
}

LBL:
  if(g) cout << "Yes";
  else cout << "No";

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)

line = []
buf = []

H.times do |i|
  if i.even?
    line << gets.split.map(&:to_i)
  else
    line << gets.split.map(&:to_i).reverse
  end
end

line.flatten!

(line.size-1).times do |i|
  if line[i].odd?
    line[i+1] += 1
    x1, y1 = i % W, i / W
    x2, y2 = (i+1) % W, (i+1) / W
    x1 = (W-1) - x1 if y1.odd?
    x2 = (W-1) - x2 if y2.odd?
    buf << "#{y1+1} #{x1+1} #{y2+1} #{x2+1}"
  end
end

puts buf.size
buf.each do |l|
  puts l
end

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

int main() {
    int p, q;
    cin >> p >> q;

    int g = q / __gcd(p, q);
    set<int> s;
    for (int i = 1; i <= sqrt(g); i++) {
        if (g % i == 0) {
            s.insert(i);
            s.insert(g / i);
        }
    }
    int ans = 1;
    for (auto i : s) {
        bool flag = true;
        for (int j = 2; flag && j <= sqrt(i); j++) {
            if (i % j == 0) flag = false;
        }

        if (flag) ans *= i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3108
//abc069_a.cpp
//Sun Sep 30 15:54:26 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	cout << (n-1)*(m-1)<< endl;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{

	int n,q;
	cin>>n>>q;
	vector<stack<int>> st(n);

	while(q--){
		int i;
		cin>>i;
		if(i==0){
			int t,x;
			cin>>t>>x;
			st[t].push(x);
		}else if(i==1){
			int t;
			cin>>t;
			if(st[t].size()!=0)cout<<st[t].top()<<endl;
		}else{
			int t;
			cin>>t;
			if(!st[t].empty())st[t].pop();
		}
	}
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    long long n,h,w;cin>>n>>h>>w;
    int ans=0;

    rep(i,n){
        long long a,b;cin>>a>>b;
        if(a>=h&&b>=w){
            ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256