akhauriyash/Code-Regression huggingface dataset:
/*its_Rashid*/
#include <bits/stdc++.h>
using namespace std ;

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio

    lli num ;
    cin >> num ;

    (num == 7 || num == 5 || num == 3 ? YES : NO ) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;string s;cin>>N>>s;
    int cnt=0;
    for(int i = 0; i <s.size(); i++)
    {
        if (s[i]=='R') {
            cnt++;
        }
        else
        {
            cnt--;
        }
        
    }
    if (cnt>0) {
        /* code */
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<ctime>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 1e2+7;
const int inf = 1e5;
const int modn = 1e9+7;
const ld eps = 1e-8;
const long double PI = acos(-1.0);
void qRead(ll &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
void qRead(int &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
ll qpow(ll a,ll b,ll mo = modn){
//    printf("%lld\n",mo);
    ll res = 1;
    while(b){
        if(b & 1)res = (res*a) % mo;
        a = (a*a) % mo;
        b >>= 1;
    }
    return res;
}
ld qpow(ld a,ll b){
    ld res = 1;
    while(b){
        if(b & 1)res *= a;
        a = a*a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
//ll vis[maxn],prime[maxn],cnt,smallP[maxn];
//void getPrime(int n){
//    cnt = 0;
//    for(int i = 1;i <= n;i++)vis[i] = 0;
//    for(ll i = 2;i <= n;i++){
//        if(!vis[i]){
//            prime[++cnt] = i;
//            smallP[i] = i;
//        }
//        for(int j = 1;j <= cnt && i*prime[j] <= n;j++){
//            vis[prime[j]*i] = 1;
//            smallP[prime[j]*i] = prime[j];
//            if((i % prime[j]) == 0)break;
//        }
//    }
//}
//ll cnm[maxn][maxn];
//void getCnm(){
//    cnm[0][0] = 1;
//    for(int i = 1;i < maxn;i++){
//        for(int j = 0;j <= i;j++){
//            cnm[i][j] = cnm[i-1][j];
//            if(j)cnm[i][j] += cnm[i-1][j-1];
//            cnm[i][j] %= (modn-1);
//        }
//    }
//}
//ll f[maxn],invF[maxn];
//void getF(){
//    f[0] = invF[0] = 1;
//    for(int i = 1;i < maxn;i++)f[i] = f[i-1]*i % modn;
//    invF[maxn-1] = qpow(f[maxn-1],modn-2);
//    for(int i = maxn-2;i >= 1;i--)invF[i] = invF[i+1]*(i+1) % modn;
//}
char grid[maxn][maxn];
int h,w;
bool judge(int x,int y){
    int check = 0;
    for(int i = 1;i <= w;i++)if(grid[x][i] == '#'){check++;break;}
    for(int i = 1;i <= h;i++)if(grid[i][y] == '#'){check++;break;}
    if(check == 2)return 1;
    return 0;
}
int main(){
    scanf("%d%d",&h,&w);
    for(int i = 1;i <= h;i++)scanf(" %s",grid[i]+1);
    bool nex = 0;
    for(int i = 1;i <= h;i++){
        for(int j = 1;j <= w;j++){
            if(judge(i,j))printf("%c",grid[i][j]),nex = 1;
        }
        if(nex)printf("\n"),nex = 0;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class F
{
	public static void Main()
	{
		int M = GetInt();
		int K = GetInt();

		StringBuilder sb = new StringBuilder();
		if(M == 0)
		{
			if(K == 0)
				sb.Append("0 0");
			else
				sb.Append("-1");
		}
		else if(M == 1)
		{
			if(K == 0)
				sb.Append("0 0 1 1");
			else
				sb.Append("-1");
		}
		else
		{
			if(K >= (1 << M))
				sb.Append("-1");
			else
			{
				for(int i = 0; i < (1 << M); i++)
				{
					if(i == K)
						continue;
					sb.AppendFormat("{0} ", i);
				}
				sb.AppendFormat("{0} ", K);
				for(int i = (1 << M) - 1; i >= 0; i--)
				{
					if(i == K)
						continue;
					sb.AppendFormat("{0} ", i);
				}
				sb.AppendFormat("{0}", K);
			}
		}

		Console.WriteLine(sb);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 28116
#include <stdio.h>
int main(){
  int a,b,c,d,m;
  m=0;
  scanf("%d%d%d",&a,&b,&c);
  for(d=b-a;d>=0;d--){
    if(c%(d+a)==0){
      ++m;
    }
  }
  printf("%d\n",m);
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    LL H, W;
    cin >> H >> W;

    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }

    LL tmp1 = ((H + 1) / 2);
    LL tmp2 = ((W + 1) / 2);
    cout << tmp1 * tmp2 + (H - tmp1) * (W - tmp2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<ll> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;

//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll n,cnt=0;cin>>n;
  veci v(n);
  {rep(i,n)cin>>v[i];}
  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      for(ll k=j+1;k<n;k++){ ll a=max(v[i],max(v[j],v[k]));
        if((v[i]!=v[j])&&(v[j]!=v[k])&&(v[k]!=v[i])&&((a*2)<(v[i]+v[j]+v[k])))cnt++;
              }
    }}cout<<cnt;}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	ll n, k; cin >> n >> k;
	cout << min(n%k, k - n%k) << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    string C, D;

    cin >> C >> D;

    cout << (C[0] == D[2] && C[1] == D[1] && C[2] == D[0] ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
s=is1()
print(s[0:3])

Measured memory_bytes: 9492
from heapq import heappop, heappush

def dijkstra(s):
    used = [1] * N
    dp = [INF] * N
    dp[s] = 0
    hq = []
    used[s] = 0
    for i in cost[s]:
        heappush(hq, i)

    while hq:
        minv = heappop(hq)
        if used[minv[1]] == 0:
            continue
        v = minv[1]
        dp[v] = minv[0]
        used[v] = 0
        for i in cost[v]:
            if used[i[1]]:
                heappush(hq, [i[0] + dp[v], i[1]])
    return dp

INF = 10 ** 18
N = int(input())
cost = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    cost[a].append([c, b])
    cost[b].append([c, a])

Q, K = map(int, input().split())
dp1 = dijkstra(K - 1)
for i in range(Q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    ans = dp1[x] + dp1[y]
    print(ans)

Measured memory_bytes: 55928
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

long long X, Y;

void Work()
{
	scanf("%lld%lld", &X, &Y);
	if (X % Y == 0)
	{
		printf("-1\n");
		return;
	}
	for (long long p = X; ; p += X)
		if (p % Y != 0)
		{
			printf("%lld\n", p);
			return;
		}
}

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

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

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    int n = s.length();
    for(int i=0; i<n; i++) {
        s[i] = (s[i] - 'A' + 23) % 26 + 'A';
    }
    cout << s << endl;
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vll a(m);
  rep(i,m) cin>>a[i];
  vsort(a);
  
  vll d(m-1);
  rep(i,m-1){
    d[i]=a[i+1]-a[i];
    // cout<<d[i]<<endl;
  }
  sort(d.rbegin(),d.rend());
  
  if(n>=m){
    cout<<0<<endl;
    return 0;
  }
  
  ll ans=a[m-1]-a[0];
  // cout<<ans<<endl;
  rep(i,n-1){
    ans-=d[i];
  }
  
  cout<<ans<<endl;
  
}

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

int main(){
  int N;
  cin >> N;
  vector<string> B(N);
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  int M;
  cin >> M;
  vector<string> R(M);
  for(int i=0;i<M;i++){
    cin >> R.at(i);
  }
  int ans=0;
  string S;
  int sum=0;
  for(int i=0;i<N;i++){
    S=B.at(i);
    for(int j=0;j<N;j++){
      if(S==B.at(j)){
        sum ++;
      }
    }
    for(int j=0;j<M;j++){
      if(S==R.at(j)){
        sum --;
      }
    }
    ans = max(ans,sum);
    sum = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (A[i] % 2 == 1){
      cnt++;
    }
  }
  if (cnt % 2 == 0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(){
    int m, h;
    char cards[256], temp[256], result[256];
    int i, j=0, len;

    while(1){
        scanf("%s", cards);
        len=strlen(cards);
        if(strcmp(cards, "-")==0&&len==1)break;
        scanf("%d", &m);
        for(;m>0;m--){
            scanf("%d", &h);
            strcpy(temp, cards);
            for(i=0;i<h;i++){
                cards[len-h+i]=temp[i];
            }
            for(i=0;i<len-h;i++){
                cards[i]=temp[i+h];
            }
        }
        for(i=0;i<len;i++){
            result[j++]=cards[i];
        }
        result[j++]='\n';
    }
    result[j]='\0';
    printf("%s", result);

    return 0;
}

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

int main(){
  int n,W,w[201],sum[201]={};
  cin>>n>>W;
  for(int i=0;i<n;i++)cin>>w[i];
  sort(w,w+n,greater<int>());
  sum[n-1]=w[n-1];
  for(int i=n-2;i>=0;i--) sum[i]=w[i]+sum[i+1];

  ll dp[20011]={1},ans=0;  
  for(int i=0;i<n;i++){
    
    for(int j=0;sum[i+1]+j<=W;j++)
      if(sum[i+1]+j+w[i]>W) ans=(ans+dp[j])%mod;
    
    for(int j=W;j>=0;j--)dp[j+w[i]]=(dp[j+w[i]]+dp[j])%mod;
  }
  
  cout << max(1LL,ans)<<endl;
  return 0;
}

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

using namespace std;


int main(){
    
    
    int H,W,D;
    cin >> H >> W >> D;
    vector<vector<int> > A(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    
    int Q;
    cin >> Q;
    vector<int> L(Q);
    vector<int> R(Q);
    
    for (int i = 0; i < Q; i++) {
        cin >> L[i] >> R[i];
    }
    
    vector<int> hh(H*W+1, 0);
    vector<int> ww(H*W+1, 0);
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            hh[A[i][j]] = i;
            ww[A[i][j]] = j;
        }
    }
    
    
    vector<int> dp(H*W+1, -1);
    for (int i = 1; i <= H*W; i++) {
        if (dp[i] == -1) {
            dp[i] = 0;
            int k = i;
            while (k+D <= H*W) {
                dp[k+D] = dp[k] + abs(hh[k+D]-hh[k]) + abs(ww[k+D] - ww[k]);
                k = k+D;
            }
            
        }
    }
    
    for (int i = 0; i < Q; i++) {
        cout << abs(dp[R[i]] - dp[L[i]]) << endl;
    }
    
    
}





Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

typedef long long ll;

using namespace std;

int main(){
  int N;
  int h[110];
  cin >> N;
  for (int i; i < N; i++) cin >> h[i];
  
  int ans = 0;
  for (int i = 0; i < 100; i++) {
    bool flag = false;
    for (int j = 0; j < N; j++) {
      if (h[j] != 0 && flag == false) {
	ans++;
	flag = true;
      }
      if (h[j] == 0 && flag == true) flag = false;
      if (h[j] > 0) h[j]--;
    }
  }
  cout << ans << endl;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
int second[10];

void prepare(){
    
    rep(i,10){
        second[i]=(1<<i);
    }

}

int change(char c){
    return int(c-'0');
}

int main(){
    
    long long ans=0;
    string s;
    cin>>s;
    int n=s.size();
    int p[n];

    rep(i,n)p[i]=change(s[i]);
    prepare();
    for(int bit=0;bit<(1<<(n-1));bit++){
        long long total=0;
        long long  now=1;
        total+=p[n-1];
        for(int i=n-2;i>-1;i--){
            if(second[i]&bit){
                //cout<<total<<" ";
                ans+=total;
                now=1;
                total=0;
            }
            else{
                now*=10;
            }
            total+=p[i]*now;
        }
        //cout<<total<<" ";
        ans+=total;
    }
    
    cout<<ans<<endl;


    return 0;

}
/*


*/


Measured memory_bytes: 256
import java.util.Scanner;

//ABC116A

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		System.out.println((A * B)/2);


	}

}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
long long k,a,b,ans;

int main(){
	cin>>k>>a>>b;
	if(b-a<=2) ans=k+1;
	else{
		if(k<a+1) ans=k+1;
		else if(k==a+1) ans=b;
		else{
			k-=a+1;
			ans=b+(k/2)*(b-a)+k%2;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

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

    int cnt = 0;
    int ans = 0;
    for (int i=0; i<n-1; i++) {
        if (h[i] >= h[i+1])
            cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }

    ans = max(ans, cnt);
    cout << ans << endl;
}


Measured memory_bytes: 888
import java.util.Arrays;
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[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;

		for (int i = 1; i < n; i++) {
			for (int j = 1; j <= k && i - j >= 0; j++) {
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i] - h[i - j]));
			}
		}
		System.out.println(dp[n - 1]);
	}
}


Measured memory_bytes: 49180
str = gets.chomp
gets.to_i.times do
  n = gets.split
  f = n[1].to_i
  l = n[2].to_i
  case n[0]
  when 'replace'
    str[f..l] = n[3]
  when 'reverse'
    str[f..l] = str[f..l].reverse
  when 'print'
    puts str[f..l]
  end  
end

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll n;
VL w;

ll secdp(ll n) {
    vector<VL> dp(n, VL(n, 0));
    REP(i, n - 1) if(abs(w[i] - w[i + 1]) <= 1) { dp[i][i + 1] = 2; }
    FOR(i, 2, n) REP(l, n - i) {
        ll r = l + i;
        if(abs(w[l] - w[r]) <= 1 && dp[l + 1][r - 1] == i - 1) {
            dp[l][r] = i + 1;
        }
        FOR(k, l + 1, r + 1) {
            dp[l][r] = max(dp[l][r], dp[l][k - 1] + dp[k][r]);
        }
    }
    return dp[0][n - 1];
}

signed main() {
    while(cin >> n) {
        if(n == 0) break;
        REP(i, n) w.emplace_back(IN());
        cout << secdp(n) << "\n";
        w.clear();
    }
}




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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    atcoder::dsu d(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        d.merge(u, v);
    }
    cout << d.groups().size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 8972
rows=[]
(n=gets.chomp.split.map(&:to_i))[0].times{
rows<< (m=gets.split.map(&:to_i)).push(m.inject(:+))
}
me=Array.new((n[1]+1),0)
(n[1]+1).times{|a|;(n[0]).times{|b|me[a]+=rows[b][a]}}
rows.map{|ans|puts ans.join(" ")};puts me.join(" ")


Measured memory_bytes: 7048
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }

int main() {
	int A; int B; int C; int D;
	while(~scanf("%d%d%d%d", &A, &B, &C, &D)) {
		int X = abs(A - C), Y = abs(B - D);
		int g = gcd(X, Y);
		int ans = (X / g + Y / g - 1) * g;
		printf("%d\n", ans);
	}
	return 0;
}


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

bool somesum(int x, int a, int b){
    int sum=0;
    while(x>0){
        sum += x%10;
        x /= 10;
    }
    
    if(sum >= a and sum <= b){
        return true;
    }else{
        return false;
    }
}
int main(){
    int n,a,b; cin>>n>>a>>b;
    int answer = 0;
    for(int i=1; i<=n; i++){
        if(somesum(i,a,b))
            answer += i;
    }
    cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

long long int a[3][100001];

int main() {
	int n;
	int sum = 0;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}

	for (int i = 0; i < n; i++) {
		if (a.at(i) > b.at(i)) {
			sum += a.at(i) - b.at(i);
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

float pri2(int n) {
    int cnt = 0;
    while (n % 2 == 0) {
        n /= 2;
        cnt++;
    }

    if (cnt >= 2) return 1;
    else if (cnt == 1) return 0.5;
    else return 0;
}

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

    vector<int> a(N);
    rep(i, N) cin >> a[i];

    float cnt = 0;
    rep(i, N) {
        cnt += pri2(a[i]);
    }

    if ((int)cnt >= N / 2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int main() {
	int query;
	cin >> query;
	for (int i = 0; i < query; ++i) {
		long long a, b;
		cin >> a >> b;
		if (a >= b) swap(a, b);
		if (a == b) {
			cout << 2 * a - 2 << endl;
		}
		else if(a+1 == b) {
			cout << 2 * a - 2 << endl;
		}
		else {
			long long geko = sqrt(a * b);
			if (geko * geko == a * b)geko--;
			if (geko * (geko + 1LL) >= a * b) {
				cout << 2 * geko - 2LL << endl;
			}
			else {
				cout << 2 * geko - 1LL << endl;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
const int maxn = 1e7 + 10;
ll n;
 
ll fac[maxn];
ll inv[maxn];
ll ci[maxn];
 
ll quickpow(ll a, ll b){
  ll ans = 1 % mod;
  while(b){
    if(b & 1)
      ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
 
 
void init(){
 
  fac[0] = ci[0] = 1;
  for(ll i = 1; i <= n; i ++){
    fac[i] = 1ll * fac[i - 1] * i % mod;
    ci[i] = ci[i - 1] * 2 % mod;
  }
  inv[n] = quickpow(fac[n], mod - 2);
  for(ll i = n - 1; i >= 0; i --)
    inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
 
 
}
 
 
ll C(ll x, ll y){
  return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod;
}
 
 
int main()
{
  scanf("%lld",&n);
  init();
  ll ans = quickpow(3ll ,n) % mod;
  ll x = 0;
  for(ll i = n / 2 + 1; i <= n; i ++)
    x += C(n, i) * ci[n - i] % mod;
  printf("%lld\n",(ans - x * 2 % mod + mod) % mod);
  return 0;
}

Measured memory_bytes: 234624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
const int mod = 1e9 + 7;
const int MX = 110000;
ll inv[MX], f[MX], invf[MX];
void calc(){
	inv[0] = inv[1] = f[0] = f[1] = invf[0] = invf[1] = 1;
	for (int i = 2; i < MX; i++){
		inv[i] = mod - mod / i * inv[mod % i] % mod;
		f[i] = f[i - 1] * i % mod;
		invf[i] = invf[i - 1] * inv[i] % mod;
	}
}
inline ll C(ll n, ll k){
	return f[n] * invf[k] % mod * invf[n - k] % mod;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	calc();
	int n, k; cin >> n >> k;
	vi a(n); rep(i, n) cin >> a[i];
	sort(all(a));
	ll ans = 0;
	rep(i, n - k + 1) ans += mod - a[i] * C(n - i - 1, k - 1) % mod;
	for(int i = k - 1; i < n; i++) ans += a[i] * C(i, k - 1) % mod;
	cout << ans % mod << endl;
	
	return 0;
}

Measured memory_bytes: 3200
/*** author: yuji9511 ***/
/***
``````````````````````````````````````````````````````````````````````
``````````````````````````````````````````````````````````````````````
``````.JNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNg,``````
```` (MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm ````
````.MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM]````
````(MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMMMMHHHMMMMMMMMMMMMMH"""WMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMMM!   .MMMMMMMM#^         ?HMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMM\     -MMMMMM^   .JNNNg,..MMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMF  .N.  dMMMM\   jMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMM@   JMR   HMM#   (MMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMM`  .MMM[  .MMb   JMMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMM\           (MN.  ,MMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMF   .------   vMb   .WMMMMM#"WMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMM@   (MMMMMMML   WMN,     ``   .dMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMN+...MMMMMMMMNa...MMMNg-.....JMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMF````
````(MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMF````
````,MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM$````
```` 7MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM@ ````
``````.TMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM9!``````
``````````````````````````````````````````````````````````````````````
``` ``````````````````````````````````````````````````````````````````
***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3 >= 22){
        print("bust");
    }else{
        print("win");
    }
    

}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split();
            int a = int.Parse(str[0]), b = int.Parse(str[1]);

            b = b - a;
            a = a % k;
            b = b + a;

            if (a == 0 || b >= k)
            {
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine("NG");
            }
        }
    }
}


Measured memory_bytes: 27484
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll x, ans = 0;
  scanf("%lld", &x);
  ans+=1000*(x/500);
  x%=500;
  ans+=5*(x/5);
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
    int N,A;
    cin >> N >> A;
    bool answer = false;
    for(int i = 0; i <= A; i++) {
        for(int j = 0; j < 3000; j++) {
            if((i + 500*j) == N) {
                answer = true;
            } 
        }
    }
    if(answer == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <functional>
#include <algorithm>
#include <climits>

using namespace std;

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

struct Edge
{
	int to;
	int cost;
};

struct Node
{
	int city_index;
	int total_cost;
	int current_life;

	bool operator >(const Node &a) const
	{
		if (total_cost == a.total_cost)
		{
			return current_life > a.current_life;
		}
		else
		{
			return total_cost > a.total_cost;
		}
	}
};

int main()
{
	int city_count, initial_life, cooler_count, road_count, start_index, goal_index;
	while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index,
		city_count)
	{
		// input
		vector<int> is_cooler(city_count, false);
		REP(i, cooler_count)
		{
			int cooler_index;
			cin >> cooler_index;
			is_cooler[cooler_index] = true;
		}
		vector<vector<Edge>> roads(city_count);
		REP(i, road_count)
		{
			int from, to, cost;
			cin >> from >> to >> cost;
			roads[from].push_back({ to, cost });
			roads[to].push_back({ from, cost });
		}

		// dijkstra
		vector<vector<int>> d(city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost
		d[start_index][initial_life] = 0;
		priority_queue<Node, vector<Node>, greater<Node> > pq;
		pq.push({ start_index, 0, initial_life });
		while (true)
		{
			if (pq.empty())
			{
				cout << "Help!" << endl;
				break;
			}
			auto current_node = pq.top(); pq.pop();
			if (current_node.city_index == goal_index)
			{
				cout << current_node.total_cost << endl;
				break;
			}
			for (auto &road : roads[current_node.city_index])
			{
				if (is_cooler[current_node.city_index])
				{
					REP(i, initial_life - current_node.current_life + 1)
					{
						int life = current_node.current_life + i - road.cost;
						if (life < 0)
						{
							continue;
						}
						int cost = current_node.total_cost + road.cost + i;
						if (cost < d[road.to][life])
						{
							d[road.to][life] = cost;
							pq.push({ road.to, cost, life });
						}
					}
				}
				else
				{
					int life = current_node.current_life - road.cost;
					if (life < 0)
					{
						continue;
					}
					int cost = current_node.total_cost + road.cost;
					if (cost < d[road.to][life])
					{
						d[road.to][life] = cost;
						pq.push({ road.to, cost, life });
					}
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1596
#include <iostream>

int main() {
    std::string s;

    std::cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == ',') std::cout << " ";
        else std::cout << s[i];
    }
    std::cout << "\n";
    return 0;
}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	long long d,t,s;
	cin>>d>>t>>s;

	if((long long)ceil((double)d/s)<=t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n),b(n,0);
  rep(i,n) cin>>a[i];
  
  rep(i,min(k,60)){
  rep(i,n){
    int l=max(0,i-a[i]);
    int m=min(n,i+a[i]);
    b[l]++;
    if(m+1<n) b[m+1]--;
  }
  Rep(i,1,n) b[i]+=b[i-1];
  
  a=b;
  rep(i,n) b[i]=0;
  }
  
  rep(i,n) cout<<a[i]<<endl;
}

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

int main()
{
	double a[10];
	
	for (int i=1;i<=9;i++)   cin>>a[i];
	if((a[4]-a[1]==a[5]-a[2] && a[4]-a[1]==a[6]-a[3] )&& (a[7]-a[1]==a[8]-a[2] && a[7]-a[1]==a[9]-a[3]))
	   cout<<"Yes"<<endl;
	else
	   cout<<"No"<<endl;
	   
	   return 0;
}

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

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

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            int q = Integer.parseInt(in.next());

            int query_op = 0;
            boolean reverseFlg = false;
            StringBuilder sb = new StringBuilder(S);
            StringBuilder sb_rev = new StringBuilder();
            for (int i = 0; i < q; i++) {
                query_op = Integer.parseInt(in.next());
                if (reverseFlg == false && query_op == 1) {
                    reverseFlg = true;
                } else if (reverseFlg == true && query_op == 1) {
                    reverseFlg = false;
                } else if (reverseFlg == false && query_op == 2) {
                    int query_op2 = Integer.parseInt(in.next());
                    char query_ch = in.next().charAt(0);
                    if (query_op2 == 1) {
                        sb_rev.append(query_ch);
                    } else if (query_op2 == 2) {
                        sb.append(query_ch);
                    }

                } else if (reverseFlg == true && query_op == 2) {
                    int query_op2 = Integer.parseInt(in.next());
                    char query_ch = in.next().charAt(0);
                    if (query_op2 == 1) {
                        sb.append(query_ch);
                    } else if (query_op2 == 2) {
                        sb_rev.append(query_ch);
                    }
                }

            }
            if (reverseFlg == true) {
                out.println(sb.reverse().append(sb_rev));
            } else {
                out.println(sb_rev.reverse().append(sb));
            }


        }

    }
}



Measured memory_bytes: 88360
#include <stdio.h>

int main(){
    int n, i, j, k, l, a[10], b[10], c[10];
    
    scanf("%d", &n);
    
    while(n--){
        l = 0;
    
        for(i = 0; i < 10; i++) scanf("%d", &a[i]);
        
        for(i = j = k = 0; i < 10 && !l; i++)
            if     (j == 0 || a[i] > b[j - 1])
                b[j++] = a[i];
            else if(k == 0 || a[i] > c[k - 1])
                c[k++] = a[i];
            else
                l = 1;
                
        printf("%s\n", (l ? "NO" : "YES"));
    }
 
    return 0;
}

Measured memory_bytes: 576
def chk_cake():
    for i in range(0, cake_kind):
        if cakes[i] > 0:
            return True
    return False


def get_max(last_cake):
    max_num = 0
    max_inx = last_cake
    for i in range(0, cake_kind):
        if max_num < cakes[i] and i != last_cake:
            max_num = cakes[i]
            max_inx = i
    return max_inx

counter = 0
cake_num, cake_kind = map(int, raw_input().split())
cakes = map(int, raw_input().split())

last_cake = -1
while chk_cake():
    i = get_max(last_cake)
    cakes[i] = cakes[i] - 1
    if i == last_cake:
        counter += 1
    last_cake = i

print counter

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

string c1[128];
char c2[100];

int main() {
  c1[' '] = "101";
  c1['\''] = "000000";
  c1[','] = "000011";
  c1['-'] = "10010001";
  c1['.'] = "010001";
  c1['?'] = "000001";
  c1['A'] = "100101";
  c1['B'] = "10011010";
  c1['C'] = "0101";
  c1['D'] = "0001";
  c1['E'] = "110";
  c1['F'] = "01001";
  c1['G'] = "10011011";
  c1['H'] = "010000";
  c1['I'] = "0111";
  c1['J'] = "10011000";
  c1['K'] = "0110";
  c1['L'] = "00100";
  c1['M'] = "10011001";
  c1['N'] = "10011110";
  c1['O'] = "00101";
  c1['P'] = "111";
  c1['Q'] = "10011111";
  c1['R'] = "1000";
  c1['S'] = "00110";
  c1['T'] = "00111";
  c1['U'] = "10011100";
  c1['V'] = "10011101";
  c1['W'] = "000010";
  c1['X'] = "10010010";
  c1['Y'] = "10010011";
  c1['Z'] = "10010000";

  for(int i = 0; i < 26; ++i) c2[i] = 'A' + i;
  c2[31] = '?';
  c2[30] = '\'';
  c2[29] = '-';
  c2[28] = ',';
  c2[27] = '.';
  c2[26] = ' ';

  string s;
  while(getline(cin, s)) {
    string t;
    for(int i = 0; i < s.size(); ++i) {
      t += c1[s[i]];
    }
    while(t.size()%5 != 0) t += "0";
    for(int i = 0; i < t.size(); i += 5) {
      string u = t.substr(i,5);
      reverse(u.begin(), u.end());
      int v = 0;
      for(int j = 0; j < u.size(); ++j) {
        if(u[j] == '1') v += (1<<j);
      }
      cout << c2[v];
    }
    cout << endl;
  }
  return 0;
}

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

int main()
{
  int a, b;
  string s;
  bool can = true;
  cin >> a >> b >> s;
  
  if (s.at(a) != '-') can = false;
  
  if (can) {
    for (int i=0; i<s.size(); i++) {
      if (i != a) {
        if (s.at(i) == '-') {
          can = false;
          break;
        }
      }
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
    char S[12], T[12];
    int result = 0;
    scanf("%s", S);
    scanf("%s", T);

    for (int i = 0; i < 3; i++)
    {
        if (S[i] == T[i])
        {
            result++;
        }
    }
    printf("%d\n",result);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < int , int >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 1000005

    int main()
    {

      // unordered_map< pair<char,int> ,ll> :: iterator itr;
      map<ll,ll>m1,m2;
      map<ll,ll> :: iterator itr;
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll ans1,ans2,ans3,ans4;
        ans1=b/c;
        ans2=b/d;
        ans3=(a-1)/c;
        ans4=(a-1)/d;
          //   cout<<ans1<<ans2<<endl;
        ll lcm=(c*d)/(__gcd(c,d));
        //cout<<"LCM"<<lcm<<endl;
        ans1=ans1-ans3;ans2=ans2-ans4;
         //cout<<ans1<<ans2<<endl;
        ll ans5=b/lcm;
        ll ans6=(a-1)/lcm;
        ans5=ans5-ans6;
       // cout<<"ANS5"<<ans5<<endl;
        cout<<((b+1)-a)-(ans1+ans2)+ans5<<endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

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

    int ans = 0;
    for(int i = 0; i < N; ++i){
        ans += a[i] - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var list = new List<int>();
            t.MakeList(list);
            t.LoopPrint(list, 0);
        }

        public void MakeList(List<int> list)
        {
            var input = this.ReadInputOneLine();
            if (input == 0)
            {
                return;
            }
            list.Add(input);
            MakeList(list);
        }

        public void LoopPrint(List<int> list, int i)
        {
            if (i == list.Count)
            {
                return;
            }
            Console.WriteLine("Case " + ++i + ": " + list[i - 1]);
            LoopPrint(list, i);
        }


        public int ReadInputOneLine()
        {
            return int.Parse(Console.ReadLine());
        }
}
}


Measured memory_bytes: 16984