akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a,ll b,ll mod)
{
    ll c=1;
    while(b>=2)
    {
        if(b%2==0)
            a*=a,b/=2;
        else
            c*=a,a*=a,b--,b/=2;
        a%=mod,c%=mod;
    }
    return (a*c)%mod;
}
bool cmp(ll a,ll b) {return a>b;}
int main()
{
    ll k,n;
    while(cin>>k>>n)
    {
        vector <ll> s,dis;
        ll num;
        for(int i=0;i<n;i++)
        {
            cin>>num;
            s.push_back(num);
        }
        sort(s.begin(),s.end());
        for(int i=1;i<n;i++)
        {
            num=s[i]-s[i-1];
            dis.push_back(num);
        }
        dis.push_back(k-s[n-1]+s[0]);
        ll aa=*max_element(dis.begin(),dis.end());
        cout<<k-aa<<endl;
    }
    return 0;
}


Measured memory_bytes: 4848
#include <iostream>

using namespace std;

int main()
{
  int N, K;

  cin >> N >> K;
  for (int i = 0, buf; i < N; i++) cin >> buf;

  int ans = int(((N - 1) - 1) / (K - 1)) + 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
l,r = map(int, input().split())

if r-l >= 2019:
  print(0)
  exit()

ans = float('inf')
for i in range(l, r):
  for j in range(i+1, r+1):
  	t = i*j%2019
  	if t < ans: ans = t
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#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)-1); i>0; i--)
#define ALL(x) (X).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }

int main() {
  int N; cin >> N;
  string s, t; cin >> s;
  char c = s[0];
  int cnt = 0;
  rep (i, N) {
    if (c != s[i]) cnt ++;
    c = s[i];
  }
  cnt++;
  cout << cnt << endl;
  return 0;
}


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

typedef long long ll;

int main() {
int N, M, a;  cin >> N >> M;
vector<bool> can_use(N, true);
for (int i = 0; i < M; i++) {
    cin >> a;
    can_use[a] = false;
}

vector<ll> c(N + 1);
ll n = 1000000007;

c[0] = 1;
c[1] = 1;
for (int i = 2; i < N + 1; i++) {
    if (!(can_use[i - 1]) && !(can_use[i - 2])) {
        cout << 0 << endl;
        return 0;
    } else if (!(can_use[i - 1])) {
        c[i] = c[i - 2];
    } else if (!(can_use[i - 2])) {
        c[i] = c[i - 1];
    } else {
        c[i] = (c[i - 1] + c[i - 2]) % n;
    }
}

cout << c[N] << endl;

}

Measured memory_bytes: 1024
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1e4;

string s;
int d,n;

int dp[N][105][2];          // (index, sum, tight)

int rec(int n,int sum,int tight)
{
    if(n==-1)
    {
        if(sum==0)
            return 1;
        else
            return 0;
    }

    if(dp[n][sum][tight]!=-1)
        return dp[n][sum][tight];

    int k=9;
    if(tight)
        k=s[n]-'0';

    int res=0,nt;
    for(int i=0;i<=k;++i)
    {
        if(i==s[n]-'0')
            nt=tight;
        else
            nt=0;

        res=(res+rec(n-1,(sum+i)%d,nt))%M;
    }

    //cout<<n<<" "<<sum<<" "<<tight<<" "<<res<<"\n";

    return (dp[n][sum][tight]=res);
}

void solve()
{
    mem(dp,-1);

    cin>>s>>d;
    n=s.length();

    reverse(all(s));

    int ans=(rec(n-1,0,1)-1ll+M)%M;
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 17408
// never give up //
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,n,i;
	string s;
	set< char > v;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		v.insert(s[i]);
	}
	if(v.size()==s.size())
	cout<<"yes";
	else
	cout<<"no";
	
	

}


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

void next (string &s, int n)
{
    int max;
    
    s[n-1]++;
    max = 'a';
    for (int i = 0; i < n-1; i++)
      if (s[i] > max) max = s[i];
    if (s[n-1] - max > 1) {
      s = s.substr(0, n-1);
      next(s, n-1);
      s += "a";
    }
}

int main()
{
  int n;
  cin >> n;
  
  string s(n, 'a');
  string end_s(n, 'a');
  for (int i = 0; i < n; i++) end_s[i] += i;
  while (s != end_s) {
      cout << s << endl;
      next(s, n);
  }
  cout << s << endl;
  
  return 0;
}

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  string s;
  cin >> s;
  int k;
  cin >> k;

  int n=s.size();

  vecst tmp;
  rep(i,n){
    string t="";
    rep(j,5){
      if(i+j<n){
        t+=s[i+j];
        tmp.push_back(t);
      }
    }
  }
  sortall(tmp);
  uniqueall(tmp);
  prt(tmp[k-1]);
}


Measured memory_bytes: 4300
n = gets.to_i
s = gets.chomp.chars
a = Array.new(n){Array.new(2, 0)}
if s[0] == '.'
  a[0][0] = 1
else
  a[0][1] = 1
end
1.upto(n - 1) do |i|
  if s[i] == '.'
    a[i][0] = a[i - 1][0] + 1
    a[i][1] = a[i - 1][1]
  else
    a[i][0] = a[i - 1][0]
    a[i][1] = a[i - 1][1] + 1
  end
end
min = [a[n - 1][0], a[n - 1][1]].min
n.times do |i|
  min = a[n - 1][0] - a[i][0] + a[i][1] if min > a[n - 1][0] - a[i][0] + a[i][1]
end
puts min

Measured memory_bytes: 30332
#include <iostream>
#include <algorithm>

using namespace std;

long long gcm(long long c, long long d)
{
    long long r, a = c, b = d;

    if(a < b) swap(a, b);
    r = a % b;
    while(r) {
        a = b; b = r;
        r = a % b;
    }

    return c * d / b;
}

int main()
{
    int ans = 0;
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long _gcm = gcm(c, d);
    --a;

    cout << (b - (b / c + b / d - b / _gcm)) - (a - (a / c + a / d - a / _gcm));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,c,a,b,k,q;
int main(){
  for(cin>>n>>a;i<n-1;i++){
    cin>>b;
    if(b>a)m=max(m,c),c=0;
    else c++;
    a=b;
  }
  m=max(m,c);
  cout<<m;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;


typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void shortestPath(const Graph &g, int s,
	vector<Weight> &dist, vector<int> &prev) {
	int n = g.size();
	dist.assign(n, INF); dist[s] = 0;
	prev.assign(n, -1);
	priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
	for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
		Edge e = Q.top(); Q.pop();
		if (prev[e.dst] != -1) continue;
		prev[e.dst] = e.src;
		for (auto f = g[e.dst].begin();f != g[e.dst].end();f++) {
			if (dist[f->dst] > e.weight + f->weight) {
				dist[f->dst] = e.weight + f->weight;
				Q.push(Edge(f->src, f->dst, e.weight + f->weight));
			}
		}
	}
}
vector<int> buildPath(const vector<int> &prev, int t) {
	vector<int> path;
	for (int u = t; u >= 0; u = prev[u])
		path.push_back(u);
	reverse(path.begin(), path.end());
	return path;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

int main() {
	ll H, W;
	cin >> H >> W;
	Graph g((H+1)*(W+1));
	vector<string> area(H+2, string(W+2, '#'));
	for (int y = 1;y <= H;y++) {
		cin >> area[y];
		area[y] = "#" + area[y] + "#";
	}
	for (int y = 1;y <= H;y++)
		for (int x = 1;x <= W;x++)
			for (int k = 0;k < 4;k++)
				if (area[y][x] == '.' && area[y + dy[k]][x + dx[k]] == '.')
					g[y*W + x].push_back(Edge(y*W + x, (y + dy[k])*W + x + dx[k], 1));
	vector<Weight> dist;
	vector<int> prev;
	shortestPath(g, 1*W + 1, dist, prev);
	ll ans = 0;
	for (int y = 1;y <= H;y++)
		for (int x = 1;x <= W;x++)
			if(area[y][x] == '.')
				ans++;
	if (dist[H*W + W] >= INF - 100)
		cout << -1 << endl;
	else
		cout << ans - dist[H*W + W] - 1 << endl;
	return 0;
}


Measured memory_bytes: 512
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.io.*;
import java.util.*;
public class Main
{
    
    
    
    public static int func(ArrayList <Integer>ls[], int vis[], int len, int j,int dp[])
    {
        int temp=0;
        int ans=0;
        
        if(ls[j]==null)
        {
            return 0;
        }
         
        if( vis[j]==1)
        {
            return dp[j];
        }
       
        
        else {
            for(int k =0;k<ls[j].size();k++)
            {
            
            
            temp= 1+ func(ls,vis,len,ls[j].get(k),dp);
            
           // dp[ls[j].get(k)]=temp;
            ans=Math.max(temp,ans);
            
            }
        }
        vis[j]=1;
        return dp[j]=ans;
        
        
    }
    
    
	public static void main(String[] args) throws Exception {
	//	System.out.println("Hello World");
		
		int N,M;
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
	String s=br.readLine();
	String ss[]=s.split(" ");
	N=Integer.parseInt(ss[0]);
	M=Integer.parseInt(ss[1]);
	int x=0,y=0;
	int ans=0;
	int vis[]=new int[N+1];
	int dp[]=new int [N+1];
	Arrays.fill(dp,0);
	//int dp[][]=new int[N+1][N+1];
	ArrayList<Integer>ls[]=new ArrayList[N+1];
	for(int i=0;i<M;i++)
	{
	    s=br.readLine();
	    ss=s.split(" ");
	 x=Integer.parseInt(ss[0]);
	y=Integer.parseInt(ss[1]);
	 if(ls[x]==null)
	 {
	     ls[x]=new ArrayList();
	 }
	    ls[x].add(y);
	    
	}
	for(int i=1;i<=N;i++)
	{
	 if(vis[i]==1)
	 {
	     ans=Math.max(ans,dp[i]);
	     continue;
	 }
	 if(ls[i]!=null)
	 {
	     vis[i]=1;
	     for(int j=0;j<ls[i].size();j++)
	     {
	      int temp =1+func(ls,vis,0,ls[i].get(j),dp);
	      dp[i]=Math.max(dp[i],temp);
	      
	     }
	      ans=Math.max(ans,dp[i]);
	 }
	   
	}
	System.out.println(ans);
   
	}
}


Measured memory_bytes: 61480
mod=10**9+7
def prime_factor(n):
  ass=[]
  for i in range(2,int(n**0.5)+1):
    while n%i==0:ass.append(i);n//=i
  if n!=1:ass.append(n)
  return ass
f=[1]
for i in range(1,200000):f.append(f[-1]*i%mod)
def comb(a,b,m):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m

n,m=map(int,input().split())
if m==1:print(1);exit()
d=prime_factor(m)
b=[1]
for i in range(1,len(d)):
  if d[i-1]==d[i]:b[-1]+=1
  else:b.append(1)
ans=1
for i in b:ans*=comb(i+n-1,i,mod);ans%=mod
print(ans)

Measured memory_bytes: 11052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cstdlib>

using namespace std;

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t X, Y;
    std::cin >> X >> Y;

    //long double n = log2((long double)Y/X) + 1;

    int64_t n = 0;
    int64_t v = X;
    while (v <= Y) {
        v *= 2;
        n++;
    }

    std::cout << n << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char s[110];bool C;
int main()
{
	gets(s+1);int len=strlen(s+1);
	for(int i=1;i<=len;i++)
	{
		if(s[i]=='C')C=1;
		if(C&&s[i]=='F'){printf("Yes\n");return 0;}
	}printf("No\n");return 0;
}

Measured memory_bytes: 128
def f(): return map(int,raw_input().split())
n,q=f()
a0,v0=0,0
A=[0]*(n+1)
for _ in range(q):
  a,v=f()
  A[a]+=v
  if a==a0 and A[a]<v0:
    v0=max(A)
    a0=A.index(v0)
  elif A[a]>v0: a0,v0=a,A[a]
  elif A[a]==v0 and a<a0: a0=a
  print a0,v0

Measured memory_bytes: 15084
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,x[105];
int main(){
	cin>>n;
	rep(i,n)cin>>x[i];
	int ans=INF;
	rep(i,200){
		int add=0;
		rep(j,n) add+=(x[j]-i)*(x[j]-i);
		ans=min(ans,add);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

bool solve(int i,int m);

int n,q,A[20],M[200];

int main(){
  cin >> n;
  rep(i,n) cin >> A[i];
  cin >> q;
  rep(i,q) cin >> M[i];

  rep(i,q){
    if(solve(0,M[i])) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

bool solve(int i,int m){
  if(m == 0) return true;
  if(i >= n || m < 0) return false;
  if(solve(i+1,m)) return true;
  if(solve(i+1,m-A[i])) return true;
  return false;
}




Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main(){
    int i,n;
    cin >> n;
    long long a[10000],max = 0,min = 0,sum = 0;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    max = a[0];
    min = a[0];
    for(int j = 0; j < n; j++){
        if(max < a[j]){
            max = a[j];
        }
        if(min > a[j]){
            min = a[j];
        }
        sum = sum + a[j];
    }
    cout << min << " " << max << " " << sum << endl;
 
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,x[N],y[N];
ll ans;
int main()
{
	cin>>n;
	for(int i=0;i<=n;i++)
	{
		cin>>x[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>y[i];
		ans+=min(y[i],x[i]+x[i+1]);
		x[i+1]-=min(max(0,y[i]-x[i]),x[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

long long dp[110][100010];
int main() {
	int N;
	cin >> N;
	if (N == 1) {
		cout << "Hello World";
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;

void solve(){

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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int q,w;
    q=max(a,c);
    w=min(b,d);
    if (q>=w) {
        cout << 0;

    }
    else {
        cout << w-q ;
        
    }

    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = new long[][](N);
	foreach (i; 0..N)
		A[i] = RDA;
	
	bool ok = true;
	(){
	foreach (y; 0..N)
	{
		foreach (x; y+1..N)
		{
			if (A[y][x] != A[x][y])
			{
				ok = false;
				return;
			}
		}
	}}();
	foreach (i; 0..N)
	{
		if (A[i][i] != 0)
		{
			ok = false;
			break;
		}
	}

	if (ok)
	{
		long ans;
		long[][] edges;
		foreach (y; 0..N)
		{
			foreach (x; y+1..N)
			{
				edges ~= [y, x, A[y][x]];
			}
		}
		edges.sort!"a[2] < b[2]"();
		(){
		foreach (e; edges)
		{
			debug writeln(e);
			auto from = e[0];
			auto to   = e[1];
			auto d    = e[2];
			long pos = -1;
			foreach (i; 0..N)
			{
				if (A[from][i] > d) continue;
				if (i == to || i == from) continue;
				auto tmp = A[from][i]+A[i][to];
				if (tmp == d)
				{
					pos = i;
				}
				else if (tmp < d)
				{
					ans = -1;
					return;
				}
			}
			debug writeln("pos:", pos);
			if (pos == -1)
			{
				ans += d;
			}
		}}();
		writeln(ans);
	}
	else
		writeln(-1);

	stdout.flush;
	debug readln;
}

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

int main()
{
    long long N, K, x;
    cin >> N >> K;
    set<long long> s;
    for (auto i = 0; i < 10; i++)
        s.insert(i);
    for (auto i = 0; i < K; i++)
    {
        cin >> x;
        s.erase(x);
    }

    while (true)
    {
        x = N;
        long long digit = 1;
        while (x > 0)
        {

            if (s.find(x % 10) == s.end())
            {
                N = (x + 1) * digit;
                break;
            }
            digit *= 10;
            x /= 10;
        }
        if (x == 0)
            break;
    }

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);

    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];


    for (int i = 0; i + m <= n; i++) {
        for (int j = 0; j + m <= n; j++) {

            bool ok = true;

            for (int ii = 0; ii < m; ii++) {
                for (int jj = 0; jj < m; jj++) {
                    if (a[i + ii][j + jj] != b[ii][jj]) {
                        ok = false;
                    }
                }
            }

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

Measured memory_bytes: 256
string = input()
news = "NEWS"
flg = [False for _ in range(4)]
for s in string:
    for i in range(4):
        if s == news[i]:
            flg[i] = True
            break
if flg[0] != flg[3] or flg[1] != flg[2]:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
// ProblemURL : https://atcoder.jp/contests/agc036/tasks/agc036_a
// ---------------------------------------------
package main

import "fmt"

type point struct{ x, y int }

func main() {
	var s int
	fmt.Scan(&s)

	max := int(1e9)
	a := point{x: 0, y: 0}
	b := point{x: max, y: 1}
	c := point{x: (max - s%max) % max, y: 1 + (s-1)/max}

	fmt.Println(a.x, a.y, b.x, b.y, c.x, c.y)
}


Measured memory_bytes: 512
#Beginner COnetst 145 /2019/11/16
#Probrem A
DEBUG = 0

def calc(n,S):
    if n%2 == 1:return 'No'
    h = n//2
    pre = S[0:h]
    if DEBUG == 1:print(pre)
    lat = S[h:n]
    if DEBUG == 1:print(lat)
    if pre == lat: return 'Yes'
    else: return 'No'

n = int(input())
S = input()


print(calc(n,S))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n,m;
	cin>>n>>m;
	vector<int> in(n+1,0),out(n+1,0),p(n+1,-1);
	vector<vector<int>> g(n+1);
	for(int i=0;i<n-1+m;++i){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		++out[u],++in[v];
	}
	queue<int> Q;
	for(int i=1;i<=n;++i) if(in[i]==0) Q.push(i),p[i]=0;
	while(!Q.empty()){
		int u=Q.front();
		Q.pop();
		for(int v:g[u]) 
			if(p[v]==-1){
				--in[v];
				if(in[v]==0) Q.push(v),p[v]=u;
			}
	}
	for(int i=1;i<=n;++i) cout<<p[i]<<'\n';
}

Measured memory_bytes: 7424
def main():
    n = int(input())
    up = []
    down = []
    for _ in range(n):
        height = 0
        m = 0
        for si in input():
            if si == "(":
                height += 1
            else:
                height -= 1
                m = min(m, height)
        if height >= 0:
            up.append([m, height])
        else:
            down.append([m-height, -height])
    up.sort(reverse=True)
    down.sort(reverse=True)
    if sum([i for _, i in up]) - sum([i for _, i in down]) != 0:
        print("No")
        return
    h = 0
    for mi, hi in up:
        if h+mi < 0:
            print("No")
            return
        h += hi
    h = 0
    for mi, hi in down:
        if h+mi < 0:
            print("No")
            return
        h += hi
    print("Yes")
    return
            

if __name__ == "__main__":
    main()

Measured memory_bytes: 99984
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy" << endl;
  else if (s == "Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
while(fscanf(STDIN,"%d %d %d",$score_m,$score_f,$score_r)){
    if($score_m===-1 and $score_f===-1 and $score_r===-1) break;
    $score_mf = $score_m + $score_f;
    if($score_m===-1 or $score_f===-1 or $score_mf<30 ){
        echo "F",PHP_EOL;
    }elseif($score_mf >= 80){
        echo "A",PHP_EOL;
    }elseif($score_mf >=65 ) {
        echo "B",PHP_EOL;
    }elseif($score_mf >= 50 or ($score_mf>=30 and $score_r>=50) ){
        echo "C",PHP_EOL;
    }elseif($score_mf >= 30){
        echo "D",PHP_EOL;
    }
}

Measured memory_bytes: 15160
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    System.out.println((S.charAt(0) != S.charAt(1) && S.charAt(1) != S.charAt(2) && S.charAt(2) != S.charAt(3)) ? "Good" : "Bad");
  }
}

Measured memory_bytes: 23764
import sys

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


def main():
    x, y = map(int, readline().split())

    print((x - 1) * (y - 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61320
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    while(cin >> n , n){
        int px[n][n] , py[n][n];
        int x , y;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >> px[i][j] >> py[i][j];
        int visited[n][n] = {};
        int ans = 0;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++){
                stack <pair <int , int> > st;
                if(visited[i][j] == 2)continue;
                visited[i][j] = 1;
                st.push(make_pair(i,j));
                int y = py[i][j] , x = px[i][j];
                while(1){
                    if(visited[y][x] != 0){
                        if(visited[y][x] == 1){
                            ans++;
                            visited[y][x] = 2;
                        }
                        while(!st.empty()){
                            if(visited[st.top().first][st.top().second] != 2)
                                visited[st.top().first][st.top().second] = 0;
                            st.pop();
                        }
                        break;
                    }
                    else{
                        visited[y][x] = 1;
                        st.push(make_pair(y,x));
                    }
                    int kari = y;
                    y = py[y][x];
                    x = px[kari][x];
                    kari = y;
                }
            }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int s,w;
    while(cin>>s>>w){
        cout<<(s>w?"safe":"unsafe")<<endl;
    }
    return 0;
}


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

int main() {
  int R,C,K;
  cin>>R>>C>>K;
  vector<vector<int64_t>> p(R,vector<int64_t>(C));
  for(int i=0;i<K;i++){
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    a--,b--;
    p[a][b]=c;
  }
  vector<int64_t> dp(C);
  for(int i=0;i<R;i++){
    vector<int64_t> ndp(C);
    vector<int64_t> kdp(4);
    for(int j=0;j<C;j++){
      kdp[0]=max(kdp[0],dp[j]);
      ndp[j]=kdp[0];
      for(int k=2;k>=0;k--){
        kdp[k+1]=max(kdp[k+1],kdp[k]+p[i][j]);
        ndp[j]=max(ndp[j],kdp[k+1]);
      } 
    }
    dp=ndp;
  }
  cout<<dp[C-1]<<endl;
}

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

using namespace std;

int N,balls[1000][10];
string result[1000];

void saiki(int Bnow,int Cnow,int next,int roop)
{
	if(next == 10)
	{
		result[roop] = "YES";
	}
	else
	{
		if(Bnow < balls[roop][next])
		{
			saiki(balls[roop][next],Cnow,next+1,roop);
		}
		if(Cnow < balls[roop][next])
		{
			saiki(Bnow,balls[roop][next],next+1,roop);
		}
	}
}

int main()
{
	for(int a = 0;a<1000;a++)
	{
		result[a] = "NO";
	}

	cin >> N;

	for(int i = 0;i<N;i++)
	{
		for(int a = 0;a<10;a++)
		{
			cin >> balls[i][a];
		}

		saiki(0,0,0,i);

		cout << result[i] << endl;
	}

}

Measured memory_bytes: 1248
# frozen_string_literal: true

N = gets.to_i
vs = gets.chomp.split(' ').map(&:to_i)
vs.sort!

merged = vs[0].to_f
N.times do |i|
  next if N - 1 == i

  merged = (merged + vs[i + 1]) / 2.to_f
end
puts merged


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

int main(){
  int N, MOD; cin >> N >> MOD;
  vector<vector<long long>> dp(3 * N + 1, vector<long long>(6 * N + 3, 0));
  dp[0][N * 3 + 1] = 1;
  rep(i, N * 3 + 1) rep(k, 6 * N) {
    if (i == 0 || k == 0) continue;
    long long num = 0;
    if (i >= 3) { num += dp[i - 3][k] * (3 * N - i + 2) * (3 * N - i + 1); num %= MOD; }
    if (i >= 2) { num += dp[i - 2][k - 1] * (3 * N - i + 1); num %= MOD; }
    if (i >= 1) { num += dp[i - 1][k + 1]; num %= MOD; }
    dp[i][k] = num;
  }
  long long ans = 0;
  rep(i, N * 3 + 2) {
    ans += dp[3 * N][i];
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 565248
# coding:utf-8
S = input()
s =len(S)
t=0

def endcheck(t,s):
  if t==s:
    print("YES")
    
while t < s:
  if S[-t-5:s-t] =="dream":
    t += 5
    endcheck(t,s)
  elif S[-t-7:s-t] =="dreamer":
    t += 7
    endcheck(t,s)
  elif S[-t-5:s-t] =="erase":
    t += 5
    endcheck(t,s)
  elif S[-t-6:s-t] =="eraser":
    t += 6
    endcheck(t,s)
  else:
    print("NO")
    break
  


Measured memory_bytes: 3316
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = inp()
a = inpl()
cntsum = list(itertools.accumulate(a)) + [0]
cntcol = Counter(cntsum)
res = 0
for key in cntcol.keys():
    if cntcol[key] >= 2:
        res += conb(cntcol[key],2)
print(res)


Measured memory_bytes: 111668
#include <iostream>
#include <string>
#include <vector>
#include "limits.h"
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>

#define mod 1000000000+7;
typedef long long ll;
using namespace std;

const int N = 1e7 + 5;
vector<ll> v(N);

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n; cin >> n;
 
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = i; j <= n; j += i){
            v[j]++;
		}
        ans += v[i] * i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 81244
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        int a[] = new int[n];
        ArrayList<Integer> li = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            for (int j = 0; j < a[i]; j++) {
                li.add(i + 1);
            }
        }
        int k = 0;
        int c[][] = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                c[i][j] = li.get(k);
                k++;
            }
        }
        for (int i = 0; i < h; i++) {
            if (i % 2 == 0) {
                for (int j = w - 1; j > 0; j--) {
                    System.out.print(c[i][j] + " ");
                }
                System.out.println(c[i][0]);
            } else {
                for (int j = 0; j < w - 1; j++) {
                    System.out.print(c[i][j] + " ");
                }
                System.out.println(c[i][w - 1]);
            }
        }
    }
}


Measured memory_bytes: 32248
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() { // num or 'infinity'
    input! {
        T1: i64, T2: i64,
        A1: i64, A2: i64, 
        B1: i64, B2: i64,
    }

    let mut diff1 = T1 * (A1 - B1);
    let mut diff2 = T2 * (A2 - B2);
    if diff1 > 0 {
        diff1 *= -1;
        diff2 *= -1;
    }

    if diff1 + diff2 == 0 {
        println!("infinity");
        return;
    }
    if diff1 + diff2 < 0 {
        println!("0");
        return;
    }

    let div = diff1 + diff2;
    let mut ans = -diff1 / div * 2;
    if -diff1 % div != 0 {
        ans += 1;
    }
    println!("{}", ans);

}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  string S, T;
  cin >> S >> T;

  rep(i, S.size()){
    if(S[i] != T[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  
  return 0;
}


Measured memory_bytes: 3628
w, h, n = map(int, input().split())
xyaList = [list(map(int, input().split())) for _ in range(n)]
blackRec = [[0, w], [0, h]]
for i in range(n):
    x = xyaList[i][0]
    y = xyaList[i][1]
    a = xyaList[i][2]
    if a == 1 and blackRec[0][0] < x:
        blackRec[0][0] = x
    elif a == 2 and blackRec[0][1] > x:
        blackRec[0][1] = x
    elif a == 3 and blackRec[1][0] < y:
        blackRec[1][0] = y
    elif a == 4 and blackRec[1][1] > y:
        blackRec[1][1] = y
width = blackRec[0][1] - blackRec[0][0]
height = blackRec[1][1] - blackRec[1][0]
ans = width * height
if width < 0 or height < 0:
    ans = 0
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{  string a,b;
  cin>>a;
 cin>>b;
 int count=0;
  for(int i=0;i<3;i++)
  {  if(a[i]==b[i])
        count++;

  }
 cout<<count<<endl;


}


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

//Containers
typedef long long int lng;
#define vint vector<int>
#define vtwod vector<vector<int>>
#define vlng vector<long long int>
#define vstr vector<string>
#define vvint vector<int,int>
#define pint pair<int,int>
#define lint list<int>
#define qint queue<int>
#define dqint deque<int>
#define pq priority_queue<int>
#define rpq priority_queue<int,vector<int>,greater<int>>
#define fl forward_list<int>
#define st stack<int>
#define sint set<int>
#define msint multiset<int>


//Methods of containers:-
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define binsear binary_search
#define popf pop_front
#define popb pop_back
#define empb emplace_back
#define empf emplace_front
#define emp emplace
#define emt empty
#define ins insert
#define insaft insert_after
#define emplaft emplace_after
#define ersaft erase_after
#define swp swap
#define splicaft splice_after


//FUNCTIONS
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int max3(int a,int b,int c)
{
    return max(max(a,b),c);
}
void gcd(int a,int b)
{
    cout<<__gcd(a,b)<<endl;
}

/*******************************************************CODE**************************************************************/
void doit()
{
    lng n=0,c1=0,c2=0,c3=0,c4=0;
    cin>>n;
    for(lng i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s[0]=='A')
        {
            c1++;
        }
        else if(s[0]=='W')
        {
            c2++;
        }
        else if(s[0]=='T')
        {
            c3++;
        }
        else if(s[0]=='R')
        {
            c4++;
        }
    }
    cout<<"AC x "<<c1<<endl;
    cout<<"WA x "<<c2<<endl;
    cout<<"TLE x "<<c3<<endl;
    cout<<"RE x "<<c4<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(NULL);
    doit();
    return 0;
}




Measured memory_bytes: 3668
def update(i,j):

    tmp_A = 200
    tmp_B = 200
    
    if 0 < i < H and j < W:
        if table[i-1][j] == table[i][j]:
            tmp_A = colormap[i-1][j]
        else:
            if table[i-1][j]:
                tmp_A = colormap[i-1][j] + 1
            else:
                tmp_A = colormap[i-1][j]
    if i < H and 0 < j < W:
        if table[i][j-1] == table[i][j]:
            tmp_B = colormap[i][j-1]
        else:
            if table[i][j-1]:
                tmp_B = colormap[i][j-1] + 1
            else:
                tmp_B = colormap[i][j-1]
    
    colormap[i][j] = min(tmp_A, tmp_B)

H, W = map(int, input().split())
table = []
for i in range(H):
    table.append([(True if x == "." else False) for x in list(input())])

colormap = [[0 for _ in range(W)] for _ in range(H)]
colormap[0][0] = 0 if table[0][0] else 1

for i in range(H):
    for j in range(W):
        if not(i == 0 and j ==0):
            update(i, j)
    # print(colormap)

# 必要反転回数
print(colormap[H-1][W-1])

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
    long long  n,i,f=0,a[100010],j=1;
    cin>>n;
    cin>>a[0];
    for(i=1; i<n; i++)
    {
        long long  c;
        cin>>c;
        if(c!=a[j-1])
            a[j++]=c;
    }
    if(j==1)
        cout<<"Yes"<<endl;
    else if(j==2&&a[0]-a[1]<2)
        cout<<"Yes"<<endl;
    else if(j==2&&a[0]-a[1]>1)
        cout<<"No"<<endl;
    else
    {
        for(i=0; i<j-2; i++)
        {
            if(a[i]>a[i+1]&&a[i+1]>a[i+2])
            {
                f=0;
                break;
            }
            else if(a[i]-a[i+1]>1)
            {
                f=0;
                break;
            }
            else
                f=1;
        }
        if(f==1&&a[j-2]-a[j-1]<2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	vector<vector<char>>A(2, vector<char>(3));
	vector<vector<char>>B(2, vector<char>(3));
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			B[i][j] = A[1 - i][2 - j];
		}
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 3; j++) {
			if (A[i][j] != B[i][j]) {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String args[]){
	int A[] = new int[100000];
	int i,j,n,l,count=0;
	Scanner scan = new Scanner(System.in);
	
	n = scan.nextInt();
	
	for(i=0;i<n;i++){
	    A[i] = scan.nextInt();
	}
	
	l = partition(A,0,n-1);
	
	for(i=0;i<n;i++){
	    if(A[l]==A[i]){
		count++;
	    }
	}
	
	for(i=0;i<n;i++){
	    if(A[l]==A[i]){
		count--;
		if(count<1){
		System.out.print("["+A[i]+"] ");
		continue;
		}
	    }
	    if(i==n-1){
		System.out.println(A[i]);
		break;
	    }
	    System.out.print(A[i]+" ");
	}
    }
    
    public static int partition(int A[],int p,int r){
	int i,j,x,temp=0;
	
	x = A[r];
	i = p-1;
	for(j=p;j<r;j++){
	    if(A[j]<=x){
		i++;
		temp = A[i];
		A[i] = A[j];
		A[j] = temp;
	    }
	}
	temp = A[i+1];
	A[i+1] = A[r];
	A[r] = temp;
	return i+1;
    }
}



Measured memory_bytes: 68396
// Last Change: 04/13/2019 23:34:31.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  bool ans = true;
  map<string, int> W;
  char last;

  for (int i = 0; i < N; ++i) {
    string ipt;
    cin >> ipt;

    if (i > 0) {
      if (ipt[0] != last) {
        ans = false;
      }
    }

    if (W[ipt] != 0) {
      ans = false;
    }
    ++W[ipt];
    last = ipt[ipt.size() - 1];
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
n,m = map(int,input().split())
t='000'
if n==2: t='010'
if n==3: t='100'
f=[0]*len(t)
t=[int(t[0]),int(t[1]),int(t[2])]
ans = t[0]*100+t[1]*10+t[2] 
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s=s-(n-2)
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    int num=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        num^=a[i];
    }
    
    for(int i=0;i<n;i++)
        cout<<(num^a[i])<<" ";
    
    return 0;
}

Measured memory_bytes: 3884
import sys
import itertools
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

town = [list(map(int, input().split())) for _ in range(N)]
lis = [x for x in range(N)]
roots = list(itertools.permutations(lis))
sum_dis = 0

for i in range(len(roots)):
    for j in range(N-1):
        sum_dis += math.sqrt((town[roots[i][j]][0] - town[roots[i][j+1]][0])**2 + (town[roots[i][j]][1] - town[roots[i][j+1]][1])**2)

print(sum_dis / len(roots))
    

Measured memory_bytes: 7972
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, H, W;
    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W + 1) << endl;

    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D)
    cout << "Left" << endl;
  if (A + B == C + D)
    cout << "Balanced" << endl;
  if (A + B < C + D)  
    cout << "Right" << endl;
}

Measured memory_bytes: 256