akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
signed main(){

	int N, P;
	cin>>N>>P;
	string S;
	cin>>S;

	ll ans=0;
	if(P==2 || P==5){
		for(int i=0;i<N;i++){
			int s=S[i]-'0';
			if(s%P==0)
				ans+=i+1;
		}
		cout<<ans<<endl;
		return 0;
	}

	reverse(S.begin(), S.end());
	vint A(1);
	int now=0, pot=1;
	for(int i=0;i<N;i++){
		int s=S[i]-'0';
		(pot*=10)%=P;
		now=(s*pot+now)%P;
		A.pb(now);
	}

	ll cnt[10001]={};
	for(int a:A)
		cnt[a]++;

	for(int i=0;i<P;i++)
		ans+=cnt[i]*(cnt[i]-1)/2;
	
	cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll a,b,c,d,e,f,n,m;
ll int t[105]={},sum,p,x,ans[105]={};

int main()
{
    cin >> n;
    for(int i=0; i<n; i++){
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    for(int i=0; i<m; i++){
        cin>>p>>x;
        ans[i]=sum-t[p-1]+x;
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define maxn 55
const double g=9.8;
double EPS=1e-6;
int N, V, X ,Y;
int L[maxn], B[maxn], R[maxn], T[maxn];
double calc(double vy, double t) {
    return vy*t-g*t*t/2;
}
int cmp(double lb, double ub, double a) {
    return a<lb+EPS?-1:a>ub-EPS?1:0;
}
bool check(double qx, double qy) {
    double a=g*g/4, b=g*qy-V*V, c=qx*qx+qy*qy;
    double D=b*b-4*a*c;
    if (D<0&&D>-EPS)
        D=0;
    if (D<0)
        return false;
    for (int d=-1; d<=1; d+=2) {
        double t2=(-b+d*sqrt(D))/(2*a);
        if (t2<=0)
            continue;
        double t=sqrt(t2);
        double vx=qx/t, vy=(qy+g*t*t/2)/t;
        double yt=calc(vy, X/vx);
        if (yt<Y-EPS)
            continue;
        bool ok=true;
        for (int i=0; i<N; i++) {
            if (L[i]>=X)
                continue;
            if (R[i]==X&&Y<=T[i]&&B[i]<=yt)
                ok=false;
            int yL=cmp(B[i], T[i], calc(vy, L[i]/vx));
            int yR=cmp(B[i], T[i], calc(vy, R[i]/vx));
            int xH=cmp(L[i], R[i], vx*(vy/g));
            int yH=cmp(B[i], T[i], calc(vy, vy/g));
            if (xH==0&&yH>=0&&yL<0)
                ok=false;
            if (yL*yR<=0)
                ok=false;
        }
        if (ok)
            return true;
    }
    return false;
}
void solve() {
    for (int i=0; i<N; i++)
        R[i]=min(R[i], X);
    bool ok=check(X, Y);
    for (int i=0; i<N; i++) {
        ok|=check(L[i], T[i]);
        ok|=check(R[i], T[i]);
    }
    puts(ok?"Yes":"No");
}
int main()
{
    scanf("%d%d%d%d", &N, &V, &X, &Y);
    for (int i=0; i<N; i++)
        scanf("%d%d%d%d", &L[i], &B[i], &R[i], &T[i]);
    solve();
    return 0;
}

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

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

    int n = s.size();
    vector<int> res(n + 1);
    int p = 1;
    rep(i, n){
        if (s[i] == '<'){
            res[i + 1] = p;
            p++;
        }else{
            p = 1;
        }
    }
    p = 1;
    for (int i = n - 1; i >= 0; i--){
        if (s[i] == '>'){
            res[i] = max(p, res[i]);
            p++;
        }else p = 1;
    }
    ll ans = 0;
    rep(i, n + 1) ans += (ll)res[i];
    cout << ans << endl;
}


Measured memory_bytes: 5800
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
using ll = long long;
using namespace std;
vector<vector<int>> vec;
vector<int> d_1;
vector<int> d_n;
vector<int> reg;
vector<int> reg1;
int n;
void dfs(int x){
    for(int i=0;i<vec[x].size();i++){
    if(reg[vec[x][i]]==0){
        reg[vec[x][i]]=1;
        d_1[vec[x][i]]=d_1[x]+1;
        dfs(vec[x][i]);
    }
    }
}
void dfs1(int x){
    for(int i=0;i<vec[x].size();i++){
    if(reg1[vec[x][i]]==0){
        reg1[vec[x][i]]=1;
        d_n[vec[x][i]]=d_n[x]+1;
        dfs1(vec[x][i]);
    }
    }
}
int main(){
    cin >> n;
    vec.resize(n+1);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    d_1.resize(n+1,1e9+7);
    d_n.resize(n+1,1e9+7);
    reg.resize(n+1);
    reg1.resize(n+1);
    d_1[1]=0;
    reg[1]=1;
    dfs(1);
    d_n[n]=0;
    reg1[n]=1;
    dfs1(n);
    int fe=0;
    int su=0;
  //  cout<<d_1[1]<<" "<<d_n[1]<<endl;
    for(int i=1;i<=n;i++){
        if(d_1[i]<=d_n[i]){
            fe++;
        //    cout<<"FE"<<i<<endl;
        }else{
            su++;
          //  cout<<"SU"<<i<<endl;
        }
    }
    if(su>=fe){
        cout<<"Snuke"<<endl;
    }else{
        cout<<"Fennec"<<endl;
    }
}


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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long
#define ALL(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define vi vector<int>

using namespace std;

double EPS = 1e-9;
int INF = 1e9+7;;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

clock_t first_attempt = clock();
inline void cek_time(){
	clock_t cur = clock()- first_attempt;
	cerr<<"TIME : "<<(double) cur/CLOCKS_PER_SEC<<endl;
}
inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of template

int n,m,d;

const int maxn = 3005;
int ret[maxn][maxn],buck[maxn][maxn];

char ans[maxn][maxn];
int main(){
    cin>>n>>m>>d;
    
    memset(buck,-1,sizeof buck);
    rep(k,0,d)rep(i,0,d)buck[k][i] = 0;
    rep(k,0,d)rep(i,0,d)buck[k+d][i] = 1;
    rep(k,0,d)rep(i,0,d)buck[k][i+d] = 2;
    rep(k,0,d)rep(i,0,d)buck[k+d][i+d] = 3;
    
    rep(k,0,maxn)rep(i,0,maxn)if(buck[k][i]==-1){
        if(k-2*d>=0)buck[k][i] = buck[k-2*d][i];
        if(i-2*d>=0)buck[k][i] = buck[k][i-2*d];
    }
    char s[4] = {'R','Y','G','B'};
    
    memset(ret,-1,sizeof ret);
    rep(k,0,n)rep(i,0,m){
        ans[k][i] = s[buck[k+i+505][k-i+505]];
    }
    
    rep(k,0,n)printf("%s\n",ans[k]);
}

Measured memory_bytes: 73088
#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 tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define endl "\n"
#define pii pair<int,int>
#define mii map<int,int>
#define int long long int
#define fbo find_by_order
#define ook order_of_key
#define in insert
#define F first
#define S second
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a) for(auto ws: a)cout<<ws<<" "; cout<<endl
#define print1(a,b) for(int ws=0;ws<b;ws++) {cout<<a[ws]<<" ";} cout<<endl
#define all(a) a.begin(), a.end()
#define si set<int>
#define print2(a) for(auto ws: a)cout<<"("<<ws.F<<","<<ws.S<<") "; cout<<endl

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
vpi v;
int cache[101][100001];
int n, allowed;
int dp(int index, int val, int w)
{
	if (index == n)return val;
	int &ans = cache[index][w];
	if (ans != -1)return ans;
	ans = 0;
	if (w + v[index].S > allowed)return ans = dp(index + 1, val, w);
	return ans = max(v[index].F + dp(index + 1, val, w + v[index].S), dp(index + 1, val, w));

}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cout << setprecision(9) << fixed;

	cin >> n >> allowed;
	v.resize(n);
	memset(cache, -1, sizeof(cache));
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i].S;
		cin >> v[i].F;
	}
	cout << dp(0, 0, 0);
	return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  if(b==1)
    cout<<3800+200*(a-b);
  if(b==2)
    cout<<15200+400*(a-b);
  if(b==3)
    cout<<45600+800*(a-b);
  if(b==4)
    cout<<121600+1600*(a-b);
  if(b==5)
    cout<<304000+3200*(a-b);
  
}

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

#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long 

int main(){
        IOS;
        string s;
        cin>>s;
        ll n=(int)s.size();
        ll ans=0;
        for(ll i=0;i<n;i++){
                char c=s[i];
                ll ct=0;
                if(c=='R'){
                while(s[i]=='R' && i<n)i++,ct++;
                ans=max(ans,ct);
                i--;
                }
        }
        cout<<ans<<"\n";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b,c;
		int ans=0;
		cin>>a>>b>>c;
		int y3=333-(a/3);
		int y1=999-y3-a;
		int d=0;
		if(a%3==0){
			d=(21-c)+(10-b)*20;
		}else{
			if(b%2==0){
				d=(20-c)+(10-b)*39/2;
			}else{
				d=(21-c)+19+(10-b-1)*39/2;
			}
		}
		cout<<y3*200+y1*195+d<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,n,k,i,j, q, b, c;
    cin >> n;
    vector<ll> v(n + 5, INT_MAX);
    map<ll, ll> m;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        m[v[i]]++;
        sum += v[i];
    }
    cin >>q;
    while(q--){
        cin >> b >> c;
        ll p = c * m[b];
        sum = sum - (m[b] * b) + p;
        m[c] += m[b];
        //cout <<"b: " <<  b << " c: " << c << " m[b]: " << m[b]<< " m[c]: " << m[c] << endl;
        m[b] = 0;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 9968
h,w,k=map(int,input().split())
r,s,t,u=map(lambda x:int(x)-1,input().split())
b=[input()for _ in range(h)]
l=[[-1]*w for _ in range(h)]
l[r][s]=0
from collections import*
d=deque([(r,s)])
while d:
  x,y=d.popleft()
  if(x==t)&(y==u):exit(print(l[x][y]))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@":break
      if 0<=l[p][q]<=l[x][y]:break
      if l[p][q]==-1:d+=[(p,q)];l[p][q]=l[x][y]+1
print(-1)

Measured memory_bytes: 93820
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;
use std::cmp;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(), 256);

    let n:usize = scan.next();
    let slp:Vec<(usize,usize,usize)> = (0..n).map(|_| (scan.next(),scan.next(),scan.next())).collect();

    let m:usize = scan.next();
    let w:Vec<usize> = (0..m).map(|_| scan.next()).collect();

    let mut answer = Vec::with_capacity(m);

    for i in 0..m {
        let mut dp:Vec<usize> = (0..(w[i]+1)).map(|_| 0).collect();

        for slp in &slp {
            for w in 0..(w[i]+1) {
				let k = slp.0;

				if w >= k {
					dp[w] = cmp::max(dp[w],dp[w-k] + slp.2);
				} else if w > k  && dp[w-k] == 0 {
					break;
				}
            }
        }

        if dp[w[i]] == 0 {
            println!("-1");
            return;
        }

        answer.push(dp[w[i]]);
    }

    for ans in answer {
        println!("{}",ans);
    }
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}




Measured memory_bytes: 5024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  /*
  int A, B;
  while (true) {
    cin >> A >> B;
    A ^= B;
    A ^= B;
    cout << A << endl;
  }*/
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  ll sum = 0;
  REP(i, N) { sum ^= a[i]; }
  REP(i, N) {
    ll ans = a[i] ^ sum;
    cout << ans <<" ";
  }
  cout << endl;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int 
#define mk make_pair

/*int main(){
   int x;cin>>x;
   if(x>=30)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    return 0;
}*/
/*int main(){
    ll n,d;
    cin>>n>>d;
    ll x[n],y[n];
    int ans=0;
    d=d*d;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        ll val=x[i]*x[i]+y[i]*y[i];
        if(d>=val)ans++;
    }
    cout<<ans<<endl;
    return 0;
}*/
int main(){
    int n;cin>>n;
    string s;cin>>s;
    int l=0;
    int r=s.length()-1;
    int cnt=0;
    while(l<r){
       while(s[l]!='W' && l<r){l++;}
       while(s[r]!='R' && l<r){r--;}
       if(l<r){swap(s[l],s[r]);cnt++;}
    }
    int f=0;
    for(int i=s.length()-1;i>=0;i--){
        if(f==0 && s[i]=='R')f=1;
        else if(f==1 && s[i]=='W')cnt++;
        
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <queue>

using namespace std;

int main(void) {
  int ans = 0;
  int tmp;
  priority_queue<int, vector<int>, greater<int>> que;
  for (int i = 0; i < 3; i++) {
    cin >> tmp;
    que.push(tmp);
  }

  int first = que.top();
  que.pop();

  int second = que.top();
  que.pop();

  ans += second - first;
  int third = que.top();
  ans += third - second;

  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrr
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = b - a;//b place

            //b high
            int bh = 0;
            for(int i = 1; i <= c; i++)
            {
                bh += i;
            }
            Console.WriteLine(bh - b);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 

int
main(int argc, char const *argv[])
{
    uint64_t n;
    cin >> n;
    cout << (n  * (n - 1)) / 2<< endl;
    return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
const int maxn = 1000;
int M[maxn][maxn], G[maxn][maxn];
typedef pair<int, int> PII;
queue<PII> Q;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
int n, m, k, sn, sm;
char ch;
int abs(int x) { return x < 0 ? -x : x; }
int getans(int y, int x){
    int d = min(y, n-y-1);
    d = min(d, x); d = min(d, m-x-1);
    if(d == 0) return 0;
    return (d-1)/k + 1;
}

int main()
{
    cin>>n>>m>>k;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin>>ch;
            if(ch == '#') G[i][j] = 1;
            else if(ch == 'S') { sn = i; sm = j; }
        }
    }
    M[sn][sm] = 1;
    Q.push(mp(sn, sm));
    while(!Q.empty()){
        PII s = Q.front(); Q.pop();
        for(int i = 0; i < 4; i++){
            int ty = s.fi + dy[i], tx = s.se + dx[i];
            if(ty < 0 || ty >= n) continue;
            if(tx < 0 || tx >= m) continue;
            if(G[ty][tx]) continue;
            if(abs(ty - sn) + abs(tx - sm) > k) continue;
            if(!M[ty][tx]){
                M[ty][tx] = 1;
                Q.push(mp(ty, tx));
            }
        }
    }
    int ans = 1e9;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++){
            if(M[i][j]){
                ans = min(ans, getans(i, j));
            }
        }
    cout<<ans+1<<endl;
}


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

using namespace std;

using ll = long long;

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

    int a, b;
    cin >> a >> b;
    int diff = b - a, h = diff * (diff + 1) / 2;
    cout << h - b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b==0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

ll comb(ll a,ll b){
    ll ans=1;
    for(ll i=a;i>a-b;i--){
        ans=ans*i%mod;
    }
    for(ll i=1;i<=b;i++){
        ans=(ans*rui(i,mod-2))%mod;
    }
    return ans;
}

int main(){
    
    int N,A,B,C,D;cin>>N>>A>>B>>C>>D;
    ll dp[1001][1001],p[1001];//i人以下のみ合計はj
    
    for(int i=0;i<1001;i++){
        for(int j=0;j<1001;j++){
            dp[i][j]=0;
        }
    }
    
    for(int i=0;i<1001;i++){
        if(i) p[i]=p[i-1]*i%mod;
        else p[i]=1;
    }
    
    for(int i=0;i<A;i++){
        dp[i][0]=1;
    }
    
    for(int i=A;i<=B;i++){
        for(int j=0;j<=N;j++){
            dp[i][j]=dp[i-1][j];
            for(int k=C;k<=min(D,j/i);k++){
                if(j-k*i<0) continue;
                dp[i][j]+=dp[i-1][j-i*k]*p[N-(j-i*k)]%mod*rui(p[N-j]*rui(p[i],k)%mod*p[k]%mod,mod-2)%mod;
                dp[i][j]=dp[i][j]%mod;
            }
        }
    }
    
    cout<<dp[B][N]<<endl;
    
}



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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  int sqr = sqrt(n);
  ll ans = 0;
  
  bool prime_num = false;
  for(int i = 2; i <= sqr; ++i) {
    if(n % i == 0) {
      prime_num = true;
    }
  }
  // 素数である
  if(!prime_num) {
    ans = n - 1;
  }
  // 素数でない
  else {
    while(n % sqr != 0) {
      --sqr;
    }
    ans = (sqr-1) + ((n/sqr) - 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
using namespace std;
int n,sums[200010];
double ans=0;
int main(){
	cin>>n;
	for(int i=1;i<=n<<1;++i)cin>>sums[i];
	sort(sums+1,sums+1+n*2);
	for(int i=1;i<=n<<1;++i)
		ans+=1.0*(i-1)*sums[i]/(2*n-1);
	printf("%.15lf\n",ans);
	return 0;
}

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

int p[100000];
int c , n;
bool check(int x){
	for(int i = 0;i < 100000;i++){
		if(p[i] == 0)return true;
		if(x % p[i] ==0)return false;
	}
	return true;
}

void set(){
	p[0] = 2;
	c = 1;
	for(int i = 3;i < 123456 * 2;i+=2){
		if(check(i)){
			p[c] = i;
			c++;
		}
	}
}
bool input(){
	cin >> n;
	return n !=0;
}

int find(int num){
		if(num == 1)return -1;
		int u = c;
		int l = 0;
		int x;
		while(u - l> 1){
			x = floor((u + l)/2);
			if(num < p[x]) u = x;
			else if(p[x] < num)l = x;
			else if(p[x] == num){
				//	cout << l << ' '<< p  <<endl;
					return x;
			}
		//cout << p[l] << ' ' << p[u] << endl;
		}
		return l;
}
int find2(int num){
		int u = c;
		int l = 0;
		int x;
		while(u - l > 1){
			x = floor((u + l)/2);
			if(num < p[x]) u = x;
			else if(p[x] < num)l = x;
			else if(p[x] == num)return x;
		}
		return u;
}

void solve(){
	int a = find(n);
	int b = find2(2*n);
	//cout << b << ' ' << a  <<endl;
	cout << b - a - 1<< endl;
}
int main(){
	set();
//	for(int i = 0; p[i] != 0;i++)cout << p[i] << endl;
//	cout << c <<endl;
	while(input())solve();
	 
}



Measured memory_bytes: 3156
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <iostream>

using namespace std;

char al[12], r[1001], l[1001], tl[1001], tr[1001], f[11];

int calc(int c,char *s){
	int ret = 1;
	if(s[c] == '('){
		int i, j = 0;
		for(i = c;(!(s[i] == '-' && s[i + 1] == '>') && s[i] != '+' && s[i] != '*') || j != 1;i++){
			if(s[i] == '(') j++;
			else if(s[i] == ')') j--;
		}
		if(s[i] == '-')
			return !calc(c + 1,s) || calc(i + 2,s);
		else if(s[i] == '+')
			return calc(c + 1,s) || calc(i + 1,s);
		else if(s[i] == '*')
			return calc(c + 1,s) && calc(i + 1,s);
	}
	else if(isdigit(s[c]))
		return s[c] - '0';
	else if(s[c] == '-' && s[c + 1] != '>')
		return (calc(c + 1,s) + 1) % 2; 
}

int dfs(int c){
	int ret = 1;
	unsigned int i, j;
	if(c == strlen(al)){
		strcpy(tl,l);
		strcpy(tr,r);
		for(i = 0;i < strlen(al);i++)
			for(j = 0;j < strlen(tl);j++) if(al[i] == tl[j]) tl[j] = '0' + f[i];
		for(i = 0;i < strlen(al);i++)
			for(j = 0;j < strlen(tr);j++) if(al[i] == tr[j]) tr[j] = '0' + f[i];
		ret = calc(0,tl)==calc(0,tr);
//		printf("%s=%s",tl,tr);
//		printf(" %d\n",ret);
		ret = min(1,ret);
		return ret;
	}
	for(i = 0;i < 2;i++){
		f[c] = i;
		ret = min(ret,dfs(c + 1));
	}
	return ret;
}


int main(void){
	unsigned int i, j;
	char  c;
	while(1){
		for(i = 0;(c = getchar()) != '=' && c != '\n';i++)
			l[i] = c;
		l[i] = '\0';
		if(!strcmp(l,"#")) break;
		for(i = 0;(c = getchar()) != '\n';i++)
			r[i] = c;
		r[i] = '\0';
		al[0] = '\0';
		for(i = 0;i < strlen(l);i++){
			if(islower(l[i])){
				for(j = 0;j < strlen(al);j++)
					if(al[j] == l[i]) break;
				if(j == strlen(al)){
					al[j] = l[i];
					al[j + 1] = '\0';
				}
			}
		}
		for(i = 0;i < strlen(r);i++){
			if(islower(r[i])){
				for(j = 0;j < strlen(al);j++)
					if(al[j] == r[i]) break;
				if(j == strlen(al)){
					al[j] = r[i];
					al[j + 1] = '\0';
				}
			}
		}
		for(i = 0;i < strlen(l);i++){
			if(l[i]=='T') l[i] = '1';
			else if(l[i]=='F') l[i] = '0';
		}
		for(i = 0;i < strlen(r);i++){
			if(r[i]=='T') r[i] = '1';
			else if(r[i]=='F') r[i] = '0';
		}
		printf(dfs(0)?"YES\n":"NO\n");
	}
	return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int a5, b7, c5;

  if (a == 7) {
      b7 = a;
      a5 = b;
      c5 = c;
  } else if (b == 7) {
      b7 = b;
      a5 = a;
      c5 = c;

  } else if (c == 7) {
      b7 = c;
      a5 = a;
      c5 = b;

  } else {
      cout << "NO" << endl;
      return 0;
  }

if (a5 == 5 && c5 == 5) {
      cout << "YES" << endl;
      return 0;

} else {
      cout << "NO" << endl;
      return 0;

}
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<ios>
using namespace std;
int p[101];
main()
{
    int P,S;
    while(scanf("%d,%d",&P,&S),P)
    {
        p[P]=S;
    }
    while(cin>>P)
    {
        int cnt=1;
        bool is[99]={};
        for(int i=0;i<=100;i++)
        {
            if(!is[p[i]])
            {
                is[p[i]]=1;
                cnt+=p[i]>p[P];
            }
        }
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 200000000000000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
  ll N;
  cin >> N;
  cout << (N - 2) * 180 << endl;
} 


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
p = sorted([(x, i) for i, x in enumerate(a)], reverse=True)
dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for s in range(1, n+1):
	for x in range(s+1):
		y = s-x
		if x > 0:
			dp[x][y] = max(dp[x][y], dp[x-1][y] + abs(p[s-1][1] - x + 1) * p[s-1][0])
		if y > 0:
			dp[x][y] = max(dp[x][y], dp[x][y-1] + abs(n-y - p[s-1][1]) * p[s-1][0])
print(max(dp[x][n-x] for x in range(n+1)))

Measured memory_bytes: 101684
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
use std::cmp;

fn find_min_max(x: &[i64]) -> (i64, i64) {
    let mut min: i64 = x[0];
    let mut max: i64 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        min = cmp::min(*i, min);
        max = cmp::max(*i, max);
    }
    return (min, max)
}
fn main() {
    let n:i64 = read();
    let a:Vec<i64> = read_vec();
    let (amin, aMax) = find_min_max(&a);
    println!("{}", aMax-amin);
}


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

int main() {
  ll n;
  cin >> n;
  vector<char> a;
  string abc = "abcdefghijklmnopqrstuvwxyz";
  while (n) {
    n -= 1;
    a.push_back(abc[n%26]);
    n /= 26;
  }
  reverse(a.begin(), a.end());

  string ans = "";
  
  for (char v : a) {
    ans += v;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  int n;  cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++)  cin >> a.at(i);
  int cnt=1, ans=0;
  for(int i=0; i<n-1; i++){
    if(a[i]==a[i+1]) cnt += 1;
    else{
      ans += cnt/2; cnt = 1;
    }
  }
  cout << ans+cnt/2 << endl;
}


Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

uint16_t y[1001];

int main(void){
	int n, i, j;
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		int m=i;
		for(j=2; j<=m; j++){
			while(m%j==0){m/=j; y[j]++;}
		}
	}
	long ans=1;
	for(i=1; i<=n; i++){
		ans = ans*(y[i]+1)%P;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long STATES;

int main( void )
{
	STATES free_days[31], dp[51], goal_state, next;
	register int i, j;
	int n, answer, free_day, k;

	while ( scanf( "%d", &n ) == 1 && n )
	{
		memset( free_days, 0, sizeof(free_days) );
		memset( dp, 0, sizeof(dp) );

		goal_state = 0;
		for ( i = 0; i < n; i++ ) goal_state |= 1LL << i;

		for ( i = 0; i < n; i++ )
		{
			scanf( "%d", &k );
			for ( j = 0; j < k; j++ )
			{
				scanf( "%d", &free_day );
				free_days[free_day] |= 1LL << i;
			}
		}

		answer = -1;
		for ( i = 0; i < n; i++ ) dp[i] = 1LL << i;
		for ( i = 1; i <= 30; i++ )
		{
			next = 0;
			for ( j = 0; j < n; j++ ) if ( free_days[i] & 1LL << j ) next |= dp[j];
			for ( j = 0; j < n; j++ ) if ( free_days[i] & 1LL << j ) dp[j] |= next;
			if ( next == goal_state )
			{
				answer = i;
				break;
			}
		}

		printf( "%d\n", answer );
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846
int main(){
int n;
cin>>n;
//long long int sum=0;
int a[n-1];
for(int i=0;i<n-1;i++){
	cin>>a[i];
}
int ans[n]={0};
for(int i=0;i<n-1;i++){
	ans[a[i]-1]++;
}
for(int i=0;i<n;i++){
	cout<<ans[i]<<"\n";
}
}

Measured memory_bytes: 5132
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;





int main(void) {
  ll N;
  cin >> N;
  ll a, b;
  cin >> a >> b;
  
  if((b-a)%2==0) {
    pt((b-a)/2);
  }else {
    ll t=(b-a)/2;
    pt(min(a+t, N-a-t));
  }
  
  
  
}





Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N = 400;
const int base = 200;

typedef vector<int> die;

int n, h[N][N], top[N][N];

die rotate(die d, int pos[4])
{
    rep(i, 3) swap(d[pos[i]], d[pos[i + 1]]);
    return d;
}

int poss[][4] = {
    {0, 4, 5, 2},
    {0, 1, 5, 3},
    {0, 2, 5, 4},
    {0, 3, 5, 1}
};

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

void drop(int i, int j, die d)
{
    int dir = -1, mx = -1;
    if (h[i][j] > h[i + 1][j] and d[2] > mx) dir = 0, mx = d[2];
    if (h[i][j] > h[i][j + 1] and d[3] > mx) dir = 1, mx = d[3];
    if (h[i][j] > h[i - 1][j] and d[4] > mx) dir = 2, mx = d[4];
    if (h[i][j] > h[i][j - 1] and d[1] > mx) dir = 3, mx = d[1];

    if (dir < 0 or mx <= 3) {
        ++h[i][j], top[i][j] = d[0];
    } else {
        drop(i + dx[dir], j + dy[dir], rotate(d, poss[dir]));
    }
}

void solve()
{
    memset(h, 0, sizeof(h));
    memset(top, 0, sizeof(top));

    rep(i, n) {
        int t, f;
        cin >> t >> f;

        die d;
        d.pb(1);
        d.pb(4);
        d.pb(5);
        d.pb(3);
        d.pb(2);
        d.pb(6);

        rep(i, 4) {
            rep(j, 4) {
                rep(k, 4) {
                    if (d[0] == t and d[3] == f) goto label;
                    d = rotate(d, poss[0]);
                }
                d = rotate(d, poss[1]);
            }
            d = rotate(d, poss[2]);
        }
        assert(d[0] == t and d[3] == f);
    label:
        drop(base, base, d);
    }

    int ans[6] = {};
    rep(i, N) rep(j, N) if (top[i][j]) {
        ++ans[top[i][j] - 1];
    }
    rep(i, 6) cout << ans[i] << (i < 5 ? ' ' : '\n');
}

int main()
{
    while (cin >> n and n) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 2468
#include<iostream>
#include<string>

using namespace std;

int main(){
	int a[26]{0};
	string s;
	cin >> s;

	for (int i = 0; i < s.size(); i++)a[s[i] - 'a']++;

	for (int i = 0; i < 26; i++)
		if (a[i] % 2 == 1) {
			cout << "No" << endl;
			return 0;
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e,f,g,h,i,j,k,l,m,n;
    cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k>>l>>m>>n;
    cout<<a-b<<endl;
    cout<<c-d<<endl;
    cout<<e-f<<endl;
    cout<<g-h<<endl;
    cout<<i-j<<endl;
    cout<<k-l<<endl;
    cout<<m-n<<endl;
}



Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	A1,A2,A3 = inputMap()

	if A1+A2+A3 <= 21:
		print("win")
	else:
		print("bust")


if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(all(a));
  int x=a[0],y=a[1],z=a[2];
  int ans=0;
  ans += (y-x)/2;
  x = y-(y-x)%2;
  if(y==x){
    ans += z-y;
  }else{
    ans += z-y+2;
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall ABC113A0.cpp -o .\out\ABC113A0.out
.\out\ABC113A0.out
*/

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

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  int ans = a * b /2;
  cout << ans << "\n";
}


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

void solve(long long N, long long M, std::vector<long long> A){
    ll sum =0;
    for(int i=0;i<M;i++){
        sum += A[i];
    }
    if(sum>N){
        cout << -1 << endl;
    }else{
        cout << N-sum << endl;
    }

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;

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

	int sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += x;
	}

	if (sum >= h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
const int MAXN = 1e5 + 5;

int n;
int height[MAXN];

bool judge() {
    for (int i = n - 1; i; --i) {
        if (height[i] > height[i + 1])
            --height[i];
        if (height[i] > height[i + 1])
            return false;
    }
    return true;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i<= n; ++i) {
        scanf("%d", &height[i]);
    }
    if (judge())
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<vector>
#define p pair<int,int>
#define P pair<int,p>
#define int long long
using namespace std;

P a[5000];
int dp[5001];
signed main() {
	fill(dp + 1, dp + 5001, LLONG_MAX);
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].second.first >> a[i].second.second;
		a[i].first= a[i].second.first+ a[i].second.second;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		for (int j = 5000; j > 0; j--) {
			if(dp[j-1]<=a[i].second.first)dp[j] = min(dp[j], dp[j - 1] + a[i].second.second);
		}
	}
	for (int i = n; i >= 0; i--) {
		if (dp[i] < LLONG_MAX) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 384
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print(int((tmp*tmp-tmp2)//2)%1000000007)

Measured memory_bytes: 25356
import sys

def get_k_order(k):
  kb = format(k, 'b')
  return len(kb) - 1


def dp(A, N, K, start):
  ans = 0
  S = 1 << start
  for b in range(40, -1, -1):
    power = 1 << b
    bit_count = sum([a & power != 0 for a in A])
    
    if (power <= S) and (power <= K) and (N - bit_count >  bit_count):
      opt_count = N - bit_count
      K -= power
    else:
      opt_count = bit_count
    
    ans += power * opt_count
  return ans


def main():
  input = sys.stdin.readline
  N, K = map(int, input().split())
  A = [int(a) for a in input().split()]
  ko = get_k_order(K)
  
  dp_from_1st_order = dp(A, N, K, ko)
  if ko > 0:
    dp_from_2nd_order = dp(A, N, K, ko-1)
  else:
    dp_from_2nd_order = 0
  ans = max(dp_from_1st_order, dp_from_2nd_order)
  print(ans)


if __name__ == '__main__':
  main()

Measured memory_bytes: 14620
# coding: utf-8
# Your code here!
X=int(input())

if X%7==1:
    print('fri')
elif X%7==2:
    print('sat')
elif X%7==3:
    print('sun')
elif X%7==4:
    print('mon')
elif X%7==5:
    print('tue')
elif X%7==6:
    print('wed')
else:
    print('thu')


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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 100000 + 5;

int n , A[N];

#ifdef Lin1043
namespace TEST
{
    const int M = 200 + 5;

    int f[M][M] , g[M][M];

    int solve(int x , int y)
    {
        if(g[x][y])
            return 0;
        if(f[x][y] != -1)
            return f[x][y];
        int now = 0;
        if(solve(x + 1 , y) == 0)
            now = 1;
        if(solve(x , y + 1) == 0)
            now = 1;
        return f[x][y] = now;
    }
}
#endif 

int comp(int x , int y)
{
    return x > y;
}

int main()
{
    read(n);
    rep(i , 1 , n) read(A[i]);
    sort(A + 1 , A + 1 + n , comp);
#ifdef Lin1043
    rep(i , 1 , n)
        TEST::g[i][A[i]] = 1;
    memset(TEST::f , -1 , sizeof TEST::f);
    TEST::solve(1 , 0);
    cout << TEST::f[1][0] << endl;
#endif
    rep(i , 1 , n) if(i + 1 > A[i + 1])
    {
        int Ans = 0;
        rep(j , i + 1 , n)
        {
            if(A[j] != i) break;
            Ans ^= 1;
        }
        Ans |= (A[i] - i) % 2;
        if(Ans)
            puts("First");
        else
            puts("Second");
        break ;
    }
    return 0;
}



Measured memory_bytes: 640
// finish date: 2018/08/13
#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, M;
    cin >> N >> M;
    vi A(N + 1);
    A[0] = 0;
    FOR(i, 1, N + 1) cin >> A[i];
    ll ans = 0;
    map<int, int> mp;
    mp[0]++;
    FOR(i, 1, N+1) {
        A[i] = (A[i - 1] + A[i]) % M;
        mp[A[i]]++;
    }
    for (auto e:mp) {
        int num = e.second;
        ans += ((ll) e.second * (e.second - 1)) / 2;
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int N; cin >> N;
    cout << N / 3 << endl;
    return 0;
}

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

int main()
{
    int a, b;
    char op;
    
    while(cin >> a >> op >> b && op != '?') {
    
        switch(op) {
        case '+': a += b; break;
        case '-': a -= b; break;
        case '*': a *= b; break;
        case '/': a /= b; break;
        default: cout << "error" << endl; return -1;
        }
        
        cout << a << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}

struct Edge {
    long long to;
    long long cost;
    Edge(long long to,long long cost) : to(to), cost(cost) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;
 
void dijkstra(Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) continue;
        for (auto e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}


int main()
{
    vector<tuple<ll,int,int>> que;
    int n;
    cin >> n;
    rep(i,n) {
        rep(j,n) {
            ll A;
            cin >> A;
            if(i >= j) continue;
            que.emplace_back(A,i,j);
        }
    }
    sort(que.begin(), que.end());

    Graph G(n);

    ll res = 0;
    for(auto [A,u,v] : que) {
        vector<ll> dist;
        dijkstra(G,u,dist);
        if(dist[v] < A) {
            cout << -1 << endl;
            exit(0);
        } 
        if(dist[v] > A) {
            G[u].emplace_back(v,A);
            G[v].emplace_back(u,A);
            res += A;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> l(M), r(M);
    REP(i, M) cin >> l[i] >> r[i];

    vector<int> p(Q), q(Q);
    REP(i, Q) cin >> p[i] >> q[i];

    vector<vector<int>> graph(N + 50, vector<int>(N + 50, 0));
    REP(i, M){
        graph[l[i]][r[i]]++;
    }
    REP(i, N+5) REP(j, N+5) graph[i][j+1] += graph[i][j];
    REP(i, N+5) REP(j, N+5) graph[i+1][j] += graph[i][j];

    REP(i, Q){
        int a, b, c, d;
        a = graph[q[i]][q[i]];
        b = graph[q[i]][p[i]-1];
        c = graph[p[i]-1][q[i]];
        d = graph[p[i]-1][p[i]-1];
        cout << a - b - c + d << endl;
    }
}

Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        HashSet<string> list = new HashSet<string>();
        for (int i = 0; i < n; i ++) {
            string[] s = Console.ReadLine().Split().ToArray();
            if(s[0]=="insert") list.Add(s[1]);
            else Console.WriteLine(list.Contains(s[1]) ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 48812