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

bool find(vector<int> arr,int n) {
  	int count = 0;
// 	for(int i=1;i<n;i++) {
//     	if(arr[i]<arr[i-1])	
//         	count++;
//     }
//   	
    vector<int> v = arr;
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++) {
        if(v[i]!=arr[i])
            count++;
    }
    if(count>2)		return false;
  	return true;
}

int main() {
	int n;	cin >> n;
  	vector<int> arr(n);
  	for(int i=0;i<n;i++) cin >> arr[i];
  	int count = 0;
  	if(find(arr,n))	cout << "YES\n";
  	else 			cout << "NO\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<algorithm>
#include<vector>
#include<math.h>
#include<iterator>
#include<ctype.h>
using namespace std;
int main() 
{
	long long int n, i, x=0,l, j, p, q;
	char c;
	vector<char>a;
	cin>>n;
	for(;n!=0;) 
	{
		if(n%26==0)
		c='z';
		else c=(n%26)+96;
		a.push_back(c);
		if(n%26==0)
		n=(n/26)-1;
		else
		n=n/26;
	} 
	for(i=a.size()-1;i>=0;i--) 
	cout<<a[i];
	cout<<endl;
  return 0;
} 


Measured memory_bytes: 3628
/*
我的心脏怦怦跳，监管者就在附近
name:
Algorithm:
writer:Lxs(cdx)
place:
nothing is impossible
*/
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
bool prime(int x){
	 int i;
	 if(x<2) return 0;
	 for(i=2;i*i<=x;i++){
		if(x%i==0){return 0;}
	 }
	 return 1;
}
int main()
{
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll cal(ll a,ll b)
{
    if(a>b)swap(a,b);
    if(b%a==0)return a*(b/a)*2-a;
    return cal(b%a,a)+a*(b/a)*2;
}
int main()
{
    ll n,x;cin>>n>>x;
    cout<<cal(x,n-x)+n<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

	int N;
	int M;	
	int ary[100000]={0};
	int bucket_1[200001]={0};
	int margin[99999]={0};
	int bucket_2[200000]={0};  
	int i,j,k;
	int notpass=0;
	
	
	scanf("%d %d",&N,&M);
	for(i=0;i<M;i++)
		scanf("%d",&ary[i]);
	
	
	if(M<=N){
	   printf("%d\n",0);
	   return 0;
	}
	
	
	///////// BucketSort_1 //////////
	for(i=0;i<M;i++)
		bucket_1[ary[i]+100000]=1;
	for(j=0,i=0;i<M;j++)
		if(bucket_1[j]!=0){
			ary[i]=j-100000;
			i++;
		}
	
	
	for(i=0;i<M-1;i++)
	    margin[i]=ary[i+1]-ary[i];
	
		
	///////// BucketSort_2 //////////
	for(i=0;i<M-1;i++)
		bucket_2[margin[i]-1]+=1;	
	for(i=0,j=0;i<M-1;j++)
		if(bucket_2[j]!=0){
			for(k=0;k<bucket_2[j];k++){
				margin[i]=j+1;
				i++;
			}
		}
	
		
	
	for(i=M-2;M-N-1<i;i--)
	   notpass+=margin[i];
	
	
	printf("%d\n",ary[M-1]-ary[0]-notpass);
	
	
	return 0;
	
}

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


int main() {
  string S, T;
  int A, B;
  string U;
  
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if (S == U) {
    cout << A-1 << " " << B << endl;
  }
  else {
    cout << A << " " << B-1 << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static long p2l(long h, long w) => h * W + w;//0index
        static (long, long) l2p(long l) => (l / W, l % W);
        static long W;
        static void Solve()
        {
            var HWN = Sarray();
            var H = HWN[0];
            W = HWN[1];
            var N = HWN[2];
            var bMasu = new HashSet<long>();
            for (var i = 0; i < N; ++i)
            {
                var ab = Sarray();
                bMasu.Add(p2l(ab[0] - 1, ab[1] - 1));
            }
            var used = new HashSet<long>();
            var zah = new long[] { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
            var zaw = new long[] { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

            var nums = new long[10];
            foreach (var b in bMasu)
            {
                var (h, w) = l2p(b);
                for (var i = 0; i < 9; ++i)//中心
                {
                    var ch = h + zah[i];
                    var cw = w + zaw[i];
                    if (0 < ch && ch < H - 1 && 0 < cw && cw < W - 1 && !used.Contains(p2l(ch, cw)))
                    {
                        var cnt = 0;
                        for (var j = 0; j < 9; ++j)//フィルタ
                        {
                            var hh = ch + zah[j];
                            var ww = cw + zaw[j];
                            if (bMasu.Contains(p2l(hh, ww))) ++cnt;
                        }
                        ++nums[cnt];
                    }
                    used.Add(p2l(ch, cw));
                }
            }
            var square = (H - 2) * (W - 2);
            nums[0] = square - nums.Skip(1).Sum();
            foreach (var n in nums)
                WriteLine(n);
        }
    }
}

Measured memory_bytes: 95420
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<iostream>
#include <stdlib.h>
#include<ctime>
#include <string>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;

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

	int ans;

	ans = min(b / a, c);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;


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

  if( s%10 == 9 || s/10 == 9 )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
int main() {
	// 入力
    int a, b, c, d;
    cin >> a >> b >> c >> d;
 
    if (abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) cout << "Yes";
    else cout << "No";
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<int> X(N);
  double sum = 0;
  
  for(int i = 0; i < N ;i++){
    cin >> X[i];
    sum += double(X[i]);
  }
  sort(X.begin(), X.end());
  
  int mean = round(sum/N);
  
  int distanse = 0;
  
  for(int i = 0; i < N; i++)
    distanse += (X[i] - mean)*(X[i] - mean);
  
  cout << distanse << endl;
  
  return 0;
}

Measured memory_bytes: 256
w, h, x, y = map(int,input().split())
area=w*h/2
awee=0
if x==w/2 or y==h/2:
    awee=0
    if x==w/2 and y==h/2:
        awee=1
else:
    awee=0

print(str(area)+" "+str(awee))

Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
int value[100];
int sp=0;
void Push(const int val){
    value[sp++]=val;
}
int Pop(void){
    return value[--sp];
}
void Operand(const char operand){
    int ch,val=operand-'0';
    while((ch=getchar())!=' '){
        val=val*10+(ch-'0');
    }
    Push(val);
}
void Operator(const char operate){
    int tmp1=Pop(),tmp2=Pop();
    switch(operate){
        case '+': Push(tmp2+tmp1); break;
        case '-': Push(tmp2-tmp1); break;
        case '*': Push(tmp2*tmp1); break;
        default : break;
    }
}
int main(void){
    while(1){
        int ch=getchar();
        if(ch==' ' || ch=='\n'){
            continue;
        }
        if(ch==EOF){
            break;
        }
        switch(ch){
            case '+': Operator(ch); break;
            case '-': Operator(ch); break;
            case '*': Operator(ch); break;
            default : Operand(ch);  break;
        }
    }
    printf("%d\n",Pop());
    return 0;
}


Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  ll n, d, a;
  cin >> n >> d >> a;
  vector<P> V(n);
  rep(i, n) {
    ll x, h;
    cin >> x >> h;
    V[i] = make_pair(x, h);
  }
  sort(all(V));
  ll ans = 0;
  vector<ll> invalid(n + 1, 0);
  ll valid = 0;
  int j = 0;
  rep(i, n) {
    valid -= invalid[i];
    ll remain = V[i].second - valid * a;
    if(remain <= 0) continue;
    ll k = (remain + a - 1) / a;
    valid += k;
    ans += k;
    for(; abs(V[j].first - V[i].first) <= 2 * d && j < n;
        j++) {
    }
    invalid[j] += k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

const long long INF = 2e18;

int N;
int A[400];
long long S[401];
long long dp[400][401];

void to(long long *x ,long long y) {
    if (*x > y) *x = y;
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        S[i + 1] = S[i] + A[i];
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= N; j++) {
            dp[i][j] = INF;
        }
    }
    for (int i = 0; i < N; i++) {
        dp[i][i + 1] = 0;
    }
    for (int d = 2; d <= N; d++) {
        for (int l = 0; l + d <= N; l++) {
            int r = l + d;
            for (int k = l + 1; k < r; k++) {
                to(&dp[l][r], dp[l][k] + dp[k][r] + S[r] - S[l]);
            }
        }
    }
    printf("%lld\n", dp[0][N]);
    return 0;
}


Measured memory_bytes: 1408
H, W = map(int, raw_input().split())
B = [raw_input() for _ in xrange(H)]
r, c = 0, 0
s = set()

while r != H-1 or c != W-1:
    s.add((r, c))
    if r < H-1 and c < W-1:
        if B[r+1][c] == '#' and B[r][c+1] == '#':
            print 'Impossible'
            exit()
        elif B[r+1][c] == '.' and B[r][c+1] == '.':
            print 'Impossible'
            exit()
        elif B[r+1][c] == '#' and B[r][c+1] == '.':
            r += 1
            continue
        else:
            c += 1
            continue
    elif r == H-1:
        if B[r][c+1] == '.':
            print 'Impossible'
            exit()
        else:
            c += 1
            continue
    else:
        if B[r+1][c] == '.':
            print 'Impossible'
            exit()
        else:
            r += 1
            continue

s.add((H-1, W-1))

t = set()
for i in xrange(H):
    for j in xrange(W):
        if B[i][j] == '#':
            t.add((i, j))

if s == t:
    print 'Possible'
else:
    print 'Impossible'


Measured memory_bytes: 2696
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var str1 = ReadLine();
        var str2 = ReadLine();
        var dp = new int[str1.Length + 1, str2.Length + 1];
        for (var i = 0; i <= str1.Length; i++)
            dp[i, 0] = i;
        for (var i = 0; i <= str2.Length; i++)
            dp[0, i] = i;
        for (var i = 1; i <= str1.Length; i++)
            for (var j = 1; j <= str2.Length; j++)
                dp[i, j] = Min(dp[i - 1, j] + 1, Min(dp[i, j - 1] + 1, dp[i - 1, j - 1] + ToInt32(str1[i - 1] != str2[j - 1])));
        WriteLine(dp[str1.Length, str2.Length]);
    }
}


Measured memory_bytes: 19256
export const Main = function (input: Array<Array<string>>) {
  const N = parseInt(input[0][0]);
  let D = input[1].map(el => parseInt(el))
  if (D[0] != 0) { console.log(0); process.exit() }
  const max = Math.max(...D);
  let prev = 1;
  let ans = 1
  let counts = new Array(max + 1).fill(0)
  for (let i = 0; i < D.length; i++) {
    counts[D[i]]++
  }
  if (counts[0] > 1) { console.log(0); process.exit() }

  for (let i = 1; i <= max; i++) {
    let count = counts[i]
    if (count === 0) { console.log(0); process.exit() }
    ans = mul(ans, modpow(prev, count, 998244353), 998244353)
    prev = count;
  }
  console.log(ans)
}
const mul = (a, b, mod) => {
  return ((a >> 16) * b % mod * 65536 + (a & 65535) * b) % mod
}
const modpow = (a: number, n: number, mod: number) => {
  let ans = 1
  while (n > 0) {
    if (n & 1) {
      ans = mul(a, ans, mod);
    }
    a = mul(a, a, mod)
    n >>= 1;
  }
  return ans
}
const parseInput = (input: string) => {
  const lines = input.split("\n");
  if (lines[lines.length - 1] === "") lines.pop();
  return lines.map((el) => (el.split(" ")));
}

Main(parseInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 28760
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    // failed to analyze input format
    // TODO: edit here
    int N,K,d,A;
    cin >> N>>K;
    VI S(N,0);
    REP(i,K) {
        cin >> d;
        REP(j,d) {
            cin >> A;
            S[A-1]++;
        }
    }
    REP (i, N) {
        if (S[i] == 0) ans++;
    }

    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc166/abc166_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc166/abc166_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc166/abc166_b && sh shellscripts/submit_cpp.sh
*/


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

using namespace std;

int main()
{
    int n,x=0,num=0;
    scanf("%d",&n);
    char c;
    for(int i=0;i<n;i++)
    {
        cin>>c;
        if(c=='I')
            x++;
        else
            x--;
        if(num<x)
            num=x;
    }
    printf("%d",num);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Node{
  int player_a,player_b;
  int id;
  std::unordered_set<int> to;
  std::unordered_set<int> from;
  Node(int a,int b,int i):player_a(a),player_b(b),id(i){}
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<Node> node;
  int id=0;
  int matchid[1001][1001]={};
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      matchid[i][j]=-1;
    }
  }

  std::vector<int> player_match[1001];
  for(int i=1;i<=n;i++){
    for(int j=0;j<n-1;j++){
      int a;
      cin>>a;
      player_match[i].push_back(a);
    }
  }

  for(int i=1;i<=n;i++){
    for(auto j:player_match[i]){
      if(matchid[i][j]==-1){
        node.push_back(Node(i,j,id));
        matchid[i][j]=id;
        matchid[j][i]=id;
        id++;
      }
    }
  }

  for(int i=1;i<=n;i++){
    int prev_id=-1;
    for(auto j:player_match[i]){
      if(prev_id==-1){
        prev_id=matchid[i][j];
      }else{
        int curr_id=matchid[i][j];
        if(node[prev_id].to.find(curr_id)==node[prev_id].to.end()){
          node[prev_id].to.insert(curr_id);
        }

        if(node[curr_id].from.find(prev_id)==node[curr_id].from.end()){
          node[curr_id].from.insert(prev_id);
        }
        prev_id=curr_id;
      }
    }
  }



  std::vector<int> t_sort_vec;
  std::queue<int> searchlist;
  for(auto nd:node){
    if(nd.from.empty()){
      searchlist.push(nd.id);
    }
  }

  while(!searchlist.empty()){
    int curr_node_id=searchlist.front();
    Node curr_node=node[curr_node_id];
    t_sort_vec.push_back(searchlist.front());
    searchlist.pop();
    std::unordered_set<int> curr_to=node[curr_node_id].to;
    for(auto t:curr_to){
      Node next_node=node[t];
      int size=next_node.from.size();
      node[curr_node_id].to.erase(t);
      node[t].from.erase(curr_node_id);
      if(node[t].from.empty()){
        searchlist.push(t);
      }
    }
  }

  for(auto nd:node){
    if(!nd.to.empty()){
      cout<<-1<<endl;
      return 0;
    }
  }

  // for(int i=0;i<t_sort_vec.size();i++){
  //   cerr<<i<<" "<<t_sort_vec[i]<<endl;
  // }

  int result=1;
  std::unordered_set<int> playerlist;
  for(int i=0;i<t_sort_vec.size();i++){
    int node_id=t_sort_vec[i];
    if(playerlist.find(node[node_id].player_a)==playerlist.end()&&
       playerlist.find(node[node_id].player_b)==playerlist.end()){
      playerlist.insert(node[node_id].player_a);
      playerlist.insert(node[node_id].player_b);
    }else{
      result++;
      playerlist.clear();
      playerlist.insert(node[node_id].player_a);
      playerlist.insert(node[node_id].player_b);
    }
  }

  cout<<result<<endl;





  return 0;
}


Measured memory_bytes: 185828
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int x=i^j;
            for(int k=0;;k++){
                if((1<<k)&x){
                    a[i][j]=k+1;
                    break;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {
  public static void main(String[] args) {
    String S;
    try(Scanner sc = new Scanner(System.in)) {
      S = sc.next();
    }
    Command command = new Command(S);
    int N = command.size();
    int tokenSize = command.getTokenSize();
    int[] c = new int[N];
    for( int i = 0; i < N; i++ ) {
      c[i] = 1;
    }
    int counter = 0;
    for ( int j = 0; j < tokenSize; j++ ) {
      String token = command.tokenAt(j);
      char tokenType = token.charAt(0);
      int tl = token.length();
      for (int k = 0; k < tl; k++) {
        c[counter+k]--;
        switch(tokenType) {
          case 'R':
            if ( (k+tl) % 2 == 0 ) {
              c[counter+tl]++;
            }
            else {
              c[counter+tl-1]++;
            }
            break;
          case 'L':
            if ( (k+tl) % 2 == 0 ) {
              c[counter-1]++;
            }
            else {
              c[counter]++;
            }
            break;
          default:
            throw new UnsupportedOperationException("Unknown token type: " + tokenType);
        }
      }
      counter += tl;
    }
    System.out.print(c[0]);
    for(int i = 1; i < N; i++) {
      System.out.print(" " + c[i]);
    }
    System.out.println();
  }

  private static class Command {
    private final int N;
    private final String S;
    private final String[] tokens;
    
    public Command(String S) {
      this.S = S;
      this.N = S.length();
      
      List<String> tokenList = new LinkedList<String>();
      char preCh = '0';
      StringBuilder buf = new StringBuilder();
      for(int i = 0; i < N; i++) {
        char ch = S.charAt(i);
        if ( preCh != '0' && ch != preCh ) {
          tokenList.add(buf.toString());
          buf.delete(0, buf.length());
        }
        buf.append(ch);
        preCh = ch;
      }
      if ( buf.length() > 0 ) {
        tokenList.add(buf.toString());
      }
      this.tokens = tokenList.toArray(new String[0]);
    }
    
    public int size() {
      return N;
    }
    
    public int getTokenSize() {
      return tokens.length;
    }
    
    public String tokenAt(int idx) {
      return tokens[idx];
    }
  }
}

Measured memory_bytes: 43148
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;

int main(void)
{
	cin>>a>>b>>c>>d;
	int m,n;
	m=a/d;
	n=c/b;
	if(a%d!=0)
		m++;
	if(c%b!=0)
		n++;
//	cout<<m<<" "<<n<<endl;
	if(m>=n)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
//for (int i = 0; i < N; i++){}

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    int x[N], y[M];


    for (int i = 0; i < N; i++){cin >> x[i];}
    for (int i = 0; i < M; i++){cin >> y[i];}

    bool flag;
    for (int z = -100; z <= 100; z++){
        flag = true;

        if((X<z && z<=Y) != true){
            flag = false;
        }
        for (int i = 0; i < N; i++){
            if(x[i] >= z) flag = false;
        }
        for (int i = 0; i < M; i++){
            if(y[i]<z) flag = false;
        }
        
        if(flag == true){
            cout << "No War" << endl;
            break;
        }
        if(z == 100 && flag == false){
            cout << "War" << endl;
        }
    }
}

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

f=1
for i in range(N):
    if a[i]%2==0:
        if a[i]%5==0 or a[i]%3==0:
            continue
        else:
            f=0
            
if f==0:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 38384
// Problem : J - Sushi
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_j
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 305

//Solution

db dp[N][N][N];

void solve(){
    int n;
    cin>>n;
    vi cnt(4);
    for(int i=0;i<n;i++){
        int x; cin>>x;
        cnt[x]++; 
    }
    db p = 1.0/n;
    for(int k=0;k<=n;k++){
        for(int j=0;j<=n;j++){
            for(int i=0;i<=n;i++){
                int waste = n-i-j-k;
                if(waste == n) continue;
                if(waste < 0) break;
                db p_good = 1.0-waste*p;
                if(i) dp[i][j][k] += dp[i-1][j][k]*i*p;
                if(j) dp[i][j][k] += dp[i+1][j-1][k]*j*p;
                if(k) dp[i][j][k] += dp[i][j+1][k-1]*k*p;
                dp[i][j][k] += 1;
                dp[i][j][k] /= p_good;
            }
        }
    }
    cout<<fixed<<setprecision(12)<<dp[cnt[1]][cnt[2]][cnt[3]];
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int H, W; cin >> H >> W;
  string a[H]; rep(i,H) cin >> a[i];
  char red[H][W], blue[H][W];
  rep(i,H) {
    rep(j,W) {
      if (a[i][j]=='#') { red[i][j]='#'; blue[i][j]='#'; }
      else {
        if ((i%2==0&j!=W-1)||j==0) { red[i][j]='#'; blue[i][j]='.'; }
        else { red[i][j]='.'; blue[i][j]='#'; }
      }
    }
  }

  rep(i,H) { rep(j,W) cout << red[i][j]; cout << endl; }
  cout << endl;
  rep(i,H) { rep(j,W) cout << blue[i][j]; cout << endl; }
  // rep(i,H) { rep(j,W) cout << (red[i][j]=='#'&&blue[i][j]=='#' ? '#' : '.'); cout << endl; }
  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
using namespace std;
int N;
int i = 2;
int num;
int main()
{

  scanf("%d", &N);
  long long ans = (long long)N * (N + 1) - 1;

  for (; i * i <= N; i++)
  {
    num = N / i;
    ans += (long long)(num - i + 1) * i * (i + num) - i * i;
  }
  printf("%lld", ans);
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiil;
typedef pair<pll, ll> pplll;
typedef pair<pli, int> pplii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<pll>> vvpll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define pb push_back
#define tostr to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void print(ld out) { cout << fixed << setprecision(12) << out << '\n'; }
template<typename T> void print(T out) { cout << out << '\n'; }
template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; }
template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } }
template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); }

template<typename T> inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; }
template<typename T> inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; }

ll sum(vector<ll> A) { ll res = 0; for (ll a: A) res += a; return res; }
ll max(vector<ll> A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; }
ll min(vector<ll> A) { ll res = INF; for (ll a: A) chmin(res, a); return res; }

ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; }
int toint(char c) { return c - '0'; }

inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; }
inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; }

inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } }
inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } }

int popcount(ll S) { return __builtin_popcountll(S); }

ll bisearch_min(ll mn, ll mx, function<bool(ll)> func) {
    ll ok = mx;
    ll ng = mn;
    while (ng+1 < ok) {
        ll mid = (ok+ng) / 2;
        if (func(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

ll rec(ll x, ll X) {
    if (x > X) return 0;
    int last = x % 10;
    ll res = 0;
    res += rec(x*10+last, X);
    if (last != 0) {
        res += rec(x*10+(last-1), X);
    }
    if (last != 9) {
        res += rec(x*10+(last+1), X);
    }
    return res + 1;
}

ll K;

bool check(ll X) {
    ll res = 0;
    rep(i, 1, 10) {
        res += rec(i, X);
    }
    return res >= K;
}

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

    cin >> K;

    ll res = bisearch_min(0, 3234566668, check);
    print(res);
    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll oo = 1e18;
const ll mod = 1e9+7;
const int INF = 1 << 30;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    ll a[n];
    map<ll,ll> mp;
    ll all = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    
    for (auto m : mp) {
        all += ((m.second) * (m.second - 1)) / 2; 
    } 

    for (int i = 0; i < n; i++) {
        ll tmpAll = all;
        tmpAll -= (mp[a[i]] * (mp[a[i]] - 1)) / 2;
        mp[a[i]]--;
        tmpAll += mp[a[i]] * (mp[a[i]] - 1) / 2;
        cout << tmpAll << endl;
        mp[a[i]]++;
    }
    
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int N; cin >>N;
    vector<int> P(N), Q(N); cin >> P >> Q;

    vector<int>& p = P < Q ? P : Q;
    vector<int>& q = P < Q ? Q : P;
    
    int i = 0;
    while (p != q) {
        next_permutation(all(p));
        i++;
    }
    cout << i << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;
typedef vector<char> vchar;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================



	ll H, W;
	cin >> H >> W;


	if (H == 1 || W == 1)
	{
		cout << 1;
	}
	else if (H % 2 == 0 || W % 2 == 0)
	{
		cout << H * W / 2;
	}
	else
	{
		cout << (H * W)/2 + 1;
	}




}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

int zero = 0;

int n, m, v, p;
int a[100005], ans;

bool check(int x) {
	int be = a[x];
	int af = a[x] + m;
	int up = a + n - upper_bound(a, a + n, af);
	//cout << be << " " << af << " " << up << endl;
	if (up >= p) return false;
	up = n - p + 1;
	int rest = max(zero, v - (p - 1) - (upper_bound(a, a + n, be) - a));
	rest *= m;
	//cout << " REST" << rest << endl;
	if (rest <= 0) return true;
	int bou = n - p;
	for (int i = (upper_bound(a, a + n, be) - a); i <= min((int)(lower_bound(a, a + n, af) - a - 1), bou); i++) {
		rest -= min(m, af - a[i]);
		//cout <<"#"<< min(m, af - a[i]) << " ";
	}
	//cout << endl;
	if (rest > 0) return false;
	return true;
}

signed main() {
	cin >> n >> m >> v >> p;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	int ok = n - 1, ng = -1;
	while ((ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		//cout << "MID" << mid << endl;
		if (check(mid)) {
			//cout <<"MIDOK"<< mid << endl;
			ok = mid;
		}
		else {
			//cout << "MIDNG" << mid << endl;
			ng = mid;
		}
	}
	cout << n - ok << endl;

	return 0;
}


Measured memory_bytes: 1024
function Main(input) {
    input = input.split(' ');
    var A = Number(input[0]);
    var B = Number(input[1]);
    var X = Number(input[2]);

    if (A == X) {
        console.log('YES');
        return;
    }
    if (A > X) {
        console.log('NO');
    }
    else {
        if (A + B >= X)
            console.log('YES');
        else
            console.log('NO');
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef vector<int> VI;
typedef pair<int, int> PII;
const int DX[] = {-1, 1, 0, 0};
const int DY[] = {0, 0, -1, 1};

#define dump(x) cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << "  (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}


int compress(VI& x1, VI& x2, int w) {
  VI xs;
  for (int i = 0; i < x1.size(); i++) {
    for (int d = -1; d <= 1; d++) {
      int tx1 = x1[i] + d;
      int tx2 = x2[i] + d;
      if (tx1 >= 0 && tx1 < w) xs.push_back(tx1);
      if (tx2 >= 0 && tx2 < w) xs.push_back(tx2);
    }
  }
  
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
 
  for (int i = 0; i < x1.size(); i++) {
    x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
    x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
  }

  return xs.size();
}

void bfs(int x, int y, int w, int h, vector<vector<bool> >& used) {

  queue<PII> que;

  used[x][y] = true;
  que.push(PII(x, y));

  while (!que.empty()) {
    PII p = que.front(); que.pop();
    for (int k = 0; k < 4; k++) {
      int nx = p.first + DX[k];
      int ny = p.second + DY[k];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
        if (used[nx][ny] == false) {
          used[nx][ny] = true;
          que.push(PII(nx, ny));
        }
      }
    }
  }
}

void print(vector<vector<bool> >& used) {
  /*
  cerr << "=====================================" << endl;
  for (int i = 0; i < used.size(); i++) {
    for (int j = 0; j < used[0].size(); j++) cerr << (used[i][j] ? 'x' : '-');
    cerr << endl;
  }
  */
}

PII find_unused(vector<vector<bool> >& used) {
  for (int i = 0; i < used.size(); i++) {
    for (int j = 0; j < used[0].size(); j++) {
      if (used[i][j] == false) {
        return PII(i, j);
      }
    }
  }
  return PII(-1, -1);
}

int solve(int w, int h, VI& x1, VI& y1, VI& x2, VI& y2) {
  // compression
  w = compress(x1, x2, w);
  h = compress(y1, y2, h);

  vector<vector<bool> > used(w, vector<bool>(h, false));
  for (int k = 0; k < x1.size(); k++) {
    for (int x = x1[k]; x < x2[k]; x++) {
      for (int y = y1[k]; y < y2[k]; y++) {
        used[x][y] = true;
      }
    }
  }

  print(used);

  int count = 0;
  while (true) {
    PII unused = find_unused(used);
    if (unused.first != -1) {
      count ++;
      bfs(unused.first, unused.second, w, h, used);
      print(used);
    } else {
      break;
    }
  }
  return count;
}

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

  while (true) {
    int w, h; cin >> w >> h;
    if (w == 0 && h == 0) break;

    int n; cin >> n;
    VI x1(n), y1(n), x2(n), y2(n);
    for (int i = 0; i < n; i++) {
      cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    }

    int ans = solve(w, h, x1, y1, x2, y2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1176
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, c, d = MAP()
print(max([a * c, a * d, b * c, b * d]))


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b&&b==c){
    cout << "1";
  }
  else if(a==b||b==c||c==a){
    cout << "2";
  }
  else{
    cout << "3";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

lli n;
vector<lli>dp;

lli bhardo(lli i)
{
    if(dp[i]!=-1)
    return dp[i];
    lli ans=0;
    for(lli j=3;j<=i;j++)
    {
        ans=(ans+bhardo(i-j))%mod;
    }
    dp[i]=ans;
    return dp[i];
}

int main() {
    cin>>n;
    if(n<3)
    {
        cout<<0;
        return 0;
    }
    dp = vector<lli>(n+1,-1);
    if(n<=5)
    {
        cout<<1;
        return 0;
    }
    dp[0]=1;
    dp[1]=0;
    dp[2]=0;
    dp[3]=1;
    dp[4]=1;
    dp[5]=1;
    cout<<bhardo(n);
	return 0;
}

Measured memory_bytes: 3648
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall

n,m,R=map(int,input().split())
r=list(map(int,input().split()))
s=[[0]*n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    a, b = a-1, b-1
    s[a][b] = c
    s[b][a] = c
s=floyd_warshall(s)   

ans=float('inf')
for i in permutations(r):
    an=0
    for j in range(R-1):
        an+=s[i[j]-1][i[j+1]-1]
    ans=min(ans,an)
print(int(ans))


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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    int h[n+1];
    for(int i=1; i<=n; i++){
        cin >> h[i];
    }
    int ans[n+1];
    ans[1] = 0;
    for(int i=2;i<=n;i++){
        int min = INT_MAX;
        for(int j=1;j<=k;j++)
        if(i>j){
            min = std::min(min,ans[i-j]+abs(h[i]-h[i-j]));
        }
        ans[i] = min;
    }
    cout << ans[n];
    return 0;
}

Measured memory_bytes: 4292
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a, b;
 
    scanf("%d%d", &a, &b);
    if (a < b) printf("a < b\n");
    else if (a > b) printf("a > b\n");
    else printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a=0,b=0,c=0;
    cin>>a>>b>>c;
    if(a<b && b<c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define F first
#define S second
#define NO {cout << "NO\n"; exit(0);}

const int MAXN = 1e5 + 10;

int n;
ll val[MAXN];
vector<ll> adj[MAXN], vec[MAXN];

ll dfs(int v, int p = -1){
	if (adj[v].size() == 1)
		return val[v];

	ll ret = 0;
	for (int u:adj[v])
		if (u^p){
			vec[v].push_back(dfs(u, v));
			ret += vec[v].back();
		}

	ll temp = val[v] * 2 - ret;
	if (temp < 0 || temp > ret) NO
	temp = ret - temp;
	if (temp&1) NO
	
	sort(vec[v].begin(), vec[v].end());
	if (ret - vec[v].back() < temp/2) NO
	ret -= temp;
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)	cin >> val[i];
	for (int i = 0; i < n - 1; i++){
		int a, b;	cin >> a >> b, a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	if (n == 2){
		if (val[0] == val[1])
			cout << "YES\n";
		else
			cout << "NO\n";
		return 0;
	}
	int root = 0;
	for (int i = 0; i < n; i++)
		if (adj[i].size() > 1) root = i;

	if (dfs(root))
		cout << "NO\n";
	else
		cout << "YES\n";
	return 0;
}


Measured memory_bytes: 20480
def execute_process(orders) #orders???????¬??????????
  list = []
  length = orders.length
  for i in 0..(length-1)
    if orders[i][0] == "insert"
      list.unshift(orders[i][1].to_i)
    elsif  orders[i][0] == "delete"
      first_order_number = list.index(orders[i][1].to_i)
      if first_order_number == nil
        next
      else
        list.delete_at(first_order_number)
      end
    elsif orders[i][0] == "deleteFirst"
      list.shift
      #list.delete_at(0)
    elsif orders[i][0] == "deleteLast"
      list.pop()
      #list.delete_at(-1)
    else
      puts "error!"
    end
  end
  return list
end


n = gets.chomp.to_i
orders = []
n.times do
  order = gets.chomp.split
  orders.push(order)
end

output = execute_process(orders)
puts output.join(' ')

Measured memory_bytes: 425640
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	string s;
	cin >> s;
	for(int i = 0;i < 12;i++){
		cout << s[i];
		if(i == 3) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    s = int(input())
    
    l = 0
    r = 10 ** 9
    while r - l != 1:
        m = l + r >> 1
        if m * m >= s:
            r = m
        else:
            l = m
    assert(r * r - s <= 10 ** 9)
    
    print(r, 1)
    print(r * r - s, r)
    print(0, 0)
    
    return 0

main()

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt()-2;
        String s = sc.next();
        int ans = 0;
        for(int i = 0; i < n; i++){
            if("ABC".equals(s.substring(i,i+3))) ans++;
        }
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 21844
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())
ans = 0

temp = 1
bl = False
for _ in range(len(A)):
    temp = A[temp-1]
    ans += 1
    if temp == 2:
        bl = True
        break
print(ans if bl else -1)


Measured memory_bytes: 12516
N=int(input())
if N==0:
    print(0)
else:
    P=0
    M=0
    A=[0 for i in range(33)]
    for j in range(33):
        if N==0:
            break
        else:
            for i in range(33):
                if i%2==0:
                    if 0<=N and N<=(((-2)**i)+P):
                        break
                    else:
                        P+=(-2)**i
                elif i%2==1:
                    if N<=0 and (((-2)**i)+M)<=N:
                        break
                    else:
                        M+=(-2)**i
            A[i]=1
            N-=(-2)**i
            P=0
            M=0
    A=A[::-1]
    ans=0
    for k in range(33):
        ans+=A[k]*(10**(32-k))
    print(ans)
                

Measured memory_bytes: 3064
h, w, d = gets.strip.split.map(&:to_i)
a = h.times.map { gets.strip.split.map(&:to_i) }
q = gets.strip.to_i
lr = readlines.map {|line| line.strip.split.map(&:to_i) }

route = Array.new(h*w+1)

h.times do |y|
  w.times do |x|
    route[a[y][x]] = [y, x]
  end
end

cum_costs = Array.new(h*w+1, 0)
(h*w).times do |i|
  c = i+1
  from = route[c]
  to = route[c+d]
  break if to.nil?
  cum_costs[c+d] = cum_costs[c] + from.zip(to).map {|f,t| (f-t).abs }.inject(:+)
end

lr.each do |l, r|
  p cum_costs[r] - cum_costs[l]
end



Measured memory_bytes: 46972
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 200 + 10;
int N;
int A[MAXN];
int ans;

int main() {
	register int i;
	scanf( "%d", &N );
	for( i = 1; i <= N << 1; ++i )
		scanf( "%d", A + i );
	sort( A + 1, A + (N << 1) + 1 );
	for( i = 1; i <= N << 1; i += 2 )
		ans += A[i];
	printf( "%d\n", ans );
	return 0;
}

Measured memory_bytes: 128