akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#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<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    vector<int>V(n);
    rep(i,n){
        cin>>V[i];
    }
    bool ans=true;
    int ma=0;
    rep(i,n){
        if(i>ma)break;
        ma=max(ma,V[i]/10+i);
    }
    if(ma<n-1)ans=false;
    reverse(all(V));
    ma=0;
    rep(i,n){
        if(i>ma)break;
        ma=max(ma,V[i]/10+i);
    }
    if(ma<n-1)ans=false;
    if(ans)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  st s;
  cin >> s;
  cout << (s.at(1) == 'B' ? "ARC" : "ABC") << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;

int main()
{
    ll n, k, ans = 1;
    cin >> n >> k;
    while(n >= k){
        n /= k;
        ans++;
    }
    cout << ans << endl;
    system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <stack>

using namespace std;

int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[2] - a[0] << endl;
    return 0;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const int MOD = 1000000007;
const int N = 202055;
const int M = 1211;

void solve() {
    string s;
    cin >> s;

    string str;
    for (int i = 0; i < SZ(s); i++){
        if (s[i] != 'B'){
            str += s[i];
        } else {
            if (!str.empty()) str.pop_back();
        }
    }

    cout << str;

}

int main() {
    ios_base::sync_with_stdio(false);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

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

int main()
{
     char s[200],t[200];
     scanf("%s",s);
     scanf("%s",t);
     sort(s,s+strlen(s));
     sort(t,t+strlen(t),greater<int >());
     if(strcmp(s,t)<0)
        printf("Yes\n");
     else
        printf("No\n");
     return 0;
}


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

using namespace std;

int main(){
    string s;
    cin>>s;
    
    for(int i=0;i<3;i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            goto Exit;
        }
    }
    
    cout<<"No"<<endl;
    
    Exit:
        ;
}

Measured memory_bytes: 3600
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int calcSumOfDigit(int num)
{
    int rem = 0;
    int sum = 0;
    while(num > 0)
    {
        rem = num % 10;
        num /= 10;

        sum += rem;
    }

    return sum;
}

int main(void)
{
    int N,A,B;
    cin >> N >> A >> B;

    int sumOfNumber = 0;
    for(int i = 0; i <= N; i++)
    {
        int c = calcSumOfDigit(i);
        if(c >= A && c <= B)
        {
            sumOfNumber += i;
        }     
    }

    cout << sumOfNumber <<endl;

    return 0;

}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

const int N = 1e5 + 5;
int cnt[N];

int main(){
    fIO

    int n, k, q;
    cin >> n >> k >> q;

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

    for(int i = 1; i <= n; i++){
        int score = k - (q - cnt[i]);
        //cout << cnt[i] << " " << score << "\n";
        if(score > 0) cout << "Yes\n";
        else cout << "No\n";
    }


}








Measured memory_bytes: 1024
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

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

    vector<ll> lucas(N + 1);
    lucas[0] = 2;
    lucas[1] = 1;
    for (ll i = 2; i <= N; i++)
    {
        lucas[i] = lucas[i - 1] + lucas[i - 2];
    }
    cout << lucas[N] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	ll N;	cin>>N;
	ll ans=INF;
	for(ll i=1;i*i<=N;i++){
		ll tmp;
		if(N%i==0){
			tmp=i-1;
			tmp+=N/i-1;
			ans=min(ans,tmp);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int inf=2147483647;
char s[110];
char ss[]={"keyence"};
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	bool flag=true;
	for(int i=0;i<7;i++)
	if(s[i]!=ss[i]){flag=false;break;}
	if(flag)return puts("YES"),0;
	flag=true;
	for(int i=n-7;i<n;i++)
	if(s[i]!=ss[i-(n-7)]){flag=false;break;}
	if(flag)return puts("YES"),0;
	for(int i=0;i<7;i++)
	{
		bool flag=true;
		for(int j=0;j<=i;j++)
		if(s[j]!=ss[j]){flag=false;break;}
//		printf("%d %d\n",i,flag);
		for(int j=n-7+i+1;j<n;j++)
		if(s[j]!=ss[j-(n-7+i+1)+i+1]){flag=false;break;}
		if(flag)return puts("YES"),0;
	}
	puts("NO");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int p,i,M,N;
	int masu[1500],sai[1500];
	while(0==0){
	scanf("%d %d",&N,&M);
	p=1;
	if(N==0 && M==0)break;
	for(i=0;i<1501;i++){
		masu[i]=0;
		sai[i]=0;
	}
	for(i=1;i<N+1;i++)
		scanf("%d",&masu[i]);
	
	for(i=1;i<M+1;i++)
		scanf("%d",&sai[i]);
	
	for(i=1;i<M+1;i++){
		p+=sai[i];//目の数だけ進む
		p+=masu[p];//升の指示に従う
		if(p>=N)break;
	}
	printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a=0;
string s;
map<string,bool> m;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n){
		cin>>s;
		if(!m[s])a++;
		m[s]=1;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 19228
n = int(input())
A=list(map(int,input().split()))
cnt=0
B=[]
C=[]
for i,a in enumerate(A):
    B.append(A[i]+i)
    C.append(A[i]-i)
from collections import Counter
Bd=dict(Counter(B))
Cd=dict(Counter(C))
cnt=0
for k in Bd.keys():
    try:
        cnt+=Bd[k]*Cd[-k]
    except KeyError:
        continue
print(cnt)


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

int main() {
	int n;
	cin >> n;
	vector<long long>A(n-1);
	rep(i, n - 1) {
		cin >> A[i];
	}
	long long ans = A[0]+A[n-2];
	for (int i = 1;i < n-1;++i) {
		ans += min(A[i - 1], A[i]);
	}
	cout << ans << endl;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    int ans = 0;

    cout << N%K << endl;
}

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

int main(){
  ll N,K;
  cin >> N >> K;
  ll T=N/K;
  if(K%2!=0){
    cout << T*T*T << endl;
    return 0;
  }else{
    ll S=0;
    if(N>=K/2+(N/K)*K){
      S=1;
    }
    cout << T*T*T + (T+S)*(T+S)*(T+S) << endl;
    return 0;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	A, B, C, K = MAP()
	dif = A-B
	if dif > 10**18:
		print('Unfair')
	elif K%2:
		print(-dif)
	else:
		print(dif)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
program palindrome_philia
    implicit none
    character(100):: s
    integer(4):: i, ans, s_len

    read*, s
    ans = 0
    s_len = len_trim(s)
    
    do i = 1, s_len/2
        if (s(i:i) /= s(s_len-i+1:s_len-i+1)) ans = ans+1
    end do

    print*, ans
end program palindrome_philia

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

int main()
{
    int N, K;
    //string S;

    cin >> N >> K;
    char S[N];
    cin >> S;

    S[K-1] = S[K-1] + 32; // 大文字を小文字に
    cout << S << endl;
    
    return 0;
}

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

int main(){
  int n, y, i, j;
  cin >> n >> y;
  int a = y/10000;
  vector<int> x(3, -1);
  for(i = 0; i <= a; i++){
    int ya = y - 10000*i;
    int n_count = i;
    if(n_count > n){break;}
    int b = ya/5000;
    for(j = 0; j <= b; j++){
      int yb = ya - 5000*j;
      int n2_count = n_count + j;
      if(n_count > n){break;}
      int k = yb/1000;
      if(k + n2_count == n){
        x[0] = i; x[1] = j; x[2] = k;
      }
    }
  }
  cout << x[0] << " " << x[1] << " " << x[2] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int r;
  if(n >= k){
    r = k-1;
  }else{
    r = n;
  }

  double ans = 0;
  for(int i=1;i<=r;i++){
    double p = 1;
    int score = i;
    while(score < k){
      score *= 2;
      p /= 2;
    }
    ans += p/n;
  }

  if(n >= k){
    ans += (double)(n-k+1)/n;
  }

  printf("%.12lf\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#define pii pair<int, int>
using ll = long long int;
using namespace std;
string s, t;
void inp()
{
    cin >> s >> t;
}
void process()
{
    int n = s.length(), m = t.length();
    int ans = m;
    for (int i = 0; i <= n-m; i++)
    {
        int tmp = 0;
        for (int k = 0; k < m; k++)
        {
            tmp += (t[k] != s[i+k]);
        }
        ans = min(ans, tmp);
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r", stdin);
    inp();
    process();
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstring> // memset()
#include <cstdlib> //abs(int x)
using namespace std;

const long long INF = 1LL << 60;

int N, W;

long long solve(long long* w, long long* v){
  long long DP[N+10][100100];
  for (int i=0; i<N+10; i++){
    for (int j=0; j<100100; j++){
      DP[i][j] = INF;
    }
  }
  DP[0][0] = 0;
  for (int i=1; i<N+1; i++){
    for (int j=0; j<100100; j++){
      if (v[i-1] >= j){
        DP[i][j] = min(DP[i-1][j], w[i-1]);
      } else {
        DP[i][j] = min(DP[i-1][j], DP[i-1][j-v[i-1]]+w[i-1]);
      }
    }
  }
  int j = 0;
  while(DP[N][j] <= W){
    j++;
  }
  return j-1;
}

int main(){
  cin >> N >> W;
  long long w[N], v[N];
  for (int i=0; i<N; i++){
    cin >> w[i] >> v[i];
  }
  cout << solve(w, v) << endl;
}


Measured memory_bytes: 86272
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	if(e - a > k)cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

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

using namespace std;

template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec){
    os << "[";
    for(int i=0;i<vec.size();i++){
        os << (i==0?"":" ") << vec[i];
    }
    os <<  "]";
    return os;
}

bool saiki(int node, int now, long long &num1, long long &num2, vector<int> &sk, vector<vector<int>> &edges){
    if(sk[node] != -1 && sk[node] != now)
        return true;
    else if(sk[node] == now)
        return false;
    else{
        sk[node] = now;
        if(now == 0)
            num1++;
        else if(now == 1)
            num2++;

        bool ret = false;
        for(int to: edges[node]){
            ret |= saiki(to, (now+1)%2, num1, num2, sk, edges);
        }
        return ret;
    }

}

int main(){
    long long n, m;
    cin >> n >> m;
    vector<vector<int>> edges(n);
    for(int i=0;i<m;i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    long long num1=0, num2=0;
    vector<int> sk(n, -1);
    bool ret = saiki(0, 0, num1, num2, sk, edges);

    cout << (ret?(n*(n-1)/2-m):(num1*num2-m)) << endl;

    return 0;
}


Measured memory_bytes: 7424
S = input()
f = False
n = len(S)

f = True
ff = False

if S[0] != "A":
  f = False
if S[1].isupper():
  f = False
for i in range(2,n-1):
  if S[i] == "C" and ff == False:
    ff = True
  elif S[i].isupper():
    f = False
if S[-1].isupper():
  f = False

if f == False or ff == False:
  print("WA")
else:
  print("AC")

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

int main(){
    
    int n,k; cin>>n>>k;
    vector<int> h(n);
    for(int i=0; i<n; i++)
        cin>>h.at(i);
    
    sort(h.begin(), h.end());
    
    int ans=h.at(k-1) - h.at(0);
    for(int i=1; i+k-1<n; i++)
        ans = min(ans, h.at(i+k-1) - h.at(i));
    
    cout<<ans;
    
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007

int main() {
    int n,k,i,j;
    cin>>n>>k;
    int a[n];
    for(i=1;i<=n;i++)
    cin>>a[i];
    ll dp[n+2][k+2];
    for(j=0;j<=k;j++)
    {
        dp[1][j]=(j>a[1])?0:1;
    }
    for(i=2;i<=n;i++)
    {
        for(j=0;j<=k;j++)
        {
            if(j==0)
            dp[i][j]=dp[i-1][j];
            else{
                if(j-a[i]-1>=0)
                dp[i][j]=(mod +dp[i][j-1]%mod+dp[i-1][j]%mod-dp[i-1][j-1-a[i]]%mod)%mod;
                else
                dp[i][j]=(dp[i][j-1]%mod+dp[i-1][j]%mod)%mod;
            }
        }
    }
    cout<<dp[n][k]%mod<<"\n";
	return 0;
}

Measured memory_bytes: 78464
#include <iostream>
#include <stdio.h>

using namespace std;

int main(void){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if(a < b && b < c){
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 3136
class dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def setnum(self,s):
        self.number = s

    def kai(self,h):
        tmp = self.number
        if h == 'E':
            self.number = [tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        elif h == 'S':
            self.number = [tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
        elif h == 'W':
            self.number = [tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        elif h == 'N':
            self.number = [tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]

num = list(map(int,input().split()))
kaitenn = input()
dice = dice()
dice.setnum(num)
for i in range(len(kaitenn)):
    dice.kai(kaitenn[i])
print(dice.number[0])


Measured memory_bytes: 5612
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
 
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
 
		for (int j = 0; j < k; j++) {
			int[] sum = new int[n];
 
			for (int i = 0; i < n; i++) {
				int s, t;
				if (i - a[i] < 0) {
					s = 0;
				} else {
					s = i - a[i];
				}
				if (i + a[i] + 1 < n) {
					sum[i + a[i] + 1] -= 1;
				}
				sum[s] += 1;
			}
 
			for (int i = 0; i < n; i++) {
				if (i == 0) {
					a[i] = sum[i];
				} else {
					a[i] = a[i - 1] + sum[i];
				}
			}
 
			boolean f = true;
			for (int i = 0; i < n; i++) {
				if (a[i] != n) {
					f = false;
					break;
				}
			}
			if (f) {
				break;
			}
		}
 
		for (int i = 0; i < n - 1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n - 1]);
 
	}
 
}

Measured memory_bytes: 62440
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		for (int i = a; i <= b; i++) {
			if (i - a < k || b - i < k) {
				System.out.println(i);
			}
		}
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define M 1000000007
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

using namespace std;
ll power(ll x,ll y){
    ll t=1;
    while(y){
        if(y&1) t=(t*x)%M;
        y>>=1;
        x=(x*x)%M;
    }
    return t;
}
ll per(ll n,ll r){
    ll t=1,p=n-r+1;
    for(ll i=n;i>=p;i--) t=(t*i)%M;
    p=1;
    for(ll i=1;i<=r;i++) p=(p*i)%M;
    t=(t*power(p,M-2))%M;
    return t;
}
int main(){
    cs;
    ll n,a,b;
    cin>>n>>a>>b;
    n=power(2,n)-1LL-per(n,a)-per(n,b);
    while(n<0) n+=M;
    cout<<n;
}

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

const ll mod = 1e+9 + 7;

int main(){
    ll n, ans = 1;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    bool flag = true;

    if (n % 2 == 0) {
        rep(i, n / 2) if (a[2 * i] != 2 * i + 1 || a[2 * i + 1] != 2 * i + 1) flag = false;
        if (flag){
            rep(i, n / 2){
                ans *= 2;
                ans = ans % mod;
            }
            cout << ans << endl;
        }
        else cout << 0 << endl;
    }
    else {
        if (a[0] != 0) flag = false;
        rep(i, n / 2) if (a[2 * i + 1] != 2 * (i + 1)|| a[2 * i + 2] != 2 * (i + 1)) flag = false;
        if (flag){
            rep(i, n / 2){
                ans *= 2;
                ans = ans % mod;
            }
            cout << ans << endl;
        }
        else cout << 0 << endl;
    }

}

Measured memory_bytes: 1024
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
using namespace std;

using LL = long long;
const int N = 505;

int p[N * N];
int vis[N][N];
int dis[N][N];
bool mk[N][N];

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


void dij(int x, int y, int f) {
    ans += dis[x][y];
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> que;
    que.push({dis[x][y], {x, y}});
    mk[x][y] = true;
    while (!que.empty()) {
        auto [d, p] = que.top();
        auto [x, y] = p;
        que.pop();
        if (vis[x][y] == f) continue;
        vis[x][y] = f;
        for (int i = 0; i < 4; i++) {
            int xx =  x + dx[i], yy = y + dy[i];
            if (xx <0 || yy < 0 || xx >= n || yy >= n || vis[xx][yy] == f) continue;
            int v = d + !mk[x][y];
            if (v < dis[xx][yy]) {
                dis[xx][yy] = v;
                que.push({v, {xx, yy}});
            }
        }
    }
}
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;
    
    for (int i = 0; i < n * n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dis[i][j] = min(min(i, j), min(n - i - 1, n - j - 1));
        }
    }
    for (int i = 0; i < n * n; i++) {
        int t = p[i] - 1;
        dij(t  / n, t % n, i + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6932
// inputに入力データ全体が入る
function Main(input) {
	var tmp = input.split("")
    if(tmp[0] != tmp[1] | tmp[0] != tmp[2] | tmp[1] != tmp[2]){
        console.log("Yes")
    }else{
        console.log("No")
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

vector<pair<char, int>> RLE(string s) {
    vector<pair<char, int>> ret;
    for(int i = 0; i < (int)s.size();) {
        int cnt = 0;
        while(s[i] == s[i+cnt]) ++cnt;
        ret.emplace_back(s[i], cnt);
        i += cnt;
    }
    return ret;
}

int main() {
    string s; cin >> s;
    long n = s.size();
    vector<long> ans(n);
    int idx = 0;
    auto RL = RLE(s);
    for(int i=0; i < RL.size() / 2; ++i) {
        int r = RL[i*2].second, l = RL[i*2+1].second;
        int L = r / 2 + (l + 1) / 2;
        int R = l / 2 + (r + 1) / 2;
        ans[idx + r - 1] = R;
        ans[idx + r] = L;
        idx += r + l;
    }

    for(int i=0; i < n; ++i) cout << ans[i] << (i == n-1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 2424
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  char s[10], temp;
  int i, len;
  scanf("%s",&s);
  len = strlen(s);
  if(len==3){
    temp = s[0];
    s[0] = s[2];
    s[2] = temp;
  }
  printf("%s",s);
  return 0;
}


Measured memory_bytes: 128
using System;

class Program
{
    static void Main()
    {
        var nk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var ans = new long[100001];
        for (int i = 0; i < nk[0]; i++)
        {
            var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            ans[ab[0]] += ab[1];
        }
        for (int i = 1; i <= 100000; i++)
        {
            nk[1] -= ans[i];
            if (nk[1] <= 0)
            {
                Console.WriteLine(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 15824
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(;;){
			// 8.4
			String s=sc.next();
			String t=sc.next();
			if(s.equals("0")){
				break;
			}
			int hit=0, blow=0;
			for(int j=0; j<4; j++){
				if(t.charAt(j)==s.charAt(j)){
					hit++;
				}
				for(int i=0; i<4; i++){
					if(t.charAt(j)==s.charAt(i)){
						blow++;
					}
				}
			}
			blow-=hit;
			println(hit+" "+blow);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

int com(int x){
  if(x < 2){
    return 0;
  }
  else{
    int ans;
    ans = x*(x - 1)/2;
    return ans;
  }
}

int main(){
  int n,m;
  cin >> n >> m;
  int ans = 0;

  ans = com(n) + com(m);
  cout << ans;

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        out.println(in.next().replace("2017", "2018"));
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

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

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

const int INF=1e9;
const int MOD=1e9+7;

ll dp[3010][3010][5];
ll val[3010][3010]={};

int main(){
    ll R,C,K; cin >> R >> C >> K;
    memset(val,0,sizeof(val));
    for(int i=0;i<K;i++){
        ll r,c,v; cin >> r >> c >> v;
        r--,c--;
        val[r][c]=v;
    }
    memset(dp,0,sizeof(dp));
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            for(int k=0;k<=3;k++){
                if(val[i][j]){
                    if(k+1<=3){
                        dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+val[i][j]);
                    }
                    if(k<3){
                        dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]+val[i][j]);
                    }
                }
                dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
            }
        }
    }
    ll ans=0;
    for(int i=0;i<=3;i++){
        ans=max(ans,dp[R][C-1][i]);
        ans=max(ans,dp[R-1][C][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 428328
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        k: usize
    }
    let mut a = vec![0;1000001];
    a[1] = 7 % k;
    if a[1] == 0 {
        println!("1");
        return;
    }
    for i in 2..=k {
        a[i] = (a[i-1] * 10 + 7) % k;
        if a[i] == 0 {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 9884
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

ll x(ll b){
  ll a = 0;
  if ((b -a) % 2 == 1){
    ll cnt_1 = (b-a+1)/2;
    if (cnt_1 % 2 == 0) return 0;
    else return 1;
  }else{
    ll cnt_1 = (b-a)/2;
    if (cnt_1 % 2 == 0) return (b ^ 0);
    else return (b ^ 1);
  }
}
int main(){
  ll a,b;
  cin>>a>>b;
  if (a == 0) cout << x(b) << endl;
  else cout << (x(b) ^ x(a-1)) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
    string S;
    ll Q,flag=1;
    cin >> S >> Q;

    for (ll i = 0; i < Q; i++) {
        int t,f;
        char c;
        cin >> t;
        if(t==1) flag=flag*(-1);
        else{
            cin >> f >> c;
            if(f==1){
                if(flag==1) S.insert(S.begin(), c);
                else S.push_back(c);
            }
            else{
                if(flag!=1) S.insert(S.begin(), c);
                else S.push_back(c);
            }
        }
    }

    if(flag!=1){
        for (ll i = S.length()-1; i >= 0; i--)
        {
            cout << S[i] ;
        }
        cout << endl;
    }
    else cout << S << endl;
}

Measured memory_bytes: 1028
#include <iostream>

using namespace std;

int comp(const void *a, const void *b){
    if(*(int *)a < *(int *)b){
        return -1;
    }else if(*(int *)a > *(int *)b){
        return 1;
    }else {
        return 0;
    }
}
int main(){
    int n;
    int *a;
    long long sum = 0;

    cin >> n;
    a = new int[n];

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

    qsort(a, n, sizeof(int), comp);

    // for (int i = 0; i < n; i++) cout << a[i];
    for (int i = 1; i < n; i++){
        sum = sum + a[n - 1 - i/2];
        // cout << i/2 << endl;
    }

    cout << sum << endl;

    delete a;
    return 0;
}

Measured memory_bytes: 4876
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N, K;
    cin >> N >> K;

    map<int, int> XtoY;
    set<int> X;
    // map<int, int> Y;
    REP(n, N) {
        int x, y;
        cin >> x >> y;
        X.insert(x);
        // Y[x] += 1;
        XtoY[x] = y;
    }
    vector<int> Xvec(ALL(X));
    int XSize = SIZE(Xvec);

    ll ans = 5 * 1e18;
    REP(xidx1, XSize) {
        int pointNumMax = 0;
        set<int> Y;
        FOR(xidx2, xidx1, XSize) {
            auto x1 = Xvec[xidx1];
            auto x2 = Xvec[xidx2];

            pointNumMax++;
            auto y = XtoY[x2];
            Y.insert(y);

            // [xidx1, xidx2]の間の領域に少なくともK個点がある
            if (pointNumMax >= K) {
                vector<int> Yvec(ALL(Y));
                int yidx1 = 0;
                int yidx2 = K - 1;
                while(yidx2 < pointNumMax) {
                    auto y1 = Yvec[yidx1];
                    auto y2 = Yvec[yidx2];
                    ans = min(ans, ll(x2 - x1) * ll(y2 - y1));

                    // printf("(x1,x2,y1,y2) = (%d,%d,%d,%d)\n",
                    //        x1, x2, y1, y2);
                    
                    ++yidx1;
                    ++yidx2;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>

using namespace std;


int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);


    int n;
    cin >> n;
    vector<long long> v(n + 1);
    vector<long long> b(n);
    for (int i = 0; i < n + 1; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vector<long long> res(n + 1);
    res[0] = min(b[0], v[0]);
    b[0] = max(b[0] - v[0], 0ll);
    int i = 1;
    for (; i < n; ++i) {
        res[i] = min(v[i], b[i] + b[i - 1]);
        b[i] = max(0ll, b[i] + min(b[i - 1] - v[i], 0ll));
    }
    res[n] = min(b[i - 1], v[i]);
    long long count = 0;
    for (auto val : res){
        count += val;
    }
    cout << count;

    return 0;
}




Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=505;
ll f[N][N],g[N][N],dp[N][N];
ll gf(int a,int b,int c,int d){//<=1,i>j
	return f[b][d]+f[a][c]-f[a][d]-f[b][c];
}
ll gg(int a,int b,int c,int d){//>=1,i<j
	return g[b][d]+g[a][c]-g[a][d]-g[b][c];
}
int main(){
	int n=read();
	For(i,1,n){
		For(j,1,n){
			int x=0;
			if(i!=j)x=read();
			f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
			g[i][j]=g[i-1][j]+g[i][j-1]-g[i-1][j-1];
			if(i>j)f[i][j]+=x; else g[i][j]+=x;
		}
	}
	ll ans=gg(0,n,0,n);
	For(i,1,n-1)ans=min(ans,gg(0,i,0,i)+gg(i,n,i,n));
	ans-=gf(0,n,0,n);
	For(i,1,n-1){
		For(j,i+1,n-1){
			dp[i][j]=-gf(0,j,0,j)+gg(0,i,0,i)+gg(i,j,i,j);
			ll zs=-gf(i,j,i,j)+gg(i,j,i,j); dp[i][j]-=zs;
			For(k,1,i-1)dp[i][j]=min(dp[i][j],dp[k][i]-gf(i,j,k,i)); 
			dp[i][j]+=zs;
			ans=min(ans,dp[i][j]-gf(j,n,i,n)+gg(j,n,j,n));
		}
	}
	cout<<ans+gf(0,n,0,n)<<endl;
}

Measured memory_bytes: 6144
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');

  (function(x) {
    // ????????????????????????
console.log(x*x*x);

  })(parseInt(inputs[0], 10)); // ??°?????????

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15688
#include<bits/stdc++.h>
using namespace std;
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
typedef long long ll;
ll l,r;
int main(){
	scanf("%lld %lld",&l,&r);
	if(r-l>=2019){puts("0");return 0;}
	ll ma=2019;
	for(ll i=l;i<=r;i++){
		for(ll j=i+1;j<=r;j++){
			if(i*j%2019<ma)ma=i*j%2019;
		}
	}
	printf("%lld",ma);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;

Graph g;

vector<int> depth;
void dfs(int v, int p, int d){
  depth[v] = d;
  for(auto nv_nw : g[v]){ 
    if(nv_nw.to == p)continue;
    dfs(nv_nw.to, v, d + nv_nw.weight);
  }
}

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

  g.resize(n);
  for(int i = 0; i < n - 1; ++i){ 
    int u, v, w;
    cin >> u >> v >> w;
    --u;
    --v;
    g[u].push_back(Edge(v, w));
    g[v].push_back(Edge(u, w));
  }

  depth.resize(n);
  dfs(0, -1, 0);

  for(int i = 0; i < n; ++i){
    if(depth[i] % 2)cout << 1 << endl;
    else cout << 0 << endl;
  }
}

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


#define loop(i,n) for(int lc=i;lc<=n;lc++)
#define tloop(tn) for(int tlc=1;tlc<=tn;tlc++)
#define loop2(i2,n2) for(int lc2=i2;lc2<=n2;lc2++)
#define bloop(n,bn) for(int blc=n;blc>=bn;blc--)
#define il() while(true)
#define pi acos(-1)
#define rad_to_deg(angl) ((180*angl)/pi)
#define ll long long
#define caseno printf("Case %d: ",tlc);

#define sfi(def_var) scanf("%d",&def_var)
#define sfii(def_var,def_var2) scanf("%d %d",&def_var,&def_var2)
#define sfll(def_var,def_var2) scanf("%lld %lld",&def_var,&def_var2)

#define sfl(def_var) scanf("%lld",&def_var)
#define sfd(def_var) scanf("%lf",&def_var)
#define sfs(def_var) scanf("%s",&def_var)

#define pfie(def_var) printf("%d\n",def_var)
#define pfi(def_var) printf("%d",def_var)
#define pfl(def_var) printf("%lld",def_var)
#define pfd(def_var) printf("%lf",def_var)
#define nl printf("\n");

int n;
int h[100010];

int dp[100010];
int find_ans(int i)
{
    if(i==n) return 0;
    if(dp[i]>=0) return dp[i];
    int x,y=INT_MAX;
    if(i<n) x=abs(h[i]-h[i+1])+find_ans(i+1);
    if(i<n-1) y=abs(h[i]-h[i+2])+find_ans(i+2);
    dp[i]=min(x,y);
    return dp[i];

}
int main()
{

    cin >> n;

    loop(1,n)
    {
        dp[lc]=-1;
        cin >> h[lc];
    }
    cout << find_ans(1);
    //cout << "\ncall : " << c <<endl;
    //nl; main();

}


Measured memory_bytes: 4096
def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする
    x=A[r-1][1]
    i=p-1
    for j in range(p,r-1):
        if(A[j][1] <= x):
            i+=1
            A[j],A[i]=A[i],A[j]
    A[i+1],A[r-1]=A[r-1],A[i+1]
    return i+1
    

def quick_sort(A,p,r):
    if( p < r-1 ):
        q=partition(A,p,r)
        quick_sort(A,p,q)
        quick_sort(A,q+1,r)

        


def stability_judge(sorted,original):
    n=len(sorted)
    j=-1
    x=sorted[0][1]
    for i in range(n):
        if(x!=sorted[i][1]):
            x=sorted[i][1]
            j=-1
        
        while(1):
            j+=1
            if(x==original[j][1]):
                if(sorted[i][0]!=original[j][0]):
                    return 0
                else:
                    break
    return 1





n=int(input())
original_cards=[]
for loop in range(n):
    original_cards.append(list(input().split()))
for card in original_cards:
    card[1]=int(card[1])

sorted_cards=[card for card in original_cards]
quick_sort(sorted_cards,0,n)

if(stability_judge(sorted_cards,original_cards)):
    print("Stable")
else:
    print("Not stable")



for card in sorted_cards:
    card[1]=str(card[1])
    print(" ".join(card))


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

int pow( int n, int i ){
	int ret = 1;
	for( int j=0; j<i; j++ )
		ret *= n;
	return ret;
}

int getMax( string str ){
	int ret=0;
	for( int i=0; i<8; i++ ){
		int m=0;
		for( int j=0; j<8; j++ ){
			if( str[m] < str[j] )	m = j;
		}
		ret += pow(10,(7-i))*(str[m]-'0');
		str[m] = '0'-1;
	}
	return ret;
}

int getMin( string str ){
	int ret=0;
	for( int i=0; i<8; i++ ){
		int m=0;
		for( int j=0; j<8; j++ ){
			if( str[m] > str[j] )	m = j;
		}
		ret += pow(10,(7-i))*(str[m]-'0');
		str[m] = '9'+1;
	}
	return ret;
}

int main(){
	int n;
	string str;
	getline( cin, str );
	sscanf( str.c_str(), "%d", &n );
	
	for( int i=0; i<n; i++ ){
		getline( cin, str );
		int max = getMax( str );
		int min = getMin( str );
		cout << max-min << endl;
	}
	return 0;
}

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

#define FOR(i, a, b)  for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << "\n"
#define _ << " _ " <<
#define ll long long

using namespace std;

vector <ll> ve;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n) {
    ll a;
    cin >> a;
    ve.push_back(a);
  }

  ll out = 0;
  while (1) {
    sort(ve.begin(), ve.end());
    if (ve[n - 1] <= (ll) (n - 1)) {break;}

    ll tr = ve[n - 1] - (ll) (n - 1);
    ll num = (tr / (ll) n);
    if (tr % (ll) n) {num += 1LL;}
    REP(i, n - 1) ve[i] += num;
    ve[n - 1] -= (num * (ll) n);
    out += num;
  }
  cout << out << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
f=None 
s=1
for i in range(n-1):
    if a[i]==a[i+1]:
        pass
    elif f==None:
        f=(a[i]<a[i+1]) 
    elif f==(a[i]<a[i+1]):
        pass
    else:
        s+=1
        f=None 
print(s)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int n,k;
struct Node{
  int no;
  int par;
  vector<Node*> child;
  void build(int i){
    no=i;
    par=i;
  }
};
signed main(){
  cin>>n>>k;
  vector<Node> node(n+1);
  rep(i,n-1){
    int a,b;cin>>a>>b;
    node[a].child.push_back(&node[b]);
    node[b].child.push_back(&node[a]);
  }
  int res=k;
  rep1(i,n)node[i].build(i);
  queue<Node> que;
  que.push(node[1]);
  while(!que.empty()){
    Node buf=que.front();que.pop();
    int num=buf.child.size();
    int cur=2;
    if(buf.par==buf.no)cur=1;
    rep(i,num){
      if(buf.child[i]->no!=buf.par){
        buf.child[i]->par=buf.no;
        res*=(k-cur);
        res%=MOD;
        cur++;
        que.push(*buf.child[i]);
      }
    }
  }
  cout<<res<<"\n";
  return 0;
}


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

using namespace std;

#define REP(s,e) for(int i=(s);i<(e);i++)

int main(){
    int A,B,C;
    
    cin>>A>>B>>C;
    
    if(C>=A&&C<=B) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 504
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

use std::ascii::AsciiExt;
use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
        s:chars,
    }

    let vec = vec![s[1],s[2],s[3]];

    for i in 0..2u32.pow(3) {
        let mut sum = s[0] as i32 -48;
        let mut sumstr = s[0].to_string();
        for op in 0..3 {
            if i >> op & 1 == 1 {
                sum +=vec[op] as i32-48;
                sumstr.push('+');
            }else{
                sum -=vec[op] as i32-48 ;
                sumstr.push('-');
            }
            sumstr.push(vec[op]);
        }

        if sum == 7 {
            println!("{}=7", sumstr);
            return;
        }
    }
}


Measured memory_bytes: 4352