akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define Cannot puts("No"), exit(0);

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' && ch > '9') && (ch != '-')) ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 3e5 + 5;
int a[MAXN];
int stk1[MAXN], stk2[MAXN];

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  int n; read(n);
  for (RI i = 1; i <= n; ++i) read(a[i]);
  for (RI i = 1; i <= n - 2; ++i)
    if (a[i] != i && a[i + 1] != i + 1 && a[i + 2] != i + 2)
      Cannot;
  for (RI i = 1; i <= n; ++i)
    if (a[i] != i) {
      if (a[i + 1] != i + 1) Cannot;
      int l = i, r = i;
      while (a[r + 1] == r + 1 && a[r + 2] != r + 2 && r + 2 <= n) r += 2;
      for (RI j = l; j <= r; ++j)
        if (a[j] < l || a[j] > r) Cannot;
      int top1 = 0, top2 = 0;
      for (RI j = l; j <= r; j += 2)
        if (a[j] < j) stk1[++top1] = a[j];
        else stk2[++top2] = a[j];
      for (RI i = 1; i < top1; ++i)
        if (stk1[i] > stk1[i + 1]) Cannot;
      for (RI i = 1; i < top2; ++i)
        if (stk2[i] > stk2[i + 1]) Cannot;
      i = r;
    }
  puts("Yes");

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size(); ++i) {
    bool flg = true;
    for (int j = i; j < S.size(); ++j) {
      if (S[j] != T[j - i]) {
        flg = false;
        break;
      }
    }
    if (!flg) {
      continue;
    }
    for (int j = 0; j < i; ++j) {
      if (S[j] != T[j + S.size() - i]) {
        flg = false;
        break;
      }
    }
    if (flg) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
}

Measured memory_bytes: 3088
#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;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	string a[] = {"Sunny", "Cloudy", "Rainy"};
	string s; cin >> s;
	rep(i, 3) if(s == a[i]){
		cout << a[(i + 1) % 3] << endl;
		return 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 55
using namespace std;

typedef long long ll;
ll n, m, s, a[N], d[N * N][N];
int main()
{
	ll i, j, k;
	cin >> n >> m;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (i = 0; i < n; i++) {
		for (j = n * m; j >= a[i]; j--) {
			for (k = 1; k <= i; k++) d[j][k + 1] += d[j - a[i]][k];
		}
		d[a[i]][1]++;
	}
	for (i = 1; i <= n * m; i++) {
		for (j = 1; j <= n; j++) if (m * j == i) s += d[i][j];
	}
	cout << s;
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a[4];
    for(int i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    int sum=0;
    for(int i=1;i<3;i++)
    {
        sum+=(a[i]-a[i-1]);
    }
    cout<<sum<<endl;
    return 0;
}


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

int g[15][15];

int main(){
  int n;
  cin >> n;
  rep(i, n) rep(j, n) g[i][j] = -1;
  rep(i,n){
    int Ai;
    cin >> Ai;
    rep(j,Ai){
      int a, x;
      cin >> a >> x;
      a--;
      g[i][a] = x;
    }
  }
  int ans = 0;
  rep(i, 1<<n){
    vector<int> d(n);
    rep(j,n) if(i>>j&1) {
      d[j] = 1;
    }
    bool ok = true;
    rep(j,n){
      if(d[j]){
        rep(k,n){
          if(g[j][k] == -1) continue;
          if(g[j][k] != d[k]) ok = false;
        }
      }
    }
    if(ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
#define maxn 1001
using namespace std;
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
int n, a[maxn], b[maxn];
int main(){
    n = read();
    for(int i = 1; i <= n; i++) 
    a[i] = read(), b[a[i]]++;
    sort(a + 1, a + n + 1);
    for(int i = a[n]; i >= 0; i--){
        int x = max(a[n] - i, i);
        b[x]--; if(b[x] < 0) {
            cout << "Impossible";return 0;
        }
    }
    for(int i = 1; i <= (a[n] + 1) / 2; i++)
    {
        if(b[i]) {cout << "Impossible\n"; return 0;}
    }
    cout << "Possible"; return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

N = INT()
grid = build_grid(2, N, '*', str, space=0, padding=1)

# 最初
if grid[1][1] == grid[2][1]:
    cnt = 3
else:
    cnt = 6
for i in range(2, N+1):
    # 直前が縦向きなら*2
    if grid[1][i-1] == grid[2][i-1]:
        cnt *= 2
    # 直前もここも横向きなら*3
    elif grid[1][i-1] != grid[2][i-1] and grid[1][i] != grid[2][i] and grid[1][i-1] != grid[1][i]:
        cnt *= 3
print(cnt % MOD)


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

bool fizzbuzz(int n, string s){
  if(n % 15 == 0) return (s == "FizzBuzz");
  if(n % 5 == 0) return (s == "Buzz");
  if(n % 3 == 0) return (s == "Fizz");
  /*for(int i = 0 ; i < s.size() ; i++){
    if(s[i] < '0' || s[i] > '9') return false;
    }*/
  return (atoi(s.c_str()) == n);
}

int main(){
  int m,n;
  string s;
  while(cin >> m >> n, m && n){
    vector<int> mem(m);
    int ii = 0;
    for(int i = 0 ; i < m ; i++) mem[i] = i+1;
    
    for(int i = 1 ; i <= n ; i++){
      //int p = i % m;
      cin >> s;
      if(mem.size() == 1) continue;
      else{
	if(fizzbuzz(i,s) == false){
	  mem.erase(remove(mem.begin(), mem.end(), mem[ii]), mem.end());
	  //mem[p] = 0;
	}
	else ii++;
       ii %= mem.size();
	//ii %= m;
      }
    }
    for(int i = 0 ; i < mem.size() ; i++){
      if(mem[i] != 0){
	cout << mem[i] << (i != mem.size()-1 ? " ":"");
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
def positions(s, subs)
  res = []
  i = 0
  while true
    tmp = s.index(subs, i)
    if tmp
      res.push(tmp)
      i = tmp + subs.size
    else
      break
    end
  end
  return res
end

n, q = gets.split.map(&:to_i)
s = gets.chomp
spans = q.times.map { gets.split.map(&:to_i) }
poss = positions(s, "AC")
rsums = []

i = s.size - 1
sum = 0
poss.reverse_each do |pos|
  i.downto(pos+1).each do |j|
    rsums[j] = sum
  end
  sum += 1
  rsums[pos] = sum
  i = pos - 1
end
i.downto(0).each do |j|
  rsums[j] = sum
end

spans.each do |l, r|
  puts rsums[l-1] - rsums[r-1]
end


Measured memory_bytes: 14460
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  long long int n;bool flag=false;
  cin >> n;
  int d=to_string(n).size();
  for(long long int i=1;i*i<=n;i++){
    if(n%i==0){
      long long int k=n/i;
      int si=to_string(i).size();
      int s=to_string(k).size();
      int ans=max(si,s);
      if(d>ans) d=ans;
    }
  }
  cout << d<<endl;
}


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

int n,m;
int c[301],v[301],d[301],l[301];
int dp[301][301];

int solve(int idx,int rem,int *t){
	if(idx == n) return 0;
	if(dp[idx][rem] != -1) return dp[idx][rem];
	int res = 0;
	for(int i=0;i*c[idx]<=rem;i++){
		res = max(res,i*t[idx]+solve(idx+1,rem-i*c[idx],t));
	}
	return dp[idx][rem]=res;
}

int main(void){
	while(cin>>n>>m){
		for(int i=0;i<n;i++){
			char ch = getchar();
			while((ch=getchar()) != '\n');
			cin>>c[i]>>v[i]>>d[i]>>l[i];
		}

		int ans = 0;
		memset(dp,-1,sizeof(dp));
		ans = max(ans,solve(0,m,v));
		memset(dp,-1,sizeof(dp));
		ans = max(ans,solve(0,m,d));
		memset(dp,-1,sizeof(dp));
		ans = max(ans,solve(0,m,l));
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
#include<vector>

using namespace std;



int main() {
	int cnt_people, cnt_relation;
	queue<int> q;
	int cnt_equiv = 0;
	cin >> cnt_people >> cnt_relation;

	vector<int> *adjacent=new vector<int>[cnt_people];
	int* equiv = new int[cnt_people];
	for (int i = 0;i < cnt_people;i++) {
		equiv[i] = -1;
	}
	int tmp1, tmp2;
	for (int i = 0;i < cnt_relation;i++) {
		cin >> tmp1>>tmp2;
		adjacent[tmp1].push_back(tmp2);
		adjacent[tmp2].push_back(tmp1);
	}
	for (int i = 0;i < cnt_people;i++) {
		if (equiv[i] == -1) {
			cnt_equiv++;
			equiv[i] = cnt_equiv;
			q.push(i);
			while (!q.empty()) {
				tmp1 = q.front();
				q.pop();
				for (int j = 0;j < adjacent[tmp1].size();j++) {
					if (equiv[adjacent[tmp1][j]] == -1) {
						equiv[adjacent[tmp1][j]] = cnt_equiv;
						q.push(adjacent[tmp1][j]);
					}
				}
			}
		}
	}
	int cnt_question;
	cin >> cnt_question;
	for (int i = 0;i < cnt_question;i++) {
		cin >> tmp1 >> tmp2;
		if (equiv[tmp1] == equiv[tmp2]) {
			cout << "yes\n";
		}
		else {
			cout << "no\n";
		}
	}
}



Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll n, q;
    string s;
    cin >> n >> q >> s;

    vector<ll> dp(n, 0);
    rep(i, s.size()-1){
        if(s[i]=='A' && s[i+1]=='C') dp[i+1] = dp[i] + 1;
        else dp[i+1] = dp[i];
    }

    //rep(i, n) cout << dp[i] << " ";
    //cout << endl;

    rep(i, q){
        ll l, r;
        cin >> l >> r;
        --l;
        --r;

        cout << dp[r] - dp[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1872
from itertools import combinations
from collections import defaultdict
n = int(input())
s = input()

d = defaultdict(int)
left = set()
for r in range(n+1):
    for cl in combinations(range(n),r):
        sl = ""
        sr = ""
        for i in range(n):
            if i in cl:
                sl += s[i]
            else:
                sr += s[i]
        left.add(sl+","+sr)
        d[sl+","+sr] += 1

res = 0
for r in range(n+1):
    for cl in combinations(range(n,2*n),r):
        sl = ""
        sr = ""
        for i in range(n,2*n):
            if i in cl:
                sl = s[i] + sl
            else:
                sr = s[i] + sr
        if sr+","+sl in left:
            res += d[sr+","+sl]

print(res)

Measured memory_bytes: 123228
stores, target = [int(i) for i in input().split()]

values = []
for i in range(stores):
    values.append([int(j) for j in input().split()])

values.sort(key=lambda x:x[0])

expence = 0

for i in range(len(values)):
    if values[i][1] < target:
        expence += values[i][0] * values[i][1]
        target -= values[i][1]
    elif values[i][1] == target:
        expence += values[i][0] * values[i][1]
        break
    elif values[i][1] > target:
        expence += values[i][0] * target
        break
print(expence)

Measured memory_bytes: 22820
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
    double n;
    while (cin >> n) {
        double ans = n;
        for (int i = 2; i <= 10; i++) {
            if (i % 2) {
                n /= 3;
                ans += n;
            } else {
                n *= 2;
                ans += n;
            }
        }
        printf("%.9lf\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3100
import java.util.*;
public class Main{
  public static int n,m;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    m = sc.nextInt();
    int[] s = new int[m];
    int[] c = new int[m];
    for(int i=0;i<m;i++){
      s[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    
    System.out.println(solve(s,c));
  }
  
  public static String solve(int[] s,int[] c){
    for(int i=0;i<1000;i++){
      String str=String.valueOf(i);
      if(ok(str,s,c)) return str; 
    }
    return "-1";
  }
  
  public static boolean ok(String str,int[] s,int[] c){
    if(n!=str.length()) return false;
    for(int i=0;i<m;i++){
      if(str.charAt(s[i]-1)!=c[i]+'0') return false;
    }
    return true;
  }
  
}

Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String AStr[] = br.readLine().split(" ");
		int A[] = new int[n];

		for(int i = 0 ; i < n ; i++) A[i] = Integer.parseInt(AStr[i]);

		bubbleSort(n,A);

	}

	public static void bubbleSort(int n, int[] A){
		boolean flag = true;
		int count = 0;
		int y = 1;
		while(flag){
			flag = false;
			for(int i = n - 1 ; y <= i ; i-- ){
				if(A[i] < A[i - 1]){
					int tmp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = tmp;
					flag = true;
					count++;
				}
			}
			y++;
		}

		StringBuilder sb = new StringBuilder();
		for(int i = 0 ; i < n; i++){
			sb.append(A[i]);
			sb.append(" ");
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
		System.out.println(count);

	}
}

Measured memory_bytes: 24352
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	str s;
	cin >> s;
	int one = 0, zero = 0;
	rep(i, s.size())
	{
		if (s[i] == '1')
			one++;
		else
			zero++;
	}
	cout << min(one, zero) * 2 << endl;
	return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll dp[61][2][2][2];
int main(){
    ll l,r;cin>>l>>r;
    dp[60][0][0][0]++;
    for(ll i=60;i>0;i--){
        rep(j,2)rep(k,2)rep(s,2){
            rep(x,2)REP(y,x,2){
                int nj,nk,ns;
                if(s)ns=1;
                else if(x&&y)ns=1;
                else if(x!=y)continue;
                else ns=0;
                if(j)nj=1;
                else if((!x)&&(l>>(i-1)&1))continue;
                else if(x&&!(l>>(i-1)&1))nj=1;
                else nj=0;
                if(k)nk=1;
                else if((!y)&&(r>>(i-1)&1))nk=1;
                else if(y&&!(r>>(i-1)&1))continue;
                else nk=0;
                dp[i-1][nj][nk][ns]+=dp[i][j][k][s];
                dp[i-1][nj][nk][ns]%=mod;
            }
        }
    }
    ll ans=0;
    rep(j,2)rep(k,2)rep(s,2)ans+=dp[0][j][k][s];
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin>>N;
  vector<pair<int,int>> a(N);
  for(int i;i<N;i++){
    cin>>a[i].first;
    a[i].second=i+1;
  }
  sort(a.begin(),a.end());
  for(auto& x:a){
    cout<<x.second<<' ';
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1664
n, k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float('inf')]*n
dp[0] = 0
dp[1] = abs(h[0]-h[1])
if n ==2: print(dp[1]);exit()
for i in range(n):
    for j in range(1,k+1):
        if i + j <n:
            dp[i+j] = min(dp[i+j],dp[i] + abs(h[i]-h[i+j]))
    
print(dp[-1])

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

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i,n-1)
        cin >> b.at(i);
    int ans=b.at(0);
    if(n!=2){
        rep(i,n-2){
            if(b.at(i)<b.at(i+1)) ans+=b.at(i);
            else ans+=b.at(i+1);
        }
    }
    ans+=b.at(n-2);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000001
typedef long long ll;
typedef vector<int> arr;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;

ll solve(int n, ll W, longarr w, arr v) {
	ll maxval = n * 1000;
	longmat dp(n + 1, longarr( maxval + 1, inf ));

	for (int i = 0; i < n; ++i) {dp[i][0] = 0;}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= maxval; ++j) {
			ll x = dp[i - 1][j];
			ll y = (j >= v[i - 1]) ? (w[i - 1] + dp[i - 1][j - v[i - 1]]) : inf;
			dp[i][j] = min(x, y);
		}
	}
	int ans;
	for (int i = maxval; i >= 0; --i) {
		if (dp[n][i] <= W) {ans = i; break;}
	}
	return ans;
}

int main() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	int n; ll W;
	cin >> n;
	cin >> W;
	longarr w(n, 0);
	arr v(n, 0);
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> v[i];
	}
	cout << solve(n, W, w, v);

}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = unsigned long long;
using p = pair<int, int>;

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

    vector<int> d(4);

    rep(i, 0, N)
    {
        string s;
        cin >> s;
        if (s == "AC")
        {
            ++d[0];
        }
        else if (s == "WA")
        {
            ++d[1];
        }
        else if (s == "TLE")
        {
            ++d[2];
        }
        else if (s == "RE")
        {
            ++d[3];
        }
    }

    cout << "AC x " << d[0] << endl;
    cout << "WA x " << d[1] << endl;
    cout << "TLE x " << d[2] << endl;
    cout << "RE x " << d[3] << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;
using Pos = std::pair<int, int>;
//cout<<fixed<<std:cout<<fixed<<setprecision(2)<<Max<<endl;
constexpr int mod = 1e9 + 7;

int main() {
    constexpr int inf=10000;
    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(N);

    int asum=1;
    int bsum=1;
    for(int i = 0; i < N; ++i) {
        int A,B,C;
        cin>>A>>B>>C;
        a[i]=A;
        b[i]=B;
        c[i]=C;
        asum+=A;
        bsum+=B;
    }

    vector<vector<vector<int>>> dp(N,vector<vector<int>>(asum, vector<int>(bsum,inf)));
    dp[0][0][0]=0;
    dp[0][a[0]][b[0]]=c[0];
    for(int i=1;i<N;++i){
        for(int j=0;j<asum;++j){
            for(int k=0;k<bsum;++k){
                if(j-a[i]>=0 && k-b[i]>=0){
                    dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
                }else{
                    dp[i][j][k]=dp[i-1][j][k];
                }
            }
        }
    }

    int ans=inf;
    int ma=Ma;
    int mb=Mb;
    while(ma<asum && mb<bsum){
        ans=min(ans, dp[N-1][ma][mb]);
        ma+=Ma;
        mb+=Mb;
    }

    if(ans<inf)cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}


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

sp = []

for i in range(n):
    s, p = input().split()
    sp.append([s, int(p), i+1])

sp.sort(key=lambda n: n[1], reverse=True)
sp.sort(key=lambda n: n[0])

for c in range(n):
    sp[c].append(c + 1)

for a in range(n):
    print(sp[a][2])

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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define      TEST    ll t ; cin >> t ; while( t -- )


//------------------------------------------------------------------------//

#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)

//------------------------------------------------------------------------//

const ll big = 10e15 + 11 ;


int  main (  ) {

    FASTIO ;

    ll  x ;
    cin >> x ;

    vector < pair < ll , ll > > v;
    v.pb( { 0 , 0 } ) ;

    for( ll i = 1 ; i <= 200 ; i++ ){
        ll y ;
        y = i *i * i * i *i ;

        v.pb( { y , i } ) ;
        v.pb( { -y , -i } ) ;
    }

    sort( v.begin( ) , v.end(  )) ;

    int   len = v.size( ) , flag  ;

    for( int i = 0 ; i < len - 1 ; i++ ){
        ll b = v[ i ].ff ;
        flag = 0 ;

        for( int j = i + 1 ; j < len ; j++ ){
            ll a = v[ j ].ff ;

            if( a - b == x ){
                cout << v[ j ].ss << " " << v[ i ].ss ;

                flag = 1 ;
                break ;
            }
        }
        if( flag ) break ;
    }

    return  0 ;
}


Measured memory_bytes: 3672
N = int(input())
a = list(map(int, input().split()))

## dp[i][j]: i???????????°????????§??§j????????????????????°
dp = [[0 for j in range(21)] for i in range(N-1)]

dp[0][a[0]] = 1
for i in range(1, N-1):
    for j in range(21):
        if (j - a[i]) in range(21):
            dp[i][j] += dp[i-1][j-a[i]]
        if (j + a[i]) in range(21):
            dp[i][j] += dp[i-1][j+a[i]]
        
print(dp[N-2][a[N-1]])

Measured memory_bytes: 7740
A,B,C,D = map(int,input().split())
ans = 0

# if B >= C:
#     if D >= A:
#         if A <= C:
#             ans = B-C
#         if A > C:
#             ans = B-A
    

# elif B >= D:
#     if D >= A:
#         if A <= C :
#             ans = D-C
#         if A > C:
#             ans = D-A

# BとDのうち小さい方-AとCのうち大きい方　で求まる
if min(B,D)>=max(A,C):
    ans = min(B,D)-max(A,C)

    


print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <complex>
#include <algorithm>
using namespace std;
typedef complex<double> P;
static const double EPS = 1e-6;
namespace std {
  bool operator<(const P& a, const P& b)
  {
    if (fabs(a.real() - b.real()) < EPS) {
      return a.imag() < b.imag();
    } else {
      return a.real() < b.real();
    }
  }
};

inline double dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }
inline double cross(const P& a, const P& b) { return a.real()*b.imag() - b.real()*a.imag(); }
struct line
{
  P a, b;
  line() {}
  line(const P& p, const P& q) : a(p), b(q) {}
};

struct segment
{
  P a, b;
  segment() {}
  segment(const P& x, const P& y) : a(x), b(y) {}

  inline bool intersects(const line& ln) const
  {
    return cross(ln.b - ln.a, a - ln.a) * cross(ln.b - ln.a, b - ln.a) < EPS;
  }

  inline P intersection(const line& ln) const
  {
    const P x = b - a;
    const P y = ln.b - ln.a;
    return a + x*(cross(y, ln.a - a))/cross(y, x);
  }

  inline bool parallel(const line& ln) const
  {
    return abs(cross(ln.b - ln.a, b - a)) < EPS;
  }
};
int main()
{
  int N;
  while (cin >> N && N != 0) {
    vector<P> ps;
    for (int i = 0; i < N; i++) {
      int x, y;
      cin >> x >> y;
      ps.push_back(P(x, y));
    }

    vector<P> qs(ps);
    for (int i = 0; i < N; i++) {
      const line ln(ps[i], ps[i] + P(1, 0));
      for (int j = 0; j < N-1; j++) {
        if (fabs(ps[i].imag() - ps[j].imag()) < EPS) {
          continue;
        }
        if (fabs(ps[i].imag() - ps[j+1].imag()) < EPS) {
          continue;
        }
        const segment s(ps[j], ps[j+1]);
        if (!s.parallel(ln) && s.intersects(ln)) {
          const P p = s.intersection(ln);
          qs.push_back(p);
        }
      }
    }
    sort(qs.begin(), qs.end());
    const int M = qs.size();

    map<int, double> dist;
    dist.insert(make_pair(M-1, 0.0));
    priority_queue<pair<double, int> > q;
    q.push(make_pair(0.0, M-1));
    while (!q.empty()) {
      const double c = -q.top().first;
      const int left = q.top().second/M;
      const int right = q.top().second%M;
      q.pop();
      if (left == right) {
        printf("%.3f\n", c);
        break;
      }
      if (dist[left*M+right] < c) {
        continue;
      }
      for (int dl = -1; dl <= 1; dl++) {
        for (int dr = -1; dr <= 1; dr++) {
          const int l = left + dl;
          const int r = right + dr;
          if (l < 0 || r >= M) {
            continue;
          }
          if (fabs(qs[l].imag() - qs[r].imag()) < EPS) {
            const double cc = c + abs(qs[l] - qs[left]) + abs(qs[r] - qs[right]);
            const int p = l*M + r;
            map<int,double>::iterator it = dist.find(p);
            if (it == dist.end()) {
              dist.insert(make_pair(p, cc));
              q.push(make_pair(-cc, p));
            } else if (cc+EPS < it->second) {
              it->second = cc;
              q.push(make_pair(-cc, p));
            }
          }
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(N)

A_sorted = {a: i for i, a in enumerate(sorted(A), start=1)}
ans = 0
for j, a in enumerate(A):
    ans += j - BIT.sum(A_sorted[a])
    BIT.add(A_sorted[a], 1)

print(ans)



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

int main() {
  int n;
  string str;
  cin >> n >> str;
  if(n % 2 != 0){
    cout << "No" << endl;
    return 0;
  }else{
    for(int i=0; i<(n/2); i++) {
      if(str[i] != str[i+n/2]){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main(int argc, const char * argv[])
{
    string r1;
    string r2;
    string r3;
    
    getline(cin,r1);
    getline(cin,r2);
    getline(cin,r3);
    
    string tot = "";
    tot.push_back(r1.at(0));
    tot.push_back(r2.at(1));
    tot.push_back(r3.at(2));
    
    
    cout << tot << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

Measured memory_bytes: 1632
#include <stdio.h>

int main(void) {
	int num;
    double h,m,bmi;
    while(scanf("%d,%lf,%lf",&num,&m,&h) != EOF){
        bmi = m / (h * h);
        if(bmi >= 25) printf("%d\n",num);
    }
	return 0;
}

Measured memory_bytes: 628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int A,B;
   cin >> A >> B;
   cout << A*B << endl;
   return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;



int main(void) {
    ll N;
    cin >> N;
    ll a[MAX];
    ll i;
    
    for(i=0; i<N; i++)
        cin >> a[i];
    sort(a, a+N);
    if(a[N-1]-a[0]>1) {
        pt("No");
    }else if(a[0]==a[N-1]) {
        if(a[0]*2<=N || a[0]==N-1) pt("Yes");
        else pt("No");
    }else {
        ll x=0, y=0, z=0;
        for(i=0; i<N; i++)
            if(a[0]==a[i]) y++;
        x=(N-y)/2;
        
        if((N-y)%2==1) pt("No");
        else if(x+y!=a[N-1]) pt("No");
        else if(N-a[N-1]<0) pt("No");
        else pt("Yes");
        
    }
}







Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        String s = scanner.nextLine();
        String s1 = s + s;
        String p = scanner.nextLine();
        if(s1.contains(p)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

using namespace std;
mt19937_64 rng(58);

int gcd(int a, int b) {
    if (b > a) swap(a, b);
    if (b==0) return a;
    return gcd(b, a % b);
}

int gcd3(int a, int b, int c) {
    return gcd(a, gcd(b, c));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k;
    long long ans = 0;
    cin >> k;
    for (int a = 1; a <= k; a++)
    for (int b = 1; b <= k; b++)
    for (int c = 1; c <= k; c++)
        ans += gcd3(a, b, c);
    cout << ans << "\n";
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N;
    cin >> N;
    if (N%2==0) cout << N << endl;
    else cout << N*2 << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
    A[i],B[i]=map(int,input().split())
    C[i] = [B[i],A[i]]
C.sort()
time = 0

for i in range(len(C)):
    time += C[i][1]
    if C[i][0] < time:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 38812
#include <iostream>

using namespace std;

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int m = max(a, max(b, c));
  int p = m;
  for (int i = 0; i < x; i++) {
    p *= 2;
  }
  int ans = a + b + c - m + p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,tmp,cntA,cntB,ans;

int main(){
    cin>>N;
    string S[N];
    rep(i,N){
        cin>>S[i];
        rep(j,S[i].length()-1){
            if(S[i][j]=='A'&&S[i][j+1]=='B')ans++;
        }
        if(S[i][0]=='B'&&S[i][S[i].length()-1]=='A')tmp++;
        else if(S[i][0]=='B')cntB++;
        else if(S[i][S[i].length()-1]=='A')cntA++;
    }
    if(tmp==0){
        ;
    }
    else if(tmp==1){
        if(cntA&&cntB)ans++;
        else{
            if(cntA>cntB)cntB++;
            else cntA++;
        }
    }
    else{
        ans+=tmp-1;
        if(cntA&&cntB)ans++;
        else{
            if(cntA>cntB)cntB++;
            else cntA++;
        }
    }
    out(ans+min(cntA,cntB));
}


Measured memory_bytes: 768
def solve(n,s):
  cnt = 0
  for i in range(len(s)-2):
    if "A" == s[i] and "B" == s[i+1] and "C" == s[i+2]:
      cnt+=1
  return cnt
 
n = int(input())
s = input()
ans = solve(n,s)
print(ans)

Measured memory_bytes: 9124
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<cstdlib>
using namespace std;

string O[27]={"111","112","113","121","122","123","131","132","133","211","212","213","221","222","223","231","232","233","311","312","313","321","322","323","331","332","333"};

string cal(vector<string> V,int in)
{  
  for(int i=0;i<V.size();i++){
    if(V[i]=="("){
      int l=1,r=0;
      vector<string> v;
      string s;
      V.erase(V.begin()+i);
      while(1){
	if(V[i]=="(")l++;
	if(V[i]==")")r++;
	v.push_back(V[i]);
	V.erase(V.begin()+i);	 
	if(r==l){
	  v.pop_back();
	  s=cal(v,in);
	  V.insert(V.begin()+i,s);
	  break;
	}
      }
    }
  }
  for(int k=1;k<=3;k++){
    for(int i=0;i<V.size();i++){
      if(V[i]=="+"){
	if((O[in][0]-'0')==k){
	  long long a=atoll(V[i-1].c_str())+atoll(V[i+1].c_str());
	  stringstream ss;
	  ss << a;
	  string S=ss.str();
	  V.erase(V.begin()+i+1);
	  V.erase(V.begin()+i);
	  V.erase(V.begin()+i-1);
	  V.insert(V.begin()+i-1,S);
	  i-=2;
	}
      }
      else if(V[i]=="-"){
	if((O[in][1]-'0')==k){
	  long long a=atoll(V[i-1].c_str())-atoll(V[i+1].c_str());
	  stringstream ss;
	  ss << a;
	  string S=ss.str();
	  V.erase(V.begin()+i+1);
	  V.erase(V.begin()+i);
	  V.erase(V.begin()+i-1);
	  V.insert(V.begin()+i-1,S);
	  i-=2;
	}
      }
      else if(V[i]=="*"){
	if((O[in][2]-'0')==k){
	  long long a=atoll(V[i-1].c_str())*atoll(V[i+1].c_str());
	  stringstream ss;
	  ss << a;
	  string S=ss.str();
	  V.erase(V.begin()+i+1);
	  V.erase(V.begin()+i);
	  V.erase(V.begin()+i-1);
	  V.insert(V.begin()+i-1,S);
	  i-=2;
	}
      }
    }
  }
  return V[0];
}
int main()
{
  string s,samp;
  long long ans=0;
  vector<string> V;
  cin>>s;
  for(int i=0;i<s.length();i++){
    if('0'<=s[i] && s[i]<='9'){
      samp+=s[i];
      if(i==s.length()-1)V.push_back(samp);
    }
    else {
      if(!samp.empty()){
	V.push_back(samp);
	samp="";
      }
      samp=s[i];
      V.push_back(samp);
      samp="";
    }
  }
  for(int i=0;i<27;i++){
    string a=cal(V,i);
    long long b=atoll(a.c_str());
    if(i==0)ans=b;
    else ans=max(b,ans);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    int a, b; cin>>a>>b;
    int res=0;
    for(int n=a; n<=b; ++n) {
        string s=to_string(n);
        string t=s;
        reverse(begin(t), end(t));
        if (s==t) ++res;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<stack>
using namespace std;
int main()
{
	long long  n, m;
	cin >> n >> m;
	if (n == 1 && m == 1) cout << "1" << endl;
	else if (n == 1) cout << m - 2 << endl;
	else if (m == 1) cout << n - 2 << endl;
	else cout << (m - 2)*(n - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
while not (n == 0 and x == 0):
    count = 0
    for a in range(1, n-1):
        for b in range(a+1, n):
            for c in range(b+1, n+1):
                if a + b + c == x:   
                    count = count + 1
    print(count)
    n, x = map(int, input().split())


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  map<int,int>m;
  rep(i,4){
    int t;cin>>t;
    m[t]++;
  }
  if(m[1]&&m[9]&&m[7]&&m[4]) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}

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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = max({a + b, a - b, a * b});
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  int a,b[100010]={};
  for(int i=0;i<n;++i){
    cin>>a;
    b[a-1]++;
    b[a]++;
    b[a+1]++;
  }

  a=0;
  for(int i=0;i<100010;++i)a=max(a,b[i]);

  cout << a << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int p = sc.nextInt();
			if(n==0&&p==0) break;
			int[] st = new int[n];
			int flag=0,flag2=0,end=p;
			while(true){
				if(p==0){
					p=st[flag];
					st[flag]=0;
				} else {
					st[flag]+=1;
					p--;
					if(p==0){
						for(int i=0;i<n;++i){
							if(st[i]==end){
								System.out.println(i);
								flag2=1;
								break;
							}
						}
					}
				}
				if(flag2==1) break;
				flag++;
				if(flag==n) flag=0;
			}
		}
	}
}


Measured memory_bytes: 27268
a,b,q=map(int, input().split())
x=[-10**11]+[int(input()) for i in range(a)]+[10**11]
y=[-10**11]+[int(input()) for i in range(b)]+[10**11]
p=[int(input()) for i in range(q)]
import bisect
ans=[]
for i in p:
    xi=bisect.bisect_left(x,i)
    yi=bisect.bisect_left(y,i)
    a1=max(x[xi],y[yi])-i
    a2=x[xi]-i+x[xi]-y[yi-1]
    a3=y[yi]-i+y[yi]-x[xi-1]
    a4=i-x[xi-1]+y[yi]-x[xi-1]
    a5=i-y[yi-1]+x[xi]-y[yi-1]
    a6=abs(min(x[xi-1],y[yi-1])-i)
    ans.append(min(a1,a2,a3,a4,a5,a6))
for i in ans:print(i)

Measured memory_bytes: 20144
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanInt := func() int {
		scanner.Scan()
		num, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatal(err)
		}
		return num
	}

	N, W := scanInt(), scanInt()
	w, v := make([]int, N), make([]int, N)
	for i := 0; i < N; i++ {
		w[i], v[i] = scanInt(), scanInt()
	}
	memo := make([][]int64, N+1)
	for i := 0; i < N+1; i++ {
		memo[i] = make([]int64, W+1)
	}

	for i := 1; i <= N; i++ {
		for j := 1; j <= W; j++ {
			if w[i-1] > j {
				memo[i][j] = memo[i-1][j]
				continue
			}
			memo[i][j] = max(memo[i-1][j], memo[i-1][j-w[i-1]]+int64(v[i-1]))
		}
	}

	fmt.Println(memo[N][W])
}


Measured memory_bytes: 81792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
#define a_macro(args...) sum(args)
#define mp make_pair
#define eb emplace_back
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

typedef long long ll;
const ll mod = 1e9+7;

typedef tuple<int,int,int> State; // operator< defined
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef double ld;

int main(int argc, const char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int t,n,i,s;
	    cin>>s>>n;
	    if(n>=s)
        cout<<"unsafe\n";
      else
        cout<<"safe\n";



    
#ifndef LOCAL_DEFINE
    cerr << "Time elapsed: "<< 1e1 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL_DEFINE
    return 0;
}

Measured memory_bytes: 3800
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition) cout << "Yes" << '\n'; else{ cout << "No" << '\n'; }
#define YES(condition) if(condition) cout << "YES" << '\n'; else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition) cout << "yes" << '\n'; else{ cout << "no" << '\n'; }






int main() {
    string n, ans;
    cin >> n;
    REP(i, 3){
        if(n[i] == '1') ans += '9';
        else ans += '1';
    }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    const int n = 9;
    const int time = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2;
    int t;
    int a[n], b[n];

    cin >> t;
    while (t--) {
        int sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            sum += a[i];
        }
        for (int i = 0; i < n; ++i) {
            cin >> b[i];
            sum += b[i];
        }

        sum = (sum + 1) / 2;
        sort(a, a + n);
        sort(b, b + n);
        int win = 0;
        do {
            int a_s = 0;
            for (int i = 0; i < n; ++i) {
                if (a[n - i - 1] > b[i])
                    a_s += a[n - i - 1] + b[i];
                if (a_s >= sum)
                    break;
            }
            if (a_s >= sum)
                ++win;
        } while (next_permutation(b, b + n));

        printf("%.5lf %.5lf\n", (double)win / time, (double)(time - win) / time);
    }

    return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL C;
LL K;
vector<LL>v;
LL T[100001];

int main(){
	cin>>N>>C>>K;
	REP(i,N){
		cin>>T[i];
		v.push_back(T[i]);
	}
	LL now=-1e9-2;
	LL ans=0;
	LL cnt=C;
	sort(v.begin(),v.end());
	REP(i,N){
		if(cnt==C){
			ans++;
			cnt=1;
			now=v[i]+K;
		}else{
			if(v[i]>now){
				ans++;
				cnt=1;
				now=v[i]+K;
			}else{
				cnt++;
			}
		}
	}
	
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1912
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
        ans += i * (i + 1) / 2;
    for (ll i = 1; i < n; i++)
    {
        ll u, v;
        cin >> u >> v;
        if (u > v)
            swap(u, v);
        ans -= u * (n - v + 1);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3636
N = int(input())
color = ["w" for _ in range(N)]
d = [float("inf") for _ in range(N)]
p = [-1 for _ in range(N)]

# Make M
M = [[-1]*N for _ in range(N)]
for i in range(N):
    input_list = list(map(int, input().split()))
    ii = input_list.pop(0)
    k = input_list.pop(0)
    jj = 0
    while jj <= 2*k - 2:
        M[ii][input_list[jj]] = input_list[jj+1]
        jj += 2

d[0] = 0
while True:
    mincost = float("inf")
    for i in range(N):
        if color[i] != "b" and d[i] < mincost:
            mincost = d[i]
            u = i
    
    if mincost == float("inf"):
        break
    color[u] = "b"

    for v in range(N):
        if color[v] != "b" and M[u][v] != -1:
            if d[v] > M[u][v] + d[u]:
                d[v] = M[u][v] + d[u]
                p[v] = u
                
for i in range(N):
    print("{} {}".format(i, d[i]))


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

struct Card{ char suit, value; };

void bubble(struct Card A[], int N) {
  for(int i=0; i<N; i++) {
    for(int j=N-1; j>=i; j--) {
      if(A[j].value < A[j-1].value) {
        Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for(int i=0;i<N;i++) {
    int minj = i;
    for(int j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for(int i=0; i<N; i++) {
    if(i>0) cout << " ";
      cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for(int i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(void) {
  Card C1[100], C2[100];
  int N;

  cin >> N;
  for(int i=0;i<N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3080