akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
typedef int ll;
 
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
 
const ll N = 500002;
const ll mod = 1000000007;
const long long int inf = INT64_MAX;
#define pp pair<ll,ll>

typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;
 
 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);


int main()
{
	fastIO();
	ll n,m;
	cin>>n>>m;
	vector<pp> v(m);
	rep(i,m){
		cin>>v[i].first>>v[i].second;
	}
	vector<ll> ans(n);
	ll f = 0;
	rep(i,n) ans[i] = -1;	
	rep(i,m){
		if(ans[v[i].first-1]==-1 || ans[v[i].first-1]==v[i].second){
			ans[v[i].first-1]= v[i].second;
		}
		else{
			f = 1;
			break;
		}
	}
	if(f){
		cout<<-1<<endl;
		return 0;
	}
	if(n==1){
		if(ans[0]==-1) cout<<0<<endl;
		else cout<<ans[0]<<endl;
		return 0;
	}
	if(n==2){
		if(ans[0]==0){
			cout<<-1<<endl;
			return 0;
		}
		if(ans[0]==-1) cout<<1;
		else cout<<ans[0];
		if(ans[1]==-1) cout<<0;
		else cout<<ans[1];
		cout<<endl;
		return 0;
	}
	if(n==3){
		if(ans[0]==0){
			cout<<-1<<endl;
			return 0;
		}
		if(ans[0]==-1) cout<<1;
		else cout<<ans[0];
		if(ans[1]==-1) cout<<0;
		else cout<<ans[1];
		if(ans[2]==-1) cout<<0;
		else cout<<ans[2];
		cout<<endl;
		return 0;
	}
}


	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

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

int main() {
    int W, H, N, x[101], y[101], a[101];
    cin >> W >> H >> N;
    for (int i = 1; i <= N; ++i) cin >> x[i] >> y[i] >> a[i];
    int xmax = W, xmin = 0;
    int ymax = H, ymin = 0;

    for (int i = 1; i <= N; ++i) {
        if (a[i] == 1) {
            if (x[i] >= xmin) xmin = x[i];
        }
        else if (a[i] == 2) {
            if (x[i] <= xmax) xmax = x[i];
        }
        else if (a[i] == 3) {
            if (y[i] >= ymin) ymin = y[i];
        }
        else if (a[i] == 4) {
            if (y[i] <= ymax) ymax = y[i];
        }
    }

    if (xmax <= xmin || ymax <= ymin) cout << 0 << endl;
    else cout <<(xmax - xmin) * (ymax - ymin) << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const double DINF = 5e14, eps = 1e-10;
const long long MOD = 1e9 + 7, INF = 5e18;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

ll n, m;
string s, t;
map<ll, char>mp;

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

int main() {
	cin >> n >> m >> s >> t;
	ll lcm = (n / gcd(n, m))*(m / gcd(n, m))*gcd(n, m);
	ll now = 1;
	for (int i = 0;i < n;i++) {
		mp[now] = s[i];
		now += lcm / n;
	}
	now = 1;
	for (int i = 0;i < m;i++) {
		if (!mp[now]) {
			now += lcm / m;
			continue;
		}
		if (mp[now] != t[i]) {
			cout << -1 << endl;
			return 0;
		}
		now += lcm / m;
	}
	cout << lcm << endl;
	return 0;
}


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


int main() {
    int a;
    int b;
    cin >> a;
    cin >> b;
    if (a <= 9 && a > 0 && b <= 9 && b > 0) {
        cout << a * b << endl;
    } else {
        cout << "-1" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN=100;

char s[MAXLEN+1]; int slen;
int times;


ll solve() {
	vector<int> parts;
	for(int l=0,r=l;l<slen;l=r) {
		while(r<slen&&s[r]==s[l]) ++r;
		parts.PB(r-l);
	}
	if(SZ(parts)==1) {
		ll tlen=(ll)slen*times;
		return tlen/2;
	} else if(s[0]!=s[slen-1]) {
		ll ret=0; REPSZ(i,parts) ret+=(ll)times*(parts[i]/2); return ret;
	} else {
		ll ret=0;
		REPSZ(i,parts) if(i==0||i==SZ(parts)-1) ret+=(parts[i]/2); else ret+=(ll)times*(parts[i]/2);
		ret+=(ll)(times-1)*((parts[0]+parts[SZ(parts)-1])/2);
		return ret;
	}
}

void run() {
	scanf("%s",s); slen=strlen(s);
	scanf("%d",&times);
	printf("%lld\n",solve());
}

int main() {
	run();
	return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	string s1,s2;
	string s;
	cin>>s1>>s2;
	for(int i=0;i<n;i++)
	  {
	      s+=s1[i];
	      s+=s2[i];
	  }
	  cout<<s;
	return 0;
	
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int u[1100000];
vector<int> y;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0;
  cin >>a;
  if(a%2==0) cout  <<a<<'\n';
  else cout <<2*a<<'\n';
  return (0);
}


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

int n;

int main(void) {
    ios_base::sync_with_stdio(0);   cin.tie(0);
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        int a;  cin >> a;
        ans += a - 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for _ in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      if (i + 1 < h and s[i + 1][j] == "#") or (0 <= i - 1 and s[i - 1][j] == "#") or (j + 1 < w and s[i][j + 1] == "#") or (0 <= j - 1 and s[i][j - 1] == "#"):
        continue
      else:
        print("No")
        exit()
    else:
      continue
print("Yes")


Measured memory_bytes: 3064
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.toInt)
      .map {
        case n if n > 9 * 4 => 0
        case n => {
          val ub = math.min(9, n)
          (for (a <- 0 to ub; b <- 0 to ub; c <- 0 to ub; d <- 0 to ub if a + b + c + d == n) yield 1)
            .length
        }
      }
      .foreach(println)
  }
}

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

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

using namespace std;

int main(){
  int n;
  cin >> n;
  int ans = 100000;
  rep(i,n){
    int input;
    cin >> input;
    int cnt = 0;
    while(input % 2 == 0){
      input /= 2;
      cnt++;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


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

public class Main {
	MyScanner sc = new MyScanner();
	Scanner sc2 = new Scanner(System.in);
	int mod = 1000000007;

	void run() {
		while (sc2.hasNext()) {
			int v = sc2.nextInt();
			int d = sc2.nextInt();
			long[] f = new long[v + 1];
			f[0] = 2;
			f[1] = 3;
			for (int i = 2; i < v; i++) {
				f[i] = (f[i - 1] + f[i - 2]) % 1001;
			}
			Arrays.sort(f);
			int cnt = 1;
			for (int i = 2; i < v + 1; i++) {
				if (Math.abs(f[i] - f[i - 1]) >= d) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	void debug2(int[][] array) {
		for (int i = 0; i < array.length; i++) {
			for (int j = 0; j < array[i].length; j++) {
				System.out.print(array[i][j]);
			}
			System.out.println();
		}
	}

	class MyScanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-')
					return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}

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

		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
}

Measured memory_bytes: 22404
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
#define mfor(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  mfor(i,0,n)
#define all(x) (x).begin(),(x).end()

bool comp(const vector<int> &x, const vector<int> &y){
    return x[2] > y[2];
}

typedef pair<ll, ll> P;

bool pairComp(const P& x, const P& y) {
	return x.first < y.first;
}

int main(void){

	ll N, M;
	cin >> N >> M;
	vector<P> ab;
	rep(i, N) {
		ll A, B;
		cin >> A >> B;
		ab.push_back(make_pair(A, B));
	}

	sort(ab.begin(), ab.end(), pairComp);


	ll ans = 0;
	rep(i, N) {
		if (M <= 0) {
			continue;
		}
		if (M < ab[i].second) {
			ans += M * ab[i].first;
			M = 0;
		}else {
			ans += ab[i].first * ab[i].second;
			M -= ab[i].second;
		}
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
n=int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
ans = -1
h = 1000
for i in range(n):
  if abs(t-H[i]*0.006-a) < h:
    h = abs(t-H[i]*0.006-a)
    ans = i+1
print(ans)

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


using namespace std;


int main()
{
    int n,d;
    cin >> d >> n;
    if(d == 0)
    {if(n==100) cout << 101<<endl;
    else cout << n<<endl;}
    else if(d == 1) {if(n==100) cout << 10100<<endl;
    else cout << n*100<<endl;}
    else {if(n==100) cout << 1010000<<endl; else cout << n*10000 << endl;}

    return 0;
}



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

using namespace std;

int main() {

    int n;

    while(cin >> n, n) {

        int m, k, temp;
        vector<int> p[n], l, suspect;

        for(int i = 0; i < n; ++i) {
            cin >> m;
            for(int j = 0; j < m; ++j) {
                cin >> temp;
                p[i].push_back(temp);
            }
        }

        cin >> k;
        for(int i = 0; i < k; ++i) {
            cin >> temp;
            l.push_back(temp);
        }

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

            bool is_suspect = true;

            for(int j = 0; j < k; ++j) {
                if(find(p[i].begin(), p[i].end(), l[j]) == p[i].end()) {
                    is_suspect = false;
                }
            }

            if(is_suspect) {
                suspect.push_back(i + 1);
            }

        }

        if(suspect.size() == 1) {
            cout << suspect[0] << endl;
        } else {
            cout << -1 << endl;
        }

    }

}

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

int main(){
    long long n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++){
        if (to_string(i).length() % 2 == 1){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
c = []
s = []
f = []
for _ in range(N - 1):
    _c, _s, _f = [int(x) for x in input().split()]
    c.append(_c)
    s.append(_s)
    f.append(_f)

def solve(i):
    start_time = 0
    for j in range(i, N - 1):
        # print("---")
        # print(j)
        # print("start_time: {}".format(start_time))
        depart_time = get_dep_time(start_time, s[j], f[j])
        # print("depart_time: {}".format(depart_time))
        arrived_time = depart_time + c[j]
        # print("arrived_time: {}".format(arrived_time))
        start_time = arrived_time
    return arrived_time

def get_dep_time(start, s, f):
    """
    E.g.:
        start = 18
        s = 15
        f = 5
        ret = 20
        start = 13
        s = 15
        f = 5
        ret = 15
    """
    t = max(start, s)
    return math.ceil(t / f) * f

for i in range(N - 1):
    # print("===")
    # print("solving {}".format(i))
    print(solve(i))
    # print("===")
print(0)


Measured memory_bytes: 3188
/*
ID: alec3
LANG: C++14
PROG: ttwo
*/

#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

ifstream fin("0.in");
ofstream fout("ans.out");

// 10^3 * 100
int dp[100001];

int main()
{
    io;
    int n, W;
    cin >> n >> W;
    int w[n], v[n];

    for (int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    // set all numbers to greater than the
    // max weight (so they aren't valid solutiosn
    memset(dp, 0x3f, sizeof(dp));

    // you can make something with value 0
    dp[0] = 0;
    // loop through possible items
    for (int i = 0; i < n; i++){
        // loop through values
        for (int j = 100000 - v[i]; j >= 0; j--){
            // we can make the value j + v[i] with the min of
            // (the weight required for the j items + the weight of the new item),
            // and (the value of the ith item + the value of the jth item)
            // this is to check whether or not we've actually found a better solution,
            // one that uses the same weight to attain a greater value.
            dp[j + v[i]] = min(dp[j] + w[i], dp[j + v[i]]);
        }
    }
    // loop through values from top down and output the one
    // with the first valid weight.
    for (int i = 100000; i >= 0; i--){
        if (dp[i] <= W){
            cout << i << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
 
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n, 0);
    for (size_t i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll min_diff = 10000000000;
    for (size_t i = 0; i <= n - k; i++)
    {
        int diff = h[i + k - 1] - h[i];
        if (diff < min_diff)
        {
            min_diff = diff;
        }
    }
    cout << min_diff << endl;
 
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int INF=1e5;

signed main(){
  int H,W,h,w;cin>>H>>W>>h>>w;
  if(W%w){
    cout<<"Yes"<<endl;
    vector<int> v(W+1,0);
    for(int i=1;i<w;i++)v[i]=INF;
    for(int i=w;i<=W;i++)v[i]=v[i-w]-1;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++)cout<<v[j+1]-v[j]<<" ";cout<<endl;
    }
    return 0;
  }
  if(H%h){
    cout<<"Yes"<<endl;
    vector<int> v(H+1,0);
    for(int i=1;i<h;i++)v[i]=INF;
    for(int i=h;i<=H;i++)v[i]=v[i-h]-1;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++)cout<<v[i+1]-v[i]<<" ";cout<<endl;
    }
    return 0;
  }
  cout<<"No"<<endl;
}


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

int main(){
  double N,K;
  double ans = 0;
  cin >> N >> K;
  for(int i = 1;i <= N;i++){
    int a = i;
    int cnt = 0;
    while(a < K){
    	a = a * 2;
        cnt ++;
    }
    ans += (1/N)*pow(0.5,cnt);
  }
  cout << fixed << setprecision(12) << ans << endl;
}

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

int main() {
  uint64_t a,b,x;
  cin>>a>>b>>x;
  if(a==0){
    cout<<b/x+1<<endl;//0もxで割り切れる数の一つなので、1を足す。
    return 0;
  }
  cout<<b/x-(a-1)/x<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int cnt =0;
    for(int i =0 ;i < 4;i++)if(s.charAt(i)=='2')cnt++;
    System.out.println(cnt);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n;
int f(int a){
  int l = 0, r = 5000, mid;
  while(r-l > 1){
    mid = (r+l)/2;
    if(mid*(mid + 1)/2 >= a){
      r = mid;
    }else{
      l = mid;
    }
  }
  return r;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  while(n > 0){
    int a = f(n);
    printf("%d\n", a);
    n -= a;
  }
  return 0;
}

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

const int N = 3e3 + 5;
const int INF = 0x3f3f3f3f;

int dp[N][N];
string a, b, ans;

int dpf(int i, int j) {
  if(!i or !j) return dp[i][j] = 0;
  if(dp[i][j] != -INF) return dp[i][j];
  if(a[i-1] == b[j-1]) dp[i][j] = 1 + dpf(i-1, j-1);
  return dp[i][j] = max({dp[i][j], dpf(i-1, j), dpf(i, j-1)});
}

void rec(int i, int j) {
  if(!i or !j) return;
  vector<pair<int, int>> v;
  if(a[i-1] == b[j-1]) v.push_back({dp[i-1][j-1] + 1, 1});
  v.push_back({dp[i-1][j], 2});
  v.push_back({dp[i][j-1], 3});
  sort(v.begin(), v.end());
  int op = v.back().second;
  if(op == 1) ans += a[i-1], rec(i-1, j-1);
  if(op == 2) rec(i-1, j);
  if(op == 3) rec(i, j-1);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> a;
  cin >> b;
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++) dp[i][j] = -INF;
  dpf(a.size(), b.size());
  rec(a.size(), b.size());
  reverse(ans.begin(), ans.end());
  cout << ans << "\n";
}


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

int main(void){

  int N,M;
  scanf("%d %d\n", &N, &M);

  int *A, *B;
  A = (int*)malloc(M*sizeof(int));
  B = (int*)malloc(M*sizeof(int));
  for(int i=0; i<M; i++){
    scanf("%d %d\n", &A[i], &B[i]);
  }

  int tmpB=0;
  int *C;
  C = (int*)malloc(N*sizeof(int));

  for(int i=0; i<N; i++){
    C[i] = 0;
  }

  for(int i=0; i<M; i++){
    if(C[A[i]]==0 || C[A[i]]>B[i]){
      C[A[i]] = B[i];
    }
  }

  int ans=0;

  for(int i=0; i<N; i++){
    if(C[i]!=0){
      if(tmpB<=i){
        ans++;
        tmpB = C[i];
      }else if(tmpB>C[i]){
        tmpB = C[i];
      }
    }
  }


  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0];
            int K = V[1];
            Console.WriteLine((N % K == 0) ? 0 : 1);
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(){
  int a,ch,j,n[105],i;
  scanf("%d",&a);
  for( i=0;i<a;i++)scanf("%d",&n[i]);
  for( j=0;j<a-1;j++)printf("%d ",n[j]);
  printf("%d\n",n[a-1]);
  for(i=1;i<a;i++){
    j=i;
    while(1){

      if(j==0)break;
      if(n[j]<n[j-1]){

	ch=n[j];
	n[j]=n[j-1];
	n[j-1]=ch;
	j--;
      }else break;
    }
    for( j=0;j<a-1;j++)printf("%d ",n[j]);
    printf("%d\n",n[a-1]);

  }
  return 0;
}

Measured memory_bytes: 2684
#!/usr/bin/env python3
def main():
    import numpy as np

    N, W = map(int, input().split())
    products = [list(map(int, input().split())) for _ in range(N)]

    dp = np.zeros(W + 1, dtype=np.int64)
    for can_w, can_v in products:
        dp[can_w:] = np.maximum(dp[can_w:], dp[:-can_w] + can_v)

    print(np.max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29836
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint



INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)


# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
d = dict()
res = 0
for _ in range(N):
    s = "".join(sorted(list(input())))
    d[s] = d.get(s, 0) + 1

ans = 0
for v in d.values():
    if v >= 2:
        ans += comb(v, 2)

print(ans)


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

bool cmp(int a, int b)
{
   return a > b;
}

int main()
{
    int n;
     list<int> ansList;
    while(scanf("%d", &n) && n != 0)
    {
        vector<long long> c[40000];
        int left = 40000, right = 0;
        int fx, fy;
        int px, py;
        rep(i,0,n+1)
        {
            int x,y;
            if(i == n)
            {
                x = fx;
                y = fy;
                goto label;
            }
            cin >> x >> y;
            if(i == 0)
            {
                fx = x;
                fy = y;
                px = x;
                py = y;
                continue;
            }
            label:
            if(x != px)
            {
                int Min = min(x,px)+20000, Max = max(x,px)+20000;
                left = min(left,Min), right = max(right,Max);
                rep(j,Min,Max)
                {
                    c[j].push_back(y);
                }
                px = x;
            }
        }
        rep(i,left,right)
        {
            sort(c[i].begin(),c[i].end(), cmp);
        }
        pair<int,int> cartain[4];
        rep(i,0,4)
        {
            cin >> cartain[i].first >> cartain[i].second;
            cartain[i].first += 20000;
        }
        sort(cartain,cartain+4);
        int cUp= cartain[1].second;
        int cBottom = cartain[0].second;
        int cLeft = cartain[1].first;
        int cRight = cartain[3].first;
        long long ans = 0;
       
        rep(i, left, right)
        {
            int index = 0;
            int _size = c[i].size();
            bool flag = true;
            while(index < _size-1)
            {
                if(flag)
                {
                    int up = c[i][index];
                    int bottom = c[i][index+1];
                    if(cLeft > i || cBottom >= up || cUp <= bottom || cRight <= i)
                        ans += up - bottom;
                    else if(cBottom >= bottom && cBottom <= up && cUp >= up)
                        ans += cBottom - bottom;
                    else if(cUp >= bottom && cUp <= up && cBottom <= bottom) 
                        ans += up - cUp;
                    else if(cUp <= up && cBottom >= bottom)
                        ans += (up-cUp) + (cBottom-bottom);   
                }
                flag = !flag;
                index++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 24848
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int D = in.nextInt();
            String s = "Christmas";
            for (int i = 0; i < (25 - D); i++) {
                s += " Eve";
            }
            out.println(s);
        }

    }
}



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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.15Lf",n);
# define line cout<<"\n";

string vow = "aeiou";
const ld pie = 3.14159265358979 ;

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ; cin >> n ;

    ld ans= 0 ;
    for ( int i=0 ; i < n ; i++ )
    {
        ld temp ; cin >> temp ;
        temp = 1/temp ;

        ans += temp ;
    }

    ans = 1 / ans ;
    pp ( ans ) ;

}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    ll n, m; cin >> n >> m;
    if (n == 1 && m == 1) cout << 1 << endl;
    else if (min(n, m) == 1) cout << max(n, m) - 2 << endl;
    else cout << (n - 2) * (m - 2) << endl;
}

Measured memory_bytes: 3608
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	string s;
	int sum=700;
	cin >> s;
	if (s[0] == 'o')
	{
		sum += 100;
	}
	if (s[1] == 'o')
	{
		sum += 100;
	}
	if (s[2] == 'o')
	{
		sum += 100;
	}
	cout << sum << endl;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read(),k=read();
	int ans=0;
	FOR(b,(k+1),n+1){
		int p=n-b+1,q=n-k;
		int x=p/b,y=p%b;
		ans+=(q-p+1)*(x+1);
		int r=p+b-y;
		if(r<=q)ans+=(q-r+1);
		if(k==0)ans--;
	}
	print(ans);
}


Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())
X = np.array([list(map(int, input().split())) for i in range(N)])
cnt = 0
for i in range(N):
  for j in range(N):
    D = np.linalg.norm(X[i]-X[j], ord=2)
    if i < j and  D%1 == 0:
      cnt += 1
print(cnt)

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

int main()
{
	int array[10];
	int i, j, tmp;
	
	for(i=0; i<10; i++){
		cin >> array[i];
	}
	
	for(i=0; i<9; i++){
		for(j=i+1; j<10; j++){
			if(array[i] < array[j]){
				tmp = array[i];
				array[i] = array[j];
				array[j] = tmp;
			}
		}
	}
	
	for(i=0; i<3; i++){
		cout << array[i] << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MAXN=1e5+5;
int tot,head[MAXN];
bool mark[MAXN];
int ans1,ans2;
int n;
int num;
int slit;
int father;

struct Edge
{
    int from,to;
    int next;
}e[MAXN*2];

void add(int u,int v)
{
    e[tot].from=u;
    e[tot].to=v;
    e[tot].next=head[u];
    head[u]=tot++;
}

bool dfs(int rt,int fa)
{
    for(int i=head[rt];i!=-1;i=e[i].next)
    {
        int to=e[i].to;
        if(to==fa) continue;
        if(to==n) return true;
        if(dfs(to,rt))
        {
            mark[to]=true;
            return true;
        }
    }
    return false;
}

int dfs2(int rt,int fa)
{
    for(int i=head[rt];i!=-1;i=e[i].next)
    {
        int to=e[i].to;
        if(to==fa) continue;
        if(!mark[to]) continue;
        else
        {
            num++;
            if(num==slit)
            {
                father=rt;
                return to;
            }
            else
                return dfs2(to,rt);
        }
    }
}

void dfs3(int rt,int fa)
{
    for(int i=head[rt];i!=-1;i=e[i].next)
    {
        int to=e[i].to;
        if(to==fa) continue;
        ans1++;
        dfs3(to,rt);
    }
}

void dfs4(int rt,int fa)
{
    for(int i=head[rt];i!=-1;i=e[i].next)
    {
        int to=e[i].to;
        if(to==fa) continue;
        ans2++;
        dfs4(to,rt);
    }
}

int main()
{
    //ios::sync_with_stdio(false);
    while(cin>>n)
    {
        memset(head,-1,sizeof(head));
        memset(mark,false,sizeof(mark));
        tot=0;
        int u,v;
        for(int i=1;i<=n-1;i++)
        {
            cin>>u>>v;
            add(u,v);add(v,u);
        }
        dfs(1,0);
        mark[1]=true;mark[n]=true;
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(mark[i])
            {
                cnt++;
                //cout<<i<<" ";
            }

        }
        //cout<<endl;
        if(cnt&1)
            slit=cnt/2+1;
        else slit=cnt/2;
        //cout<<"slit: "<<slit<<endl;
        num=1;
        int id=dfs2(1,0);
        //cout<<id<<endl;
        int child;
        for(int i=head[id];i!=-1;i=e[i].next)
        {
            int to=e[i].to;
            if(mark[to]&&to!=father)
                child=to;
        }
        //cout<<father<<" "<<id<<" "<<child<<endl;
        ans1=0;ans2=0;
        dfs3(id,child);
        dfs4(child,id);
        //cout<<ans1<<" "<<ans2<<endl;
        if(ans1>ans2)
            cout<<"Fennec"<<endl;
        else
            cout<<"Snuke"<<endl;
    }

    return 0;
}

Measured memory_bytes: 7808
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){
  int K, X; cin >> K >> X;
  int l, r;
  l = max(-1000000, X - K + 1);
  r = min(1000000, X + K - 1);
  for(int i = l; i < r+1; i++){
    cout << i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 384
function main(input) {
  const args = input.split("\n");
  insertionSort(args[1].split(" ").map(i => +i), args[0]);
}

function insertionSort(A, N) {
  console.log(A.join(" "));
  for (let i = 1; i < N; i++) {
    let v = A[i];
    let j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    console.log(A.join(" "));
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n,a,b;

int main()
{
    read(n),read(a),read(b);
    if(a%n==0||b%n==0)return puts("OK"),0;
    int t1=a/n,t2=b/n;
    if(t1<t2)puts("OK");
    else puts("NG");
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, q; cin >> n >> q;
    vector<long long> a(n);
    vector<ll> sum(n+1);
    for(long long i = 0; i < n; i ++){
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    vector<long long> x(q);
    for(long long i = 0; i < q; i ++){
        cin >> x[i];
    }

    rep(i, q){
        ll ans = 0, l = 0;
        for(ll j = 1; j <= n; j++){
            while(true){
                if(sum[j] - sum[l] > x[i]){
                    l++;
                }else{
                    ans += j - l;
                    break;
                }
                if(l == j){
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    

}


Measured memory_bytes: 4348
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int a, b, c;
	int n = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (int i = a; i <= b; i++)
	{
		if (c%i == 0)
		{
			n++;
		}
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 2724
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
int INF = 1000000000;
vector<int> dijkstra(int s, int v, vector< vector< pair<int,int> > > G){
  //s: ?§????, v: ????????°, G: ??£??\?????????
  priority_queue< pair<int, int> > wait;
  vector<int> result(v, INF);
  result[s] = 0;
  wait.push(make_pair(0, s));
  while(!wait.empty()){
    int nowpoint = wait.top().second;
    int nowcost = wait.top().first;
    wait.pop();
    if(nowcost <= result[nowpoint]){
      for(int i = 0; i < G[nowpoint].size(); ++i){
	int nextpoint = G[nowpoint][i].second;
	int nextcost = -nowcost + G[nowpoint][i].first;
	if(nextcost < result[nextpoint]){
	  wait.push(make_pair(-nextcost, nextpoint));
	  result[nextpoint] = nextcost;
	}
      }
    }
  }
  return result;
}
int main(){
  int V, E, r, s, t, d;
  cin >> V >> E >> r;
  vector< vector<pii> > G(V);
  for(int i = 0; i < E; ++i){
    cin >> s >> t >> d;
    G[s].push_back(pii(d,t));
  }
  vector<int> result = dijkstra(r,V,G);
  for(int i = 0; i < V; ++i){
    if(result[i] >= INF){
      cout << "INF" << endl;
    }else cout << result[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 20220
N = int(input())
H = list(map(int,input().split()))
H.reverse()
cnt = 0
for i in range(N-1):
  if H[i+1]-H[i]==1:
    H[i+1] = H[i+1]-1
  elif H[i+1]-H[i]>1:
    cnt = 1
    break
if cnt == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14396
#include <stdio.h>
int main(){
  int N, n, a=0;
  scanf("%d", &N);
  n=N;
  while (n>0){
    a = a + n % 10;
    n /= 10;
  }
  if (N%a==0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
import collections
n = int(input())
S = [input() for _ in range(n)]
c = collections.Counter(S)
C = sorted(c.most_common(),key=lambda x: x[0])
C = sorted(C,key=lambda x: x[1], reverse=True)
t = C[0][1]
for i in range(len(C)):
    if C[i][1] == t:
        print(C[i][0])

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int r;
  cin >> r;
  if(r < 1200) cout << "ABC" << endl;
  else if(r < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;

}

Measured memory_bytes: 256
use std::ops::Sub;
use std::fmt::Debug;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
fn read_multi_line<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for i in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.parse().ok().expect("Can't Parse"));
    }
    vec
}

macro_rules! ignore {
    ($id:ident) => {};
}
macro_rules! assign {
    (let $($id:ident),* = $value:expr) => {
        let ($($id), *) = {
            let mut iter = $value.into_iter();
            ($({ignore!($id); iter.next().unwrap()}), *)
        }
    };
}
fn inspect<T: Debug>(vec: &Vec<T>) -> () {
    if let Some(first) = vec.first() {
        println!("Vec({:?}", first);
        for i in 1..vec.len() {
            println!(", {:?}", vec[i]);
        }
        println!(")");
    }else {
        println!("Vec()");
    }
}

#[derive(Copy, Clone, Debug)]
struct Angle {
    sin: f64,
    cos: f64
}
impl Angle {
    fn from_degree(degree: f64) -> Angle {
        if degree > 180f64 {Angle::from_degree(degree - 360f64)} else if degree < -180f64 {Angle::from_degree(degree + 360f64)} else {
            let rad = degree / 180f64 * std::f64::consts::PI;
            Angle { sin: rad.sin(), cos: rad.cos() }
        }
    }
}
impl Sub for Angle {
    type Output = Angle;
    fn sub(self, rhs: Self) -> Self::Output {
        Angle{sin: self.sin * rhs.cos - self.cos * rhs.sin, cos: self.cos * rhs.cos + self.sin * rhs.sin}
    }
}
fn main() {
    let radius = 6378.1f64;
    loop {
        assign!(let a, b, c, d = read_values::<f64>());
        if a == -1f64 && b == -1f64 && c == -1f64 && d == -1f64 {break;}
        let h1 = Angle::from_degree(a);
        let h2 = Angle::from_degree(c);
        let v1 = Angle::from_degree(b);
        let v2 = Angle::from_degree(d);
        let rad = (h1.sin * h2.sin + h1.cos * h2.cos * Angle::from_degree((b - d).abs()).cos).acos();
        println!("{}", (rad * radius + 0.5) as i32);
    }
}



Measured memory_bytes: 5204
import itertools

n = int(input())
v = [int(w) for w in input().split()]
assert len(v) == n

def elem_count(ls):
    '''Return the list of (num of elem, elem).'''
    ls.sort()
    ls = itertools.groupby(ls)
    cs = [(len(list(s)), e) for e, s in ls]
    cs.sort(reverse=True)
    return cs

e = [v[i] for i in range(0, n, 2)]
o = [v[i] for i in range(1, n, 2)]

e = elem_count(e)
o = elem_count(o)

if e[0][1] != o[0][1]:
    ans = n - (e[0][0] + o[0][0])

elif len(e) == len(o) == 1:
    ans = n - e[0][0]

elif len(e) == 1:
    ans = n - (e[0][0] + o[1][0])

elif len(o) == 1:
    ans = n - (e[1][0] + o[0][0])

elif e[0][0] + o[1][0] > e[1][0] + o[0][0]:
    ans = n - (e[0][0] + o[1][0])
else:
    ans = n - (e[1][0] + o[0][0])

print(ans)


Measured memory_bytes: 15256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N,M; R(N,M);
    if(N>M)swap(N,M);
    if(N==1){
        if(M==1)W(1);
        else W(M-2);
    }
    else{
        W((N-2)*(M-2LL));
    }
    return 0;
}


Measured memory_bytes: 256