akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
double PI = 3.14159265;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<string>;
using DGraph = vector<vector<pair<int, int>>>;

const long long INF = 1LL << 60;
//---//
int H[100010] = {};

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

	rep(i, n)cin >> H[i];

	Graph g(n);
	int a, b;
	rep(i, m) {
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int sum = 0;
	rep(i, n) {
		bool flag = 1;
		for(auto v:g[i])if(H[i]<=H[v])flag=0;
		if (flag == 1)sum++;
	}
	cout << sum << endl;

	return 0;
}


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

typedef long long int llint;

int n;
llint h;

struct sword {
  llint atk;
  bool lim;
  
  sword() {}
  sword(llint atk, bool lim) : atk(atk), lim(lim) {}

  bool operator < (const sword &a) const {
    return atk > a.atk;
  }
};

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

  vector<sword> s;
  llint a, b;
  for(int i = 0; i < n; i++) {
    cin>> a >> b;
    s.push_back(sword(a, false));
    s.push_back(sword(b, true));
  }

  sort(s.begin(), s.end());
  
  int cnt = 0;
  for(int i = 0; i < s.size(); i++) {
    if(!s[i].lim) {
      cnt += h / s[i].atk + (h % s[i].atk > 0);
      break;
    } else {
      h -= s[i].atk;
      cnt++;
      if(h <= 0) break;
    }
  }

  cout<< cnt <<endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
ll dp[3];

int main()
{
	ios::sync_with_stdio(false);
	int n,a,b,c;
	ll temp[3];
	while(cin>>n){
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			if(!i){
				dp[0]=a,dp[1]=b,dp[2]=c;
			}
			else{
				temp[0]=max(dp[1],dp[2])+a;
				temp[1]=max(dp[0],dp[2])+b;
				temp[2]=max(dp[0],dp[1])+c;
				for(int j=0;j<3;j++){
					dp[j]=temp[j];
				}
			}
		}
		cout<<max(dp[0],max(dp[1],dp[2]))<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
 
int main(){
  unsigned short *A, *B;
 
  int C[VMAX+1];
  int num, i, j;
  scanf("%d", &num);
 
  A = malloc(sizeof(short)*num+1);
  B = malloc(sizeof(short)*num+1);
 
  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;
 
  for ( i = 0; i < num; i++ ){
    scanf("%hu", &A[i + 1]);
 
    C[A[i + 1]]++;
  }
 
  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];
 
  for ( j = 1; j <= num; j++ ){
 
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
 
  for ( i = 1; i <= num; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 8464
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stdexcept>
#include<climits>
#include<memory>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	int n;
	cin>>n;
	if(n>=30)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Map<Integer, String> map1 = new TreeMap<Integer, String>(Comparator.reverseOrder());
        Map<Integer, Integer> map2 = new HashMap<>();

        for (int i = 0; i < n; i++) {
            String s = scanner.next();
            int p = scanner.nextInt();
            map1.put(p, s);
            map2.put(p, i+1);
        }

        map1.entrySet().stream()
                .sorted(Map.Entry.comparingByValue())
                .forEach(s->System.out.println(map2.get((s.getKey()))));
    }

}


Measured memory_bytes: 27988
//        ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define debug(x) cout<<#x<<": "<<x<<endl
#define ull unsigned long long int
#define ll long long int
#define ld double
#define ui unsigned int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second 
 
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000000005
#define MOD 1000000007
                                  //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}

 
int main() {
    #ifdef sharma
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);      
    #endif
    fastio;
    int n;
    cin >> n;
    double x;
    double sum;
    rep(i, n)
    {
        cin >> x;
        sum += (1 / x);
    }
    double res = 1/sum;
    printf("%0.10f", res);
    



    return 0; 
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    long long D[N+1][W+1], w[N], v[N];
    for (int i = 0; i < N; i++)
    {
        cin >> w[i] >> v[i];
        for (int y = 0; y <= W; y++)
        {
            D[i][y] = -20000000000000000;
        }
    }
    D[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        for (int y = 0; y <= W; y++)
        {
            D[i+1][y] = D[i][y];
            if (y > 0)
            {
                D[i+1][y] = max(D[i][y],D[i+1][y-1]);
            }
        }
        for (int y = 0; y <= W; y++)
        {
            if (y + w[i] <= W)
            {
                D[i+1][y+w[i]] = max(D[i+1][y+w[i]],D[i][y]+v[i]);
            }
        }
        for (int y = 1; y <= W; y++)
        {
            D[i+1][y] = max(D[i+1][y],D[i+1][y-1]);
        }
    }
    cout << D[N][W];
    return 0;
}


Measured memory_bytes: 79232
def f(w1):
  x=[]
  a1=w1/500
  for i1 in range(a1+1):
    w2=w1-i1*500
    a2=w2/300
    for i2 in range(a2+1):
      w3=w2-i2*300
      if w3%200==0: x.append([w3/200,i2,i1])
  return x

def g(x):
  m=1e9
  A=[380,550,850]
  B=[.2,.15,.12]
  C=[5,4,3]
  for e in x:
    a=0
    for i in [0,1,2]:
      b=e[i]/C[i]*C[i]
      a+=A[i]*(e[i]-b*B[i])
    m=min(m,a)
  return m

while 1:
  w=input()
  if w==0: break
  print int(g(f(w)))

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

int x,y,l,r;
	int a,b,c;

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){

	cin>>a>>b>>c; 
	
}

int main(){
	init();
	
	int mx=0;
	mx=max(mx,a*10+b+c);
	mx=max(mx,b*10+a+c);
	mx=max(mx,c*10+a+b);
	
	cout<<mx<<endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;

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

bool srt(int a , int b){
    return a > b ;
}
int n,m;
string x[52];
int cost[52][52];
int S=0;
void bfs(){
    memset(cost,-1,sizeof cost);
    queue < pair < int , int > > q;
    cost[0][0]=1;
    q.push(make_pair(0,0));
    while(q.size()){
        pair < int , int > src=q.front();
        q.pop();
        for(int i=0;i<4;i++){
            int newX=dx[i]+src.first,newY=dy[i]+src.second;
            if(newX>=n||newX<0||newY>=m||newY<0)continue;
            if(x[newX][newY]=='#')continue;
            if(cost[newX][newY]!=-1)continue;
            cost[newX][newY]=cost[src.first][src.second]+1;
            q.push(make_pair(newX,newY));
        }
    }
    if(cost[n-1][m-1]==-1){
        cout<<-1<<endl;
        exit(0);
    }
    cout<<n*m-cost[n-1][m-1]-S<<endl;
    exit(0);
}

int main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        cin>>x[i];
        for(int j=0;j<m;j++){
            if(x[i][j]=='#')S++;
        }
    }
    bfs();
    return 0;
}


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

using namespace std;

void print(const vector<int>& A) {
    for (int i = 0; i < A.size(); i++) {
        if (i == 0) {
            cout << A[i];
        } else {
            cout << ' ' << A[i];
        }
    }
    cout << endl;
}

void insertionSort(vector<int>& A) {
    print(A);
    for (int i = 1; i < A.size(); i++) {
        auto v = A[i];
        auto j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        print(A);
    }
}

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;

    vector<int> a;
    a.reserve(n);

    for (int i = 0; i < n; i++) {
        int val;
        cin >> val;
        a.push_back(val);
    }

    insertionSort(a);

    return 0;
}

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

namespace Miscelleneous {
   class Program {
      public static int cin() { return int.Parse(Console.ReadLine()); }
      public static int[] cins() {
         string s = Console.ReadLine();
         if (string.IsNullOrEmpty(s)) return new int[]{ };
         string[] ss = s.Split(',');
         int[] Res = new int[ss.Length];
         for (int i = 0; i<ss.Length; i++) Res[i]=int.Parse(ss[i]);
         return Res;
      }
      public static double[] dins() {
         string s = Console.ReadLine();
         if (string.IsNullOrEmpty(s)) return new double[]{ };
         string[] ss = s.Split(',');
         double[] Res = new double[ss.Length];
         for (int i = 0; i<ss.Length; i++) Res[i]=double.Parse(ss[i]);
         return Res;
      }
      public static void print(object s) { Console.WriteLine(s.ToString()); }
      static void Main(string[] args) {
         double[] D;
         while (true) {
            D = dins();
            if (D.Length==0) break;
            //"Convex" is as same as "Exists vertex s.t. angle beyond pi"
            print(Prod(D) ? "YES" : "NO");
         }
      }

      static bool Prod(double[] JS) {
         double[] vs = new double[8];
         for (int i = 0; i<8; i++) 
            vs[i]=i<6?JS[i+2]-JS[i]:JS[i-6]-JS[i];
         double gaiz;
         int sym=0;
         bool Res = true;
         for (int i = 0; i<3; i++) {
            gaiz=vs[0+2*i]*vs[3+2*i]-vs[1+2*i]*vs[2+2*i];
            if (i==0) sym=Math.Sign(gaiz);
            else if (Math.Sign(gaiz)!=sym) { Res=false; break; }
         }
         gaiz=vs[6]*vs[1]-vs[7]*vs[0];
         Res&=Math.Sign(gaiz)==sym;
         return Res;
      }
   }
}

Measured memory_bytes: 9176
class Dice
  attr_reader :top, :front, :right, :left, :back, :bottom
  def initialize(pips)
    @top, @front, @right, @left, @back, @bottom = pips.split.map(&:to_i)
  end

  def rotate(dir)
    case dir
    when 'E'; tmp = @top; @top = @left; @left = @bottom; @bottom = @right; @right = tmp
    when 'W'; tmp = @top; @top = @right; @right = @bottom; @bottom = @left; @left = tmp
    when 'S'; tmp = @top; @top = @back; @back = @bottom; @bottom = @front; @front = tmp
    when 'N'; tmp = @top; @top = @front; @front = @bottom; @bottom = @back; @back = tmp
    when 'Z'; tmp = @front; @front = @right; @right = @back; @back = @left; @left = tmp
    end
  end

  def pips
    [
      {dir: 'top', pip: top},
      {dir: 'front', pip: front},
      {dir: 'right', pip: right},
      {dir: 'left', pip: left},
      {dir: 'back', pip: back},
      {dir: 'bottom', pip: bottom}
    ]
  end

  def same(d)
    _d = d.clone
    _d.pips.each do |item|
      if @top == item[:pip]
        case item[:dir]
        when 'top'
        when 'bottom'; _d.rotate('N'); _d.rotate('N')
        when 'front'; _d.rotate('N')
        when 'back'; _d.rotate('S')
        when 'left'; _d.rotate('E')
        when 'right'; _d.rotate('W')
        end

        4.times do
          if @bottom == _d.bottom &&
            @front == _d.front && @back == _d.back &&
            @left == _d.left && @right == _d.right
            return true
          end
          _d.rotate('Z')
        end
      end
    end
    false
  end
end

ds = []
n = gets.to_i
n.times {ds << Dice.new(gets)}
0.upto(n-2) do |i|
  j = i + 1
  while j <= n-1
    if ds[i].same(ds[j])
      puts 'No'
      exit
    end
    j += 1
  end
end

puts 'Yes'

Measured memory_bytes: 6708
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    f(K) = number of divisors of K
    sum(K*f(K)), K=1...N
    f(1) = 1, f(2) = 2, f(3) = 2, f(4) = 3
    1 <= N <= 10**7

    36 = 1, 2, 3, 4, 6, 9, 12, 18, 36
    f(36) = 9
    """
    N = read_int()
    counter = [1]*(N+1)
    for divisor in range(2, N+1):
        for step in range(divisor, N+1, divisor):
            counter[step] += 1
    return sum(k*counter[k] for k in range(1, N+1))


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 151764
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;


int main()
{
    int n;
    scanf("%d",&n);
    int ans=0;

    for(int i=1;i<n;i++)
    {
        ans=ans+(n/i);
        if(n%i==0)
        {
            ans=ans-1;
        }
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int n;
    cin >> n;
    float tmp;
    //if(n%2 == 0){
    //    tmp = 0.5;
    //}else{
        tmp = (float)((n+1)/2) / (float)n;
    //}
    cout << tmp << endl;
    
    return 0;
}

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

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    int64_t ans = 0;
    if (A[0] > x){
        ans += A[0] - x;
        A[0] = x;
    }
    for (int i = 1; i < n; i++){
        int d = A[i] + A[i - 1] - x;
        if (d > 0){
            A[i] -= d;
            ans += d;
        }
    }
    cout << ans << endl;
}

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

string s;
map<char, int> m;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
     
    cin >> s;
    for (auto it : s){
      m[it]++;
    }
    for (auto it : m){
      if (it.second & 1){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

typedef struct {
  int v;
  int c;
} jew_t;

int main(void) {
  int N;
  cin >> N;
  vector<int> vs;
  vector<int> cs;
  for(int i = 0; i < N; i++)
  {
    int t; cin >> t;
    vs.push_back(t);
  }
  for(int i = 0; i < N; i++)
  {
    int t; cin >> t;
    cs.push_back(t);
  }
  vector<int> ws;
  for(int i = 0; i < N; i++)
  {
    ws.push_back(vs[i] - cs[i]);
  }

  sort(ws.begin(), ws.end(), greater<int>());

  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (ws[i] < 0)
      break;
    sum += ws[i];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
using namespace std;

int n, e, t;
int x[101010];
long long f[101010];

long long calc(int a, int b)
{
	return max(f[b - 1] + t, f[b - 1] + 2 * x[a] - 2 * x[b]);
}

priority_queue<long long> q;

int main()
{
	scanf("%d%d%d", &n, &e, &t);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &x[i]);
	f[1] = t;
	int now = 0;
	for(int i = 2; i <= n; ++i)
	{
		f[i] = f[i - 1] + t;
		int l = 1;
		int r = i - 1, mid, key = i;
		while(l <= r)
		{
			mid = l + r;
			mid>>=1;
			if(t + 2 * x[mid] - 2 * x[i] >= 0)
			{
				r = mid - 1;
				key = mid;
			}
			else
				l = mid + 1;
		}
		f[i] = min(f[i], max(f[key - 1] + 2 * x[i] - 2 * x[key], f[key - 1] + t));
		if(key > 1)
		{
			while(now < key - 1)
			{
				++now;
				q.push(2 * x[now] - f[now - 1]);
			}
			f[i] = min(f[i], 2 * x[i] - q.top());
		}
	}
	
//	printf("%d\n", f[n] + e);
	cout<<f[n] + e<<endl;

	return 0;
}

Measured memory_bytes: 2552
#include <iostream>
using namespace std;
#define ll long long
ll mod=1e9+7;
int main()
{
	ll n,sum=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		sum=i*sum;
		sum=sum%mod;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;


int main(){

  char s, t;
  cin >> s >> t;
  if( s == t ) cout << "=" << endl;
  else cout << (s < t ? "<" : ">") << endl;

  return 0;
}





//


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) min_element(all(x))
using namespace std;
int main(void)

{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll bin, small;
    vector<ll> a(n + 1), b(n + 1);
    a[0] = 0;
    b[0] = n;
    rep(i, 0, n) a[i + 1] = a[i] + i + 1, b[i + 1] = b[i] + n - 1 - i;
    ll ans = 0;
    rep(i, k - 1, n + 1)
        ans += b[i] - a[i] + 1;
    cout << ans % 1000000007 << endl;
}


Measured memory_bytes: 6332
#include <stdio.h>
int main(void)
{
  int n,s[10000],g[10000],f[10000],hs,ms,ss,hg,mg,sg,i,j,t,c;
  while(1){
    c=1;
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i<n;i++){
      scanf("%d:%d:%d %d:%d:%d",&hs,&ms,&ss,&hg,&mg,&sg);
      s[i]=3600*hs+60*ms+ss;
      g[i]=3600*hg+60*mg+sg;
      f[i]=0;
    }
    /*for(i=0;i<n;i++)
      printf("%d %d\n",s[i],g[i]);
      putchar('\n');*/
    for(i=0;i<n-1;i++){
      for(j=n-1;j>i;j--){
	if(s[j-1]>s[j]){
	  t=s[j];
	  s[j]=s[j-1];
	  s[j-1]=t;
	  t=g[j];
	  g[j]=g[j-1];
	  g[j-1]=t;
	}
      }
    }
    /*for(i=0;i<n;i++)
      printf("%d %d\n",s[i],g[i]);*/
    for(i=1;i<n;i++){
      for(j=0;j<i;){
	if(f[j]==1){
	  j++;
	  continue;
	}
	if(s[i]>=g[j]){
	  f[j]=1;
	  break;
	}
	j++;
	if(j==i)
	  c++;
      }
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 716
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin >> k >> n;
  int a[n];
  int maxlength=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i] - a[i-1] > maxlength){
      maxlength = a[i] -a[i-1];
    }
  }
  if(a[0] + k-a[n-1] > maxlength){
    maxlength = a[0] + k-a[n-1];
  }
 cout << k-maxlength << endl;
  
}

Measured memory_bytes: 1024
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N, A, B) = rd.readLongArray()

    val ans = if (A > B) 0
                   else if (N == 1L && A != B) 0
                   else {
                        val lo = A*(N-1) + B
                        val hi = A + (N-1)*B
                        hi-lo+1
                   }
    println(ans)
}


//val rd = debug.Reader("agc", "015", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 36824
# include <iostream>
# include <cmath>
using namespace std;
typedef long long int ll;
int main()
{
	ll n;
	cin>>n;
	ll res=100;
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i)
			continue;
		ll b=n/i;
		res=min(res,1+ll(max(log10(i),log10(b))));
	}
	cout<<res<<"\n";
}

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

#define size_t int

using namespace std;
typedef unsigned long ul;
typedef unsigned long long ull;

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

  string str;
  std::cin >> str;

  auto pos = find(str.begin(),str.end(),'B');
  while(pos != str.end()){
    if(str.begin() != pos){
      str.erase(pos-1, pos+1);
    }else{
      str.erase(str.begin(),str.begin()+1);
    }
    pos = find(str.begin(),str.end(),'B');
  }

  std::cout << str << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
int main(){
 
  int a,b;
  cin>>a>>b;
  if(a==1 && b !=1)cout<<"Alice";
  else if(b==1 && a !=1)cout<<"Bob";
  else if(a>b)cout<<"Alice";
  else if(b>a) cout<<"Bob";
  else cout<<"Draw";
  return 0;
}

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

using namespace std;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> grid(H);
	for (int i = 0; i < H; ++i) { cin >> grid[i]; }

	int key = 0;
	vector<vector<int>> ans(H, vector<int>(W, 0));
	for (int i = 0; i < H; ++i) {
		int tmp = -1;
		for (int j = 0; j < W; ++j) {
			if (grid[i][j] == '.') {
				if (tmp < 0) { continue; }
				ans[i][j] = key;
			}
			if (grid[i][j] == '#') {
				++key;
				if (tmp < 0) {
					tmp = 1;
					for (int k = 0; k < j; ++k) {
						ans[i][k] = key;
					}
				}
				ans[i][j] = key;
			}
		}
	}

	for (int i = 1; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (ans[i][j] > 0) { continue; }
			ans[i][j] = ans[i - 1][j];
		}
	}
	for (int i = H - 2; i >= 0; --i) {
		for (int j = 0; j < W; ++j) {
			if (ans[i][j] > 0) { continue; }
			ans[i][j] = ans[i + 1][j];
		}
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << ans[i][j] << (j == W - 1 ? "\n" : " ");
		}
	}

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
struct UnionFind {
   vector<int> par;
   UnionFind(int N) : par(N) {
      for(int i = 0; i < N; i++) par[i] = i;
   }
   int root(int x) {
      if (par[x] == x) return x;
      return par[x] = root(par[x]);
   }
   void unite(int x, int y) {
      int rx = root(x);
      int ry = root(y);
      if (rx == ry) return;
      par[rx] = ry;
   }
   bool same(int x, int y) {
      int rx = root(x);
      int ry = root(y);
      return rx == ry;
   }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin>>N>>M;
    UnionFind Tree(N);
    vector<int>perm(N);
    for(int i=0;i<N;i++){
        cin>>perm[i];
    }
    int x,y;
    for(int i=0;i<M;i++){
        cin>>x>>y;
        Tree.unite(x-1,y-1);
    }
    int sub=0;
    for(int i=0;i<N;i++){
        if(Tree.same(i,perm[i]-1))sub++;
    }
    cout<<sub<<endl;
}

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

typedef long long ll;

int N,M,K,P;

struct edge{
  int to,c;
};

struct state{
  int id, s, t;
  ll c;
  bool operator<(const state &s) const {
    return c > s.c;
  }
};

vector<edge> G[10001];
int S[10001];
int T[10001];

ll H[10001][(1<<6)][(1<<6)];

ll dijk(){
  for(int i=0;i<=N;i++)
    for(int j=0;j<(1<<6);j++)
      for(int k=0;k<(1<<6);k++) H[i][j][k] = 10000000000000000LL;
  priority_queue<state> q;
  q.push( (state){P,0,0,0} );
  H[P][0][0] = 0LL;
  while( !q.empty() ){
    state p = q.top(); q.pop();
    if( H[p.id][p.s][p.t] < p.c ) continue;
    if( p.t == (1<<K)-1 ) return p.c;
    for(int i=0;i<(int)G[p.id].size();i++){
      edge e = G[p.id][i];
      ll nc = p.c + (ll)e.c;
      int ns = p.s;
      int nt = p.t;
      if( S[e.to] > -1 )
	ns |= (1<<S[e.to]);
      
      if( T[e.to] > -1 && ((1<<T[e.to]) & p.s) )
	nt |= (1<<T[e.to]);

      if( H[e.to][ns][nt] > nc ){
	H[e.to][ns][nt] = nc;
	q.push ( (state){e.to,ns,nt,nc} );
      }
    }
  }
  return -1;
}



int main(){
  memset(S,-1,sizeof(S));
  memset(T,-1,sizeof(T));
  cin >> N >> M >> K >> P;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin >> a >> b >> c;
    G[a].push_back( (edge){b,c} );
    G[b].push_back( (edge){a,c} );
  }

  for(int i=0;i<K;i++){
    int s,t;
    cin >> s >> t;
    S[s] = i;
    T[t] = i;
  }
  ll res = dijk();
  if( res == -1 ) cout << "Cannot deliver" << endl;
  else cout << res << endl;


}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if (l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}


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

	for (int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}

	for (int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}

	solve();

	return 0;
}



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
















int main(){

  

  int n;
  cin>>n;
  
  vector<int> x(n);
  vector<int> y(n);
  vector<int> h(n);
  
  for (int i=0;i<n;i++){
    int xi,yi,hi;
    cin>>xi>>yi>>hi;
    x.at(i)=xi;
    y.at(i)=yi;
    h.at(i)=hi;
  }
  
  int myindex;
  for (int i=0;i<n;i++){
    if (h.at(i)>0){
      myindex=i;
      break;
    }
  }

  
  int answerheight=0;
  
  int answerx;
  
  int answery;
  
  for (int cx=0;cx<=100;cx++){
    for (int cy=0;cy<=100;cy++){
      int height;
      height=h.at(myindex)+abs(cx-x.at(myindex))+abs(cy-y.at(myindex));
 
      bool flag=true;

      for (int i=0;i<n;i++){
        int tmp;
        tmp=max(height-abs(cx-x.at(i))-abs(cy-y.at(i)),0);
        if (tmp!=h.at(i)){
          flag=false;
          break;
        }
      }

      if (flag==true and height>=1){
        answerheight=height;
        answerx=cx;
        answery=cy;
        
      }
    }
  }
  
  cout<<answerx<<" "<<answery<<" "<<answerheight<<endl;
  
       
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

const int mxN = 2e3 + 5;
vector<int> adj[mxN];
int dis[mxN][mxN], cnt[mxN];

int main() {
	int n, u, v;
	cin >> n >> u >> v;
	adj[u].push_back(v);
	adj[v].push_back(u);
	for(int i = 1; i < n; ++i)
		adj[i].push_back(i + 1),
		adj[i + 1].push_back(i);
	memset(dis, -1, sizeof dis);
	for(int i = 1; i <= n; ++i) {
		queue<pair<int ,int>> bfs;
		bfs.push({i, 0});
		while(!bfs.empty()) {
			pair<int, int> cur = bfs.front();
			bfs.pop();
			if(~dis[i][cur.first])
				continue;
			dis[i][cur.first] = cur.second;
			for(int x : adj[cur.first])
				if(dis[i][x] == -1)
					bfs.push({x, cur.second + 1});
		}
	}
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			++cnt[dis[i][j]];
	for(int i = 1; i < n; ++i) 
		cout << cnt[i] << '\n';
}


Measured memory_bytes: 19452
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
2

output:
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
"""

import sys
import math


class Point(object):
    __slots__ = ('x', 'y')

    def __init__(self, x=-1, y=-1):
        """
        Initialize the point
        """
        self.x = float(x)
        self.y = float(y)


def koch_curve(d, p1, p2):
    if not d:
        return None

    s, t, u = (Point() for _ in range(3))

    s.x = (2 * p1.x + p2.x) / 3
    s.y = (2 * p1.y + p2.y) / 3

    t.x = (p1.x + 2 * p2.x) / 3
    t.y = (p1.y + 2 * p2.y) / 3

    u.x = (t.x - s.x) * COS_60 - (t.y - s.y) * SIN_60 + s.x
    u.y = (t.x - s.x) * SIN_60 + (t.y - s.y) * COS_60 + s.y

    koch_curve(d - 1, p1, s)
    print('{0:.8f} {1:.8f}'.format(s.x, s.y))

    koch_curve(d - 1, s, u)
    print('{0:.8f} {1:.8f}'.format(u.x, u.y))

    koch_curve(d - 1, u, t)
    print('{0:.8f} {1:.8f}'.format(t.x, t.y))

    koch_curve(d - 1, t, p2)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    depth = int(_input[0])
    SIN_60, COS_60 = math.sin(math.pi / 3), math.cos(math.pi / 3)

    p1_start, p2_end = Point(x=0, y=0), Point(x=100, y=0)
    print(format(p1_start.x, '.8f'), format(p1_start.y, '.8f'))
    koch_curve(depth, p1_start, p2_end)
    print(format(p2_end.x, '.8f'), format(p2_end.y, '.8f'))

Measured memory_bytes: 8044
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(string, S, N);
  map<char, int> m;
  each(x, S) {
    char c = x[0];
    if (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H') {
      m[c]++;
    }
  }
  vector<ll> v;
  each(x, m) {
    v.push_back(x.second);
  }
  ll ans = 0;
  int l = v.size();
  rep(i, 0, l - 2) {
    rep(j, i + 1, l - 1) {
      rep(k, j + 1, l) {
        ans += v[i] * v[j] * v[k];
      }
    }
  }
  print(ans);
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
double t,a,b,d,x,y,v1,v2,ans=1e9;
double xx(){
	return (a*v1+b*v2)/(v1+v2);
}
main(){
	cin>>t>>d>>a>>b>>x>>y;
	r(i,4747)r(j,4747)if(i||j){
		v1=x*i,v2=y*j;
		if(v1+v2>d)continue;
		ans=min(ans,abs(t-xx()));
	}
	printf("%.9f\n",ans);
}

Measured memory_bytes: 3272
a = list(map(int, input()))

for i in range(8):
    k = a[0]
    b = []
    for j in range(3):
        if ((i >> j) & 1):
            k += a[j+1]
            b.append("+")
        else:
            k -= a[j+1]
            b.append("-")
    if k == 7:
        break

ans = ""
for i in range(3):
    ans += str(a[i]) + b[i]
ans += str(a[3]) + "=7"

print(ans)

Measured memory_bytes: 9136
#include <stdio.h>

int main(){

int r,m,f;

while(1){

 scanf("%d%d%d",&r,&m,&f);
 if((r==-1)&&(m==-1)&&(f==-1))break;
 if((r==-1)||(m==-1))printf("F\n");
 else if((r+m)>=80)printf("A\n");
 else if((r+m)>=65)printf("B\n");
 else if((r+m)>=50)printf("C\n");
 else if((r+m)>=30){
  if(f>=50)printf("C\n");
  else printf("D\n");
 }else printf("F\n");

}

return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

int N, M;
const int N_MAX = 3000;
vector<pair<int, long long>> adj[N_MAX];
long long dist[N_MAX];
int pred[N_MAX];

bool bellmanford(int start){
    for(int i = 0; i < N; i++) dist[i] = LONG_LONG_MAX;
    dist[start] = 0;
    for(int k = 0; k < N - 1; k++){
        for(int i = 0; i < N; i++){
            for(auto p : adj[i]){
                int j = p.first;
                long long d = p.second;
                if(dist[i] < LONG_LONG_MAX && dist[i] + d < dist[j]){
                    dist[j] = dist[i] + d;
                    pred[j] = i;
                }
            }
        }
    }
    ll d = dist[N - 1];
    for(int k = 0; k < N - 1; k++){
        for(int i = 0; i < N; i++){
            for(auto p : adj[i]){
                int j = p.first;
                long long d = p.second;
                if(dist[i] < LONG_LONG_MAX && dist[i] + d < dist[j]){
                    dist[j] = LONG_LONG_MIN / 2;
                }
            }
        }
    }
    return d == dist[N - 1];
}

signed main(){
    ll P, a, b, c;
    cin >> N >> M >> P;
    REP(i, M){
        cin >> a >> b >> c;
        a--; b--;
        adj[a].push_back(pll(b, P - c));
    }
    if(bellmanford(0)){
        PRINT(abs(min(0LL, dist[N - 1])));
    }else{
        PRINT("-1");
    }
    return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int K = sc.nextInt();
        final int X = sc.nextInt();
        final int Y = sc.nextInt();
        if(N < K) {
            System.out.println(X * N);
        } else {
            System.out.println(X * K + Y * (N - K));
        }
    }
}



Measured memory_bytes: 21972
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int A =scan.nextInt();
        int B = scan.nextInt();

        if(Math.abs(A-B)%2 == 1){
            System.out.println("Borys");
        }else{
            System.out.println("Alice");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s; cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N + 1];
    int[] b = new int[N];
    for (int i = 0; i < N + 1; i++) a[i] = scanner.nextInt();
    for (int i = 0; i < N; i++) b[i] = scanner.nextInt();

    long count = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 2; j++) {
        int beat = Math.min(a[i + j], b[i]);
        count += beat;
        a[i + j] -= beat;
        b[i] -= beat;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 83588
//def
#include <iostream>

#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <map>

using namespace std;

#define rep(i,q) for(int i = 0; (q) > i; i++)
#define anyfill(n,s) setw(n) << setfill(s)
#define pb push_back
#define MOD 1000000007

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


Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let p = Array.make n 0 in
    for i = 0 to n - 1 do
        Scanf.scanf " %d" (fun a -> p.(a - 1) <- i)
    done;

    let module S = Set.Make (struct type t = int let compare = compare end) in

    let rec loop i set acc =
        if i = n then acc else
            let l, _, r = S.split p.(i) set in
            let mx = S.max_elt l in
            let mi = S.min_elt r in
            loop (i + 1) (S.add p.(i) set) (acc + (i + 1) * (p.(i) - mx) * (mi - p.(i)))
    in
    loop 0 (S.add (-1) (S.singleton n)) 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 22184
#include <bits/stdc++.h>
using namespace std;
 
 
int main(void){
  string S;
  cin >> S;
  for (int i = 1; i < S.length(); i++){
    if(S[i] == S[i - 1]){
      cout << "Bad";
      return 0;
    }
  }
  cout << "Good";
  
  
  return 0;
}

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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define pi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
#define vl vector<ll>
#define vii vector<pair<int,int> >
#define vll vector<pair<long long,long long> >
#define pb push_back
#define mp make_pair3

const ll mod=1e9+7;
#define MAX 100000

int modulo = 420047;

ll binexpo(ll a,ll b,ll c){

    if(b==0) return 1;
    else if(b%2==0) return binexpo(((a%c)*(a%c))%c,b/2,c)%c;
    else return ((a%c)*(binexpo(((a%c)*(a%c))%c,b/2,c)%c))%c;
}

int main(){

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

    int arr[n];
    FOR(i,0,n) cin>>arr[i];

    ll dp[n];
    memset(dp,(ll)1e9,sizeof(dp));

    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);
    FOR(i,2,n){
        ll ans = (ll)1e9;
        for(int j = i-1,l = 0;j>=0 && l<k;j--,l++){
            ll val = dp[j] + abs(arr[i] - arr[j]);
            ans = min(ans,val);
        }
        dp[i] = ans;
    }

    cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 1408
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,sq[200];

int f(int cur,int n,int pre){
	int res = n == 0;
	if(cur==4)return res;
	rep2(i,pre,INF){
		if(sq[i] > n)break;
		res += f(cur+1,n-sq[i],i);
	}
	return res;
}

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

	rep(i,200) sq[i] = i*i;
	while(cin>>n && n){
		cout<<f(0,n,1)<<endl;
	}
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int n; cin >> n;
    int sum = 0, maxelt = 0;
    for(int i = 0; i < n; ++i) {
        int l; cin >> l;
        maxelt = max(maxelt, l);
        sum += l;
    }

    if(maxelt < sum-maxelt) cout << "Yes";
    else cout << "No";

    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
int a[2010];
bitset<4000100> dp;
int main() {
	int n;
	int sum = 0;
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	dp.set(0);
	for(int i = 1; i <= n; i++){
		dp |= dp<<a[i];
	}
	if(sum%2) sum = sum/2+1;
	else sum /= 2; 
	for(int i = sum; i<=4000000; i++){
		if(dp[i]) {
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        h:usize,
        w:usize,
        a:[chars; h]
    }
    for _ in 0..w+2 { print!("#"); }
    println!();
    for i in 0..h{
        print!("#");
        for j in 0..w { print!("{}",a[i][j]) }
        println!("#");
    }
    for _ in 0..w+2 { print!("#"); }
    println!()
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <math.h>
#define MAX 77777777
#define N 101


struct node{
    int key;
    struct node *next;
    struct node *prev;
} ;
typedef struct node *NodePointer;

void Ins(int);
void Delkey(int);
NodePointer S(int);
void Del(NodePointer);

NodePointer nil;

int main()
{
    int i, n, data;
    char c[12];
    NodePointer x;
    
    
    nil = (NodePointer)malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
    nil->key = -1;
    
    scanf("%d",&n);
    
    for(i = 0; i < n; i++) {
        scanf("%s",c);
        
        if(strcmp(c,"insert") == 0) {
            scanf("%d",&data);
            Ins(data);
        }
        else if(strcmp(c,"delete") == 0) {
            scanf("%d",&data);
            Delkey(data);
        }
        else if(strcmp(c,"deleteFirst") == 0){
            Del(nil->next);
        }
        else {
            Del(nil->prev);
        }
    }
    
    x = nil->next;
    printf("%d",x->key);
    x = x->next;
    while(x != nil) {
        printf(" %d",x->key);
        x = x->next;
    }
    printf("\n");
    
    
    x = nil->next->next;
    while(x != nil) {
        free(x->prev);
        x = x->next;
    }
    free(nil);
    
    return 0;
}

void Ins(int data)
{
    NodePointer x;
    
    x = (NodePointer)malloc(sizeof(struct node));
    
    x->key = data;
    
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

void Delkey(int data)
{
    NodePointer x;
    
    if((x = S(data)) == nil) return;
    
    Del(x);
}

NodePointer S(int data)
{
    NodePointer x;
    x = nil->next;
    while(x != nil && x->key != data) {
        x = x->next;
    }
    
    return x;
}

void Del(NodePointer x)
{
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
}




Measured memory_bytes: 33024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			long[] L = new long[87];
			L[0] = 2;
			L[1] = 1;
			for(int i = 2; i < L.length; i++) {
				L[i] = L[i - 1] + L[i - 2];
			}
			out.println(L[N]);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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


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

using namespace std;

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b, c; long long k;
    cin >> a >> b >> c >> k;
    if (k & 1) cout << b - a << endl;
    else cout << a - b << endl;
}


Measured memory_bytes: 256
def move
  $arr.sort.reverse.each do |list|
    tmp = list[2] if $pos == list[1]
    tmp = list[1] if $pos == list[2]
    $pos = tmp unless tmp.nil?
  end
end

loop do
  tate, yoko, $pos = gets.split.map(&:to_i)
  break if tate == 0 && yoko == 0 && $pos == 0
  $arr = []
  yoko.times do
    $arr << gets.split.map(&:to_i)
  end
  move
  puts $pos
end

Measured memory_bytes: 6112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int time = in.nextInt();
		int s = time % 60;
		time -= s;
		int m = (time % (60 * 60))/60;
		time -= m;
		int h = (time % (60 * 60 * 60))/(60 * 60);
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i+=2)cout<<s[i];
    cout<<endl;
}

Measured memory_bytes: 512
n = gets.to_i
x = gets.split("\s").map(&:to_i)
min = nil

(x.max+1).times do |n_i|
  sum = x.inject(0) { |res, x_i| res + (x_i - n_i)**2 }
  min ||= sum
  min = sum if sum < min
end

p min

Measured memory_bytes: 1916