akhauriyash/Code-Regression huggingface dataset:
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;

////////////////////////////////////////////////

fn main(){
    let inputs = read_ints();
    let  a = inputs[0];
    let  b = inputs[1];
    let  ab = inputs[2];
    let mut x = inputs[3];
    let mut y = inputs[4];
    let mut ans = 0;
    
    if a+b>2*ab{
        let m = cmp::min(x,y);
        ans += m * ab * 2;
        x -= m;
        y -= m;
        // println!("buy ab {}",m);
    }

    if a > 2*ab{
        ans += x * ab * 2;
        // println!("bu ab {}",x);
        y = cmp::max(0,y-x);
        x = 0;
    }
    if b > 2*ab{
        ans += y * ab * 2;
        // println!("bu ab {}",y);
        x = cmp::max(0,x-y);
        y = 0;
    }

    ans += x * a;
    ans += y * b;

    println!("{}",ans);

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#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 repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const {
    return pow(MOD - 2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];
  vector<ll> y(m);
  rep(i, m) cin >> y[i];

  mint row = 0;
  rep(i, n - 1) {
    mint temp = x[i + 1] - x[i];
    temp *= i + 1;
    temp *= n - (i + 1);
    row += temp;
  }

  mint ans = 0;
  rep(i, m - 1) {
    mint temp = y[i + 1] - y[i];
    temp *= i + 1;
    temp *= m - (i + 1);
    ans += row * temp;
  }

  cout << ans.x << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int a, b, x;
	char op;
	x=0;
	while(1)
	{
		scanf("%d %c %d", &a, &op, &b);
		if(op=='+')
		{
			x=a+b;
			printf("%d\n", x);
		}
		else if(op=='-')
		{
			x=a-b;
			printf("%d\n", x);
		}
		else if(op=='*')
		{
			x=a*b;
			printf("%d\n", x);
		}
		else if(op=='/')
		{
			x=a/b;
			printf("%d\n", x);
		}
		else
		{
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 2636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int A,B; cin >> A >> B;
    if(A > B) swap(A,B);
    VI f(3);
    f[A-1]++;
    f[B-1]++;
    REP(i,3){
        if(f[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }

}


Measured memory_bytes: 256
N = int(input())
S = {}
for _ in range(N):
  s = "".join(sorted(input()))
  if not s in S: S[s] = 0
  else: S[s] += 1

ans = 0
for v in S.values():
  if v < 2: ans += v
  else: ans += v * (v+1) // 2
print(ans)

Measured memory_bytes: 17852
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    ld a, b; cin >> a >> b; a *= b; cout << (ll) a;
}


Measured memory_bytes: 3748
s=input().split("T")
x,y=map(int,input().split())
A=[]
B=[]
for i,j in enumerate(s):
    if i%2==0:
        A.append(len(j))
    else:
        B.append(len(j))
T=max([sum(A),sum(B),abs(x),abs(y)])
X=len(A)
Y=len(B)
if abs(x)+abs(y)>sum(A)+sum(B):
    print("No")
    exit()
dpx=[[False for i in range(2*T+1)] for _ in range(X+1)]
dpy=[[False for i in range(2*T+1)] for _ in range(Y+1)]
dpx[0][T]=True
dpy[0][T]=True
for l in range(X):
    for i in range(2*T+1):
        if dpx[l][i]:
            dpx[l+1][i+A[l]]=True
            if l==0:
                continue
            dpx[l+1][i-A[l]]=True
for r in range(Y):
    for i in range(2*T+1):
        if dpy[r][i]:
            dpy[r+1][i-B[r]]=True
            dpy[r+1][i+B[r]]=True
if dpx[X][x+T] and dpy[Y][y+T]:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 307080
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

const ll MaxN=201001;


ll Count[MaxN];

int main(){
    ll N; cin>>N;
    vec d;
    rep(i,N){
        ll x; cin>>x;
        x--;
        Count[x]++;
        d.pb(x);
    }
    ll ans=0;
    rep(i,N) {
        ll y=Count[i];
        ans+=(y*(y-1))/2;
    }

    rep(i,N) cout<<ans-Count[d.at(i)]+1<<endl;

}

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

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

  int n;
  cin >> n;

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

  vector<int> v(200000, 0);
  for (int i = 0; i < n; i++) {
    int num = a[i];
    if (num == 0) {
      v[0]++;
      v[1]++;
    } else {
      v[num]++;
      v[num + 1]++;
      v[num - 1]++;
    }
  }

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

  cout << v[0] << endl;

  return 0;
}

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

int main(){
  string s;
  bool isgood = true;
  cin >> s;
  for(int i=0;i<4;i++){
    if(s[i]==s[i+1]) isgood = false;
  }
  if(isgood){
    cout << "Good" << endl;
  }else{
    cout << "Bad" << endl;
  }
}

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

const int nmax = 50;
int a[nmax], b[nmax];

bool find(std::vector<int> v, int i){
    bool found = (std::find(v.begin(), v.end(), i) != v.end());
    return found;
}

bool isBridge(int idx){
    int start = a[idx];

    std::vector<int> visited;
    std::queue<int> que;
    que.push(start);
    visited.push_back(start);

    while (!que.empty()){
        int now = que.front();
        que.pop();
        for (int i=0; i<nmax; i++){
            if (idx==i) continue;
            if (now==a[i] && !find(visited, b[i])){
                que.push(b[i]);
                visited.push_back(b[i]);
            }
            if (now==b[i] && !find(visited, a[i])){
                que.push(a[i]);
                visited.push_back(a[i]);
            }
        }
    }
    return !find(visited, b[idx]);
}

int main(){
    int N, M;
    cin >> N >> M;
    for (int i=0; i<M; i++){
        cin >> a[i] >> b[i];
    }
    int numBridge = 0;
    for (int idx=0; idx<M; idx++){
        numBridge += isBridge(idx);
    }
    cout << numBridge << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1010;
int n, k, ans;
int x, y;
char c;
int psum[N * 2][N * 2];

inline int f(int x1, int y1, int x2, int y2) {
    return psum[x2][y2] - psum[x2][y1] - psum[x1][y2] + psum[x1][y1];
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> c;
        x %= (2 * k);
        y %= (2 * k);
        if (c == 'W')
            y = (y + k) % (2 * k);
        ++psum[x + 1][y + 1];
    }
    for (int i = 1; i <= k * 2; ++i) {
        for (int j = 1; j <= k * 2; ++j) {
            psum[i][j] += psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1];
        }
    }
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= k; ++j) {
            int sum = f(0, 0, i, j) + f(i, j, k + i, k + j) + f(k + i, k + j, 2 * k, 2 * k)
                    + f(k + i, 0, 2 * k, j) + f(0, k + j, i, 2 * k);
            ans = max(ans, max(n - sum, sum));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19448
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w; cin >> h >> w;
    vector<string> f(h); for(auto& e : f) cin >> e;

    vector<vi> memo_hor(h, vi(w));
    vector<vi> memo_ver(h, vi(w));

    int res = 0;
    rep(i, h){
        rep(j, w){
            if(f[i][j] == '#') continue;
            if(memo_hor[i][j] == 0){
                int cnt = 0;
                rep(k, w - j){
                    if(f[i][j + k] == '#') break;
                    cnt++;
                }
                rep(k, cnt) memo_hor[i][j + k] = cnt;
            }
            if(memo_ver[i][j] == 0){
                int cnt = 0;
                rep(k, h - i){
                    if(f[i + k][j] == '#') break;
                    cnt++;
                }
                rep(k, cnt) memo_ver[i + k][j] = cnt;
            }
            chmax(res, memo_hor[i][j] + memo_ver[i][j] - 1);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  string s;
  int w;
  cin >> s >> w;
  for(int i = 0;i < s.size();i+=w){
    cout << s.substr(i,min((int)s.size() - i,w))[0];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846



int main(){
	int n,i,j,k,u,v;
	cin>>n;
	vii a(n,vi(n,0));
	loop(i,0,n){
		cin>>u>>k;
		loop(j,0,k){
			cin>>v;
			a[u-1][v-1]=1;
		}
	}
	loop(i,0,n){
		loop(j,0,n){
			cout<<a[i][j];
			if(j!=n-1){
				cout<<" ";
			}else{
				cout<<endl;
			}
		}
	}
}

Measured memory_bytes: 3180
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s; cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

int N;
int A[310][310];
int L[310*310];
int U[310*310], V[310*310];
int idx[310*310];
int n;
long long A2[310][310];
int ok;
long long res;

int cmp(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	return L[i1] - L[i2];
}

void solve()
{
	int i, j, k;
	n = 0;
	for(i=0; i<N; i++){
		for(j=i+1; j<N; j++){
			L[n] = A[i][j];
			U[n] = i;
			V[n] = j;
			n ++;
		}
	}
	for(i=0; i<n; i++)
		idx[i] = i;
	qsort(idx, n, sizeof(int), cmp);
	for(i=0; i<N; i++){
		for(j=0; j<N; j++){
			if(i==j)
				A2[i][j] = 0;
			else
				A2[i][j] = -1;
		}
	}
	res = 0;
	ok = 1;
	int u, v, l;
	for(k=0; k<n; k++){
		u = U[idx[k]];
		v = V[idx[k]];
		l = L[idx[k]];
		if(A2[u][v] != -1 && A2[u][v] < l){
			ok = 0;
			return ;
		}
		if(A2[u][v]!=-1 &&  A2[u][v]==l) 
			continue;
		A2[u][v] = l;
		A2[v][u] = l;
		res += l;
		for(i=0; i<N; i++){
			for(j=i+1; j<N; j++){
				if(A2[i][u]!=-1 && A2[v][j]!=-1){
					if(A2[i][j]==-1 || A2[i][u]+l+A2[v][j] < A2[i][j])
						A2[i][j] = A2[j][i] = A2[i][u]+l+A2[v][j];
				}
				if(A2[i][v]!=-1 && A2[u][j]!=-1){
					if(A2[i][j]==-1 || A2[i][v]+l+A2[u][j] < A2[i][j])
						A2[i][j] = A2[j][i] = A2[i][v]+l+A2[u][j];
				}
			}
		}
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	int i, j;
	scanf("%d", &N);
	for(i=0; i<N; i++){
		for(j=0; j<N; j++){
			scanf("%d", &A[i][j]);
		}
	}
	solve();
	if(ok==0)
		printf("-1\n");
	else
		printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1996
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
struct tree{int left,right,parent;};
tree t[26];
int height[26];
char type;
int root;
int Height(int v){
  int ret_l=0,ret_r=0;
  if(t[v].left!=-1)ret_l=Height(t[v].left)+1;
  if(t[v].right!=-1)ret_r=Height(t[v].right)+1;
  height[v]=max(ret_l,ret_r);
  return height[v];
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)t[i].parent=-1;
  for(int i=0;i<n;i++){
    int l,r,id;
    cin >> id >>  l >> r;
    t[id].left=l;t[id].right=r;
    t[l].parent=id;t[r].parent=id;
  }
  
  for(int i=0;i<n;i++)if(t[i].parent==-1)root=i;
  Height(root);
  
  for(int i=0;i<n;i++){
    int par,sib,deg=0,dep,hei;
    par=t[i].parent;
    if(i==root)sib=-1;
    else if(t[t[i].parent].left==i)sib=t[t[i].parent].right;
    else sib=t[t[i].parent].left;

    if(t[i].left!=-1) deg++;
    if(t[i].right!=-1)deg++;
    dep=0;
    int temp_par=t[i].parent;
    while(1){
      if(temp_par==-1)break;
      dep++;
      temp_par=t[temp_par].parent;
    }
    hei=height[i];
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,par,sib,deg,dep,hei);
    
     if(i==root)printf("root\n");
     else if(height[i]==0)printf("leaf\n");
     
     else printf("internal node\n");
  }
  return 0;
}

Measured memory_bytes: 3168
package main

import (
	"fmt"
	"sort"
)

type Asc []int

func (a Asc) Len() int           { return len(a) }
func (a Asc) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Asc) Less(i, j int) bool { return a[i] < a[j] }

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	var X []int
	for i := 0; i < M; i++ {
		var x int
		fmt.Scan(&x)
		X = append(X, x)
	}

	sort.Sort(Asc(X))

	var D []int
	for i := 0; i < M-1; i++ {
		d := X[i+1] - X[i]
		D = append(D, d)
	}

	sort.Sort(Asc(D))

	c := 0
	for i := 0; i < M-1-(N-1); i++ {
		c += D[i]
	}
	fmt.Println(c)
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, K;
	int R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;
	int ans = 0;
	
	string U = T;
	REP(i, N) {
		if (T[i] == 'r') {
			if (i >= K && T[i - K] == 'r' && U[i - K] == 'o') {
				U[i] = 'x';
				continue;
			}
			ans += P;
			U[i] = 'o';
		}
		if (T[i] == 's') {
			if (i >= K && T[i - K] == 's' && U[i - K] == 'o') {
				U[i] = 'x';
				continue;
			}
			ans += R;
			U[i] = 'o';
		}
		if (T[i] == 'p') {
			if (i >= K && T[i - K] == 'p' && U[i - K] == 'o') {
				U[i] = 'x';
				continue;
			}
			ans += S;
			U[i] = 'o';
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

const ll mod=1e9+7;

int main(){
    ll n,k,sum=0;
    cin>>n>>k;
    for(ll i=k;i<=n+1;i++){
        sum+=i*(n-i+1)+1;
        sum%=mod;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
import heapq as hq

n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(1, n+1)]
p = list(zip(a, b))

q = []
hq.heapify(q)
for i in range(len(p)):
    hq.heappush(q, p[i])

while len(q) != 0:
    print(q[0][1], end=' ')
    hq.heappop(q)


Measured memory_bytes: 19960
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
//#include <complex>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e9;
//const ll MOD = 1e9 + 7;
//const double EPS = 1e-9;
//const double PI = acos(-1);
 
void solve() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if (x != i)
            ++cnt;
    }
    if (cnt == 0 || cnt == 2)
        cout << "YES";
    else 
        cout << "NO";
}   
 
 
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); 
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int mi[(1<<26)];
int dp[200020];

const int INF=1e8;

int main(){
  string s;
  cin>>s;
  int n=s.size();

  vector<int> x;
  x.push_back(0);
  int two=1;
  for(int i=1;i<=26;i++){
      x.push_back(two);
      two*=2;
  }
  
  for(int i=0;i<(1<<26);i++) mi[i]=INF;

  dp[0]=0;
  mi[0]=0;
  int now=0;
  for(int i=0;i<n;i++){
      now=now^(1<<(s[i]-'a'));
      int res=INF;
      for(int j=0;j<x.size();j++){
          int target=now^x[j];
          if(mi[target]==INF) continue;
          res=min(res,mi[target]+1);
      }
      dp[i+1]=res;
      mi[now]=min(mi[now],dp[i+1]);
  }
  cout<<dp[n]<<endl;


  return 0;
}


Measured memory_bytes: 263556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

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

	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	ll n,k,s,z;
	cin>>n>>k>>s;
	for(ll i=1;i<=k;i++)
		cout<<s<<" ";
	if(s==1000000000)
		z=1;
	else
		z=s+1;

	for(ll i=k+1;i<=n;i++)
	{
		cout<<z<<" ";
	}

	
	
}


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

using namespace std;

using matrix = vector< vector< int > >;

const int MOD = 1e9 + 7;

matrix multiply(matrix a, matrix b) {
	int n = a[0].size();

	matrix ret(n, vector< int >(n));

	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			for(int k = 0; k < n; ++k) {
				ret[i][j] = (ret[i][j] + (1ll*a[i][k] * b[k][j] % MOD)) % MOD;
			}
		}
	}

	return ret;
}
int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    int n;
    cin >> n;

    long long k;
    cin >> k;
    matrix a(n, vector< int >(n));
    matrix ans(n, vector< int >(n));

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

    	ans[i][i] = 1;
    }


    while(k) {
    	if(k&1) ans = multiply(ans, a);
    	a = multiply(a, a);
    	k >>= 1;
    }

    long long sum = 0;
    for(auto &x : ans) 
    	for(auto &y : x) sum = (sum + y) % MOD;

   cout << sum << '\n';
}   	

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np

s = input()
n = len(s) + 1

less = np.zeros(n)
more = np.zeros(n)

for i, (ch, ct) in enumerate(zip(s, s[::-1])):
    if ch == '<':
        more[i+1] = more[i] + 1
    if ct == '>':
        less[n-i-2] = less[n-i-1] + 1

rst = [max(m, l) for m, l in zip(more, less)]
print(int(sum(rst)))


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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> as(m), bs(m);
	for (int i = 0; i < m; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}

	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++)
	{
		g[as[i]].emplace_back(bs[i]);
		g[bs[i]].emplace_back(as[i]);
	}

	int inf = (1 << 29);

	vector<int> ans(n, -1), dist(n, inf);

	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;

	dist[0] = 0;
	for (auto &&next : g[0])
	{
		dist[next] = 1;
		ans[next] = 0;

		pq.emplace(dist[next], next);
	}

	while (!pq.empty())
	{
		int d = pq.top().first;
		int i = pq.top().second;
		pq.pop();

		if (dist[i] < d)
		{
			continue;
		}

		for (auto &&next : g[i])
		{
			if (dist[next] <= dist[i] + 1)
			{
				continue;
			}

			dist[next] = dist[i] + 1;
			ans[next] = i;

			pq.emplace(dist[next], next);
		}
	}

	cout << "Yes" << endl;
	for (int i = 1; i < n; i++)
	{
		ans[i]++;

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

	return 0;
}

Measured memory_bytes: 12616
N = gets.to_i
xys = N.times.map { gets.split.map(&:to_i) }

def dfs(cand, pos, sum)
  return sum if cand.empty?
  x1, y1 = pos
  cand.reduce(0) do |acc, pos2|
    tmp = cand.dup
    tmp.delete(pos2)
    x2, y2 = pos2
    d = Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
    acc += dfs(tmp, pos2, sum + d)
  end
end

sum = 0.to_f
xys.each do |pos|
  tmp = xys.dup
  tmp.delete(pos)
  sum += dfs(tmp, pos, 0)
end
ans = sum / (1..N).reduce(:*)
puts ans


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

LL A[MAX];
LL B[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		A[i] = x;
		B[i] = y;
	}

	LL cnt = 0;
	RFOR(i, n, 0)
	{
		LL cur = A[i] + cnt;
		LL x = cur / B[i] * B[i];
		if (x < cur) x += B[i];

		cnt += x - cur;
	}

	cout<<cnt<<endl;

}


Measured memory_bytes: 1920
N = int(input())
R = [None] * (N+1)

R[0] = 2
if N == 0:
    print(R[0])
    exit()
R[1] =1
if N == 1:
    print(R[1])
    exit()
if N >= 2:
    for i in range(2, N+1):
        R[i] = R[i-1] + R[i-2]
    print(R[N])

Measured memory_bytes: 9032
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0)
      break;
    int a[1000];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int dif = 1000001;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        int d=abs(a[i]-a[j]);
        if(d<dif){
          dif=d;
        }
      }
    }
    cout << dif << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}



  


int main() {
  int l,r,d;
  cin >> l >> r >> d;
  int cnt=0;
  for (int i = l;i <=r;i++){
    if (i%d==0) cnt++;
  }
  cout << cnt << endl;
}




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

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.size();
    ve<int> s0(n),t0(n);
    ve<int> sj(26,-1),tj(26,-1);
    int cnt = 0;
    rep(i,n){
        int j = s[i]-'a';
        if(sj[j] != -1) s0[i] = sj[j];
        else{
            sj[j] = cnt;
            cnt++;
            s0[i] = sj[j];
        }
    }
    cnt = 0;
    rep(i,n){
        int j = t[i] - 'a';
        if(tj[j] != -1) t0[i] = tj[j];
        else{
            tj[j] = cnt;
            cnt++;
            t0[i] = tj[j];
        }
    }
    if(s0 == t0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 5444
#include<iostream>
using namespace std;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int N,M,a,b;
int t[30][30];

void init(){
  for(int i=0;i<30;i++)
    for(int j=0;j<30;j++)
      t[i][j]=0;
}
int main(){
  while(1){
    cin>>N;
    if(N==0)break;
    init();
    for(int i=0;i<N;i++){
      cin>>a>>b;
      t[b][a]=1;
    }
    cin>>M;
    int y=10,x=10,ans=0;
    for(int i=0;i<M;i++){
      char ch;
      cin>>ch>>a;
      if(ch=='N')b=2;
      if(ch=='S')b=0;
      if(ch=='E')b=1;
      if(ch=='W')b=3;
      for(int j=0;j<a;j++){
	y+=dy[b];
	x+=dx[b];
	if(t[y][x])ans++,t[y][x]=0;
      }
    }
    cout<<(N==ans?"Yes":"No")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
//https://atcoder.jp/contests/abc122/submissions/5866378


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>


using namespace std;
int main(){
	string b,ans;
	cin>>b;
	if(b=="A")ans="T";
	if(b=="T")ans="A";
	if(b=="G")ans="C";
	if(b=="C")ans="G";
	
	cout<<ans<<endl;

}


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

int main(){
  int n,k; cin>>n>>k;
  string s; cin>>s;
  
  int happy=0;
  int cnt=0;
  
  for (int i=0; i<n-1; i++){
    if (s[i]==s[i+1]) happy+=1;
    else cnt+=1;
  }
  
  cout<<min(n-1,happy+min(cnt,k)*2)<<endl;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    int ans;
    for(int i=1;i<=11000;i++) {
        double c = i*0.08;
        double d = i*0.1;
        if((int)c == a && (int)d == b){
            ans = i;
            cout << ans << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

Measured memory_bytes: 256
/* _    _       _       _   __________
  | |  | |     /_\     | | |____  ____|
  | |__| |    //_\\    | |      | |
  |  __  |   / ___ \   | |      | |
  | |  | |  / /   \ \  | |      | |
  |_|  |_| /_/     \_\ |_|      |_|*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
const ll mod=1e9+7;

int main()
{
    ll n,i,j,s=0,c=0,k=0;
    string ss,tt;
    cin>>ss>>tt;
    tt=tt.substr(0,tt.size()-1);
    if(ss==tt) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3628
s = input()
n = len(s)

mod = 2019
cnt = [0] * mod
cnt[0] = 1
digit = 1
now = 0

for i in range(1, n + 1):
    now += int(s[-i]) * digit
    digit *= 10
    digit %= mod
    now %= mod
    cnt[now] += 1

ans = 0
for i in cnt:
    ans += i * (i - 1) // 2

print(ans)


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define RREP(i, a, n) for(int i = (int)(n); i >= a; i--)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    priority_queue<ll, vector<ll>, greater<ll> > ans;
    REP(i, 1, 10) ans.push(i);

    rep(i, K-1)
    {
        ll key = ans.top();
        ans.pop();
        ans.push( key*10 + key%10 );
        if( key%10 != 0 ) ans.push( key*10 + key%10-1);
        if( key%10 != 9 ) ans.push( key*10 + key%10+1);
    }
    cout << ans.top() << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

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

	string N;
	cin >> N;

	if (N == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;

	}

	//cout << ans << endl;
	//printf("%.11lf\n",ans);

	return 0;
}

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

const int inf = 100000009;

struct  edge{
    int to;
    int cost;
};

vector<edge> vec[200001];
int x[200001];

void dfs(int point, int prev, int cost){
    x[point] = cost;

    for(int i=0; i<vec[point].size(); i++){
        if(x[vec[point][i].to] != inf){
            continue;
        }
        dfs(vec[point][i].to, point, cost + vec[point][i].cost);
    }
}

int main() {

    int n,m;

    cin >> n >> m;

    for(int i=0; i<200001; i++){
        x[i] = inf;
    }

    int l[m],r[m],d[m];

    for(int i=0; i<m; i++){
        cin >> l[i] >> r[i] >> d[i];
        edge e;
        e.to = r[i]; e.cost = d[i];
        vec[l[i]].push_back(e);
        e.to = l[i]; e.cost = -d[i];
        vec[r[i]].push_back(e);
    }

    for(int i=0; i<m; i++){
        if (x[r[i]] == inf) {
            dfs(l[i], -1, 0);
        }
    }

    string ans = "Yes";

    for(int i=0; i<m; i++){
        if(x[r[i]] - x[l[i]] != d[i]){
            ans = "No";
            break;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
int main(void)
{
    init();
    int S,W;
    cin>>S>>W;
    if(W>=S)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
}


Measured memory_bytes: 3644
n = int(input())

def dfs(count, s):
	if int(s) > n:
		return count
	if '3' in s and '5' in s and '7' in s:
		count += 1
	for c in '357':
		count = dfs(count, s+c)
	return count

print(dfs(0, '0'))



Measured memory_bytes: 2940
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed

main :: IO ()
main = do
  n <- getl toInt
  solve n 0

solve :: Int -> Int -> IO ()
solve n i = do
  unless (i == n) $ do
    unless (i == 0) $ putStrLn ""
    m <- getl toInt
    mapM_ putStrLn $ sp m
    solve n (i+1)

sp :: Int -> [String]
sp n = toPtn n $ elems (f iar n 1)
  where
    iar = listArray ((1,1),(n,n)) (repeat ' ') :: UArray (Int,Int) Char
    f :: UArray (Int,Int) Char -> Int -> Int -> UArray (Int,Int) Char
    f ar m i
      | m <= 4 = ar // (zip (g m i) (repeat '#'))
      | otherwise = f (ar // (zip (g m i) (repeat '#'))) (m-4) (i+2)
    g m i
      | m == 1 = [(i,i)]
      | m == 2 = [(i,i),(i+1,i),(i,i+1)]
      | m == 3 = [(i,i),(i+1,i),(i+2,i),(i,i+1),(i,i+2),(i+1,i+2),(i+2,i+2)]
      | m == 4 = [(i+j,i)| j <- [0..3]] ++ [(i,i+j)| j <- [1..3]] ++ [(i+j,i+3)| j <- [1..3]] ++ [(i+3,i+2)]
      | otherwise = [(i+j,i)| j <- [0..m-1]] ++ [(i,i+j)| j <- [1..m-1]] ++ [(i+j,i+m-1)|j <- [1..m-1]] ++ [(i+m-1,i+j)| j <- [2..m-2]] ++ [(i+m-2,i+2)]

toPtn :: Int -> String -> [String]
toPtn n [] = []
toPtn n xs = take n xs : toPtn n (drop n xs)

toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

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

  if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ||
      (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ||
      (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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


int main() {
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i]; 
    bool flag = true;

    for (int i = n - 1; i >= 1 ; i--) {
        if (h[i] >= h[i - 1]) continue;
        else if (h[i] == h[i - 1] - 1) h[i - 1] = h[i - 1] - 1;
        else {
            flag = false;
            break;
        }
    }

    if (flag) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  while(true){
    int n,k;
    scanf("%d %d",&n,&k);
    if(n==0&&k==0) return 0;
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    int sum = 0,ans = 0;
    for(int i=0;i+k<=n;i++){
      if(i==0){
        for(int j=0;j<k;j++) sum += a[i+j];
        ans = sum;
      }else{
        sum = sum - a[i-1] + a[i+k-1];
        ans = max(ans,sum);
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
//#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e9;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

using Weight=int;
struct Edge{
  int src,dst;
  Weight weight;
  Edge():src(0),dst(0),weight(0){}
  Edge(int s,int d,Weight w=0):src(s),dst(d),weight(w){}
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;
const Weight inf=numeric_limits<Weight>::max()/8;
pair<vector<Weight>,bool> BellmanFord(const Graph&g,int src){
  int n=g.size();

  Edges es;
  for(int i=0;i<n;i++){
    for(auto &e:g[i])es.emplace_back(e);
  }
  vector<Weight> dis(n,inf);
  dis[src]=0;
  bool Negative_cycle=false;
  for(int i=0;;i++){
    bool update=false;
    for(auto&e:es){
      if(dis[e.src]!=inf&&dis[e.dst]>dis[e.src]+e.weight){
        dis[e.dst]=dis[e.src]+e.weight;
        update=true;
      }
    }
    if(!update)break;
    if(i>n){
      Negative_cycle=true;
      break;
    }
  }
  return {dis,Negative_cycle};
}

int main(){
  int V,E,r;
  cin>>V>>E>>r;
  Graph g(V);
  rep(i,E){
    int s,t,d;
    cin>>s>>t>>d;
    g[s].emplace_back(s,t,d);
  }
  pair<vector<int>,bool> ans=BellmanFord(g,r);
  if(ans.second){
    cout<<"NEGATIVE CYCLE"<<endl;
    return 0;
  }
  rep(i,V){
    if(ans.first[i]==inf){
      cout<<"INF"<<endl;
    }else{
      cout<<ans.first[i]<<endl;
    }
  }


 return 0;
}



Measured memory_bytes: 3232
const teststr = 
"""
4
aaaa
a
aaa
aa
"""

function lines()
  Channel{String}(32) do ch
    ll = readlines()
    lines = isempty(ll) ? split(teststr, "\n") : ll
    for s in lines
      put!(ch, s)
    end
  end
end

quit() = exit(0)
in_1(ch) = parse(Int, take!(ch))
in_a(ch) = parse.(Int, split(take!(ch)))

function main()
  ch = lines()
  N = in_1(ch)
  [take!(ch) for i in 1:N] |> unique |> length |> println
end

main()


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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    map<int, int> MAP;
    //全てのi, j(i < j)に対し差分を取る
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            if (i == j) continue;
            int diff;
            if (i >= Y) diff = j-i;
            else if (i >= X && i <= Y && j >= Y) diff = min(i-X+1, Y-i) + j-Y;
            else if (i >= X && j <= Y) diff = min(j-i, i-X+1+Y-j);
            else if (i <= X && j >= X && j <= Y) diff = min(j-i, X-i+1+Y-j);
            else if (i <= X && Y <= j) diff = min(j-i, X-i+1+j-Y);
            else if (j <= X) diff = j-i;
            MAP[diff] ++;
        }
    }
    vector<int> ans(N);
    for (int i = 1; i < N; i++) {
        ans[i] = MAP[i];
    }
    for (int i = 1; i < N; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 384
def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
    
  return distance
 
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
 
if max(bfs(bfs(0).index(max(bfs(0)))))%3==1:
  print('Second')
else:
  print('First')

Measured memory_bytes: 137204
#include<bits/stdc++.h>
using namespace std;
int n,k,a;
main(){  
  cin>>n>>k;
  int l[n];
  for(int i=0;i<n;++i)cin>>l[i];
  sort(l,l+n);
  for(int i=n-1;i!=n-1-k;--i)a+=l[i];
  cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X,string Y ,int m, int n ) 
{ 
    int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<< lcs; 
} 
  
/* Driver program to test above function */
int main() 
{ 
string X;
string Y;
cin>>X;
cin>>Y;
  int m = X.size(); 
  int n = Y.size(); 
 
  lcs(X, Y, m, n); 
  return 0; 
} 

Measured memory_bytes: 38768
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        String S = sc.next();
	        char[] c = S.toCharArray();
	        int N=c.length;
	        int scnt=0;
	        int tcnt=0;
	        for(int i=0;i<c.length;i++) {
	        	if(c[i]=='S') {
	        		scnt++;
	        	} else if(scnt!=0) {
	        		scnt--;
	        	} else {
	        		tcnt++;
	        	}
	        }
	        
	        System.out.println(scnt+tcnt);
	        
	 }

}

Measured memory_bytes: 26508
#include<iostream>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
int main(void){
 
  int a,b,c,res[4]={};
 
  while(cin >> a >> b >> c){
    
    if(a+b<=c || a+c<=b || b+c<=a){

      for(int i=0;i<4;i++){
	cout << res[i];
	if(i<3)cout <<" ";
      }
      cout <<endl;
      break;
    }
    
    res[0]++;
    if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a)res[1]++;
    else if(a*a+b*b>=c*c && a*a+c*c>=b*b && b*b+c*c>=a*a)res[2]++;
    else res[3]++;
  } 
  return 0;
}

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

#define POS(i,j) ((i)*(n+1)+(j))

void initBIT(int *b){
  const int n=b[0];
  for(int i=1;i<=n;i++) b[i]=0;
}

void add(int *bit,int x,int v){
  const int n=bit[0];
  for(int i=x;i<=n;i+=i&-i) bit[i]+=v;
}

int sum(int *bit,int x){
  int res=0;
  for(int i=x;i>0;i-=i&-i) res+=bit[i];
  return res;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *b=(int *)calloc(n+1,sizeof(int));
  int *w=(int *)calloc(n+1,sizeof(int));
  int i,j;
  for(i=0;i<2*n;i++){
    char s[10];
    int k;
    scanf("%s%d",s,&k);
    if(s[0]=='B'){
      b[k]=i+1;
    } else {
      w[k]=i+1;
    }
  }
  int *dp=(int *)calloc((n+1)*(n+1),sizeof(int));
  int *bit=(int *)calloc(2*n+1,sizeof(int));
  bit[0]=2*n;
  dp[POS(0,0)]=0;
  for(i=1;i<=n;i++){
    add(bit,b[i],1);
    dp[POS(i,0)]=dp[POS(i-1,0)]+(i-sum(bit,b[i]));
  }
  initBIT(bit);
  for(j=1;j<=n;j++){
    add(bit,w[j],1);
    dp[POS(0,j)]=dp[POS(0,j-1)]+(j-sum(bit,w[j]));
  }
  for(i=1;i<=n;i++){
    initBIT(bit);
    for(j=1;j<=i;j++){
      add(bit,b[j],1);
    }
    for(j=1;j<=n;j++){
      add(bit,w[j],1);
      int p=dp[POS(i,j-1)]+(i+j-sum(bit,w[j]));
      int q=dp[POS(i-1,j)]+(i+j-sum(bit,b[i]));
      dp[POS(i,j)]=p<q?p:q;
    }
  }
  printf("%d\n",dp[POS(n,n)]);
  return;
}

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


Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
typedef long long int ll;
ll V, E, R, S[500010], T[500010], D[500010];
ll C[100010];

const int INF = INT_MAX;

int main()
{
    cin >> V >> E >> R;

    // 入力
    for (int i = 0; i < E; i++)
    {
        cin >> S[i] >> T[i] >> D[i];
    }

    for (int i = 0; i < V; i++)
    {
        C[i] = i == R ? 0 : INF;
    }

    for (int t = 0; t < V; t++)
    {
        bool update = false;
        for (int i = 0; i < E; i++)
        {
            ll s = S[i], t = T[i], d = D[i];
            if (C[s] < INF && C[s] + d < C[t])
            {
                C[t] = C[s] + d;
                update = true;
            }
        }
        if (!update)
            break;
    }

    for (int i = 0; i < V; i++)
    {
        if (C[i] == INF)
        {
            cout << "INF" << endl;
        }
        else
        {
            cout << C[i] << endl;
        }
    }
}


Measured memory_bytes: 15348