akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static final long MOD=1000000007;//998244353;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		int N=sc.nextInt();
		long[] f=new long[N+1];
		for (int i = 1; i <= N; i++) {
			for (int j = i; j <= N; j+=i) {
				f[j]++;
			}
		}
		long sum=0;
		for (long i = 1; i <= N; i++) {
			sum+=i*f[(int) i];
		}
		System.out.println(sum);
 	}
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 112436
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(int arg_state,int arg_sum_cost,int arg_loc){
		state = arg_state;
		sum_cost = arg_sum_cost;
		loc = arg_loc;
	}
	bool operator<(const struct Info &arg) const{
		return sum_cost > arg.sum_cost;
	}
	int state,sum_cost,loc;
};


int N;
int POW[17],dp[65536][16],start_state,goal_state,ans_num[16];
char buf_start[17],buf_goal[17];

void func(){

	scanf("%s",buf_start);

	start_state = 0;

	for(int i = 0; buf_start[i] != '\0'; i++){
		if(buf_start[i] == 'B'){
			start_state += POW[i];
		}
	}

	scanf("%s",buf_goal);

	goal_state = 0;

	for(int i = 0; buf_goal[i] != '\0'; i++){
		if(buf_goal[i] == 'B'){
			goal_state += POW[i];
			ans_num[i] = 1;
		}else{
			ans_num[i] = 0;
		}
	}

	if(start_state == goal_state){
		printf("0\n");
		return;
	}

	for(int state = 0; state < POW[N]; state++){
		for(int loc = 0; loc < N; loc++)dp[state][loc] = BIG_NUM;
	}

	priority_queue<Info> Q;
	for(int loc = 0; loc < N; loc++){
		dp[start_state][loc] = 0;
		Q.push(Info(start_state,0,loc));
	}

	int ans = BIG_NUM;
	int next_state,num_1,num_2,tmp_cost;

	while(!Q.empty()){

		if(Q.top().state == goal_state){
			ans = min(ans,Q.top().sum_cost);
			Q.pop();
		}else if(Q.top().sum_cost > dp[Q.top().state][Q.top().loc]){
			Q.pop();
		}else{

			for(int mark_1 = 0; mark_1 < N; mark_1++){
				for(int mark_2 = 0; mark_2 < N; mark_2++){
					if(mark_1 == mark_2)continue;

					if(Q.top().state & (1 << mark_1)){
						num_1 = 1;
					}else{
						num_1 = 0;
					}

					if(Q.top().state & (1 << mark_2)){
						num_2 = 1;
					}else{
						num_2 = 0;
					}

					if(num_1 == num_2)continue;

					if(num_1 == ans_num[mark_1] && num_2 == ans_num[mark_2])continue;

					if(num_1 == 1){
						next_state = Q.top().state-POW[mark_1]+POW[mark_2];
					}else{ //num_2 == 1
						next_state = Q.top().state+POW[mark_1]-POW[mark_2];
					}

					tmp_cost = abs(mark_1-Q.top().loc)+abs(mark_2-mark_1);

					if(dp[next_state][mark_2] > Q.top().sum_cost+tmp_cost){
						dp[next_state][mark_2] = Q.top().sum_cost+tmp_cost;
						Q.push(Info(next_state,Q.top().sum_cost+tmp_cost,mark_2));
					}
				}
			}
			Q.pop();
		}
	}

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

int main(){

	for(int i = 0; i < 17; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 16396
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  string s; cin >> s;

  int n = s.size();
  vector<int> c(26, 0);
  for(int i = 0; i < n; i++){
    c[s[i]-'a']++;
  }

  int sum = n * (n-1) / 2;
  for(int i = 0; i < 26; i++){
    sum -= max(0LL, c[i] * (c[i]-1) / 2);
  }
  cout << sum+1 << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[200010];
long long ax[200010],ah[200010];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++){
		ax[i+1]=ax[i]^a[i];
		ah[i+1]=ah[i]+a[i];
	} 
	long long res=0;
	for(int i=0;i<n;i++){
		int l=i,r=n-1;
		while(l!=r){
			int m=l+(r-l+1)/2;
			if((ah[m+1]-ah[i])==(ax[m+1]^ax[i]))
				l=m;
			else
				r=m-1;
		}
		res+=l-i+1;
	}
	cout<<res<<endl;
	return 0;
}
//二分

Measured memory_bytes: 4992
N,X=map(int,input().split())
L=[int(i) for i in input().split()]
l=list(L)
D=[]
d=0
D.append(d)
for i in range(2,N+2):
  d+=l[i-2]
  D.append(d)
bound=[i for i in D if i<=X]
print(len(bound))

Measured memory_bytes: 3064
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    ans = sum(A)
    counter = Counter(A)

    for _ in range(Q):
        b, c = map(int, input().split())
        ans -= counter[b] * b
        ans += counter[b] * c
        counter[c] += counter[b]
        counter[b] = 0
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 23988
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sn = new Scanner(System.in);
		int n;
		while((n= sn.nextInt()) != 0){
			System.out.println(getNumberType(n));
		}
	}
	
	static String getNumberType(int n){
		if(n == 1) return "deficient number";
		int sum = 1;
		
		int range = n;
		for(int i = 2; i < range; i++){
			if(n%i == 0){
				range = n/i;
				sum += i;
				if(i  != range) sum += range; 
			}
		};
		return (sum == n)? "perfect number": (sum < n)? "deficient number": "abundant number";
	}
}

Measured memory_bytes: 19648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N; cin >> N;
	priority_queue<ll,vector<ll>,greater<ll>> a1;
	vector<ll> a2(N);
	priority_queue<ll> a3;
	ll sum1 = 0;
	ll sum2 = 0;
	rep(i,N){
		int a; cin >> a;
		sum1 += a;
		a1.push(a);
	}
	rep(i,N) cin >> a2[i];
	rep(i,N){
		int a; cin >> a;
		sum2 += a;
		a3.push(a);
	}
	vector<ll> Sum1(N+1);
	vector<ll> Sum2(N+1);
	Sum1[0] = sum1;
	rep(i,N){
		if(a1.top() < a2[i]){
			Sum1[i+1] += Sum1[i] + a2[i];
			Sum1[i+1] -= a1.top();
			a1.pop();
			a1.push(a2[i]);
		}
		else Sum1[i+1] = Sum1[i];
	}

	Sum2[N] = sum2;
	for(int i = N; i >= 1; i--){
		if(a3.top() > a2[i-1]){
			Sum2[i-1] += Sum2[i] + a2[i-1];
			Sum2[i-1] -= a3.top();
			a3.pop();
			a3.push(a2[i-1]);
		}
		else Sum2[i-1] = Sum2[i];
	}

	ll ans = -LINF;
	rep(i,N+1){
		ll now = Sum1[i] - Sum2[i];
		ans = max(ans,now);
	}
	cout << ans << endl;


	
}
   


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll);  -> a/=b;  result: a = 3
struct ModInt{
	ll val;
	ModInt():val(0ll){}
	ModInt(ll v):val(((v%MOD)+MOD)%MOD){}
	ModInt exp(ll y)const{
		if(!y)return ModInt(1ll);
		ModInt a = exp(y/2ll);
		a *= a;
		if(y&1)a*=(*this);
		return a;
	}
	bool operator==(const ModInt& x)const{return val==x.val;}
	inline bool operator!=(const ModInt& x)const{return !(*this==x);}
	bool operator<(const ModInt& x)const{return val<x.val;}
	bool operator>(const ModInt& x)const{return val>x.val;}
	inline bool operator>=(const ModInt& x)const{return !(*this<x);}
	inline bool operator<=(const ModInt& x)const{return !(*this>x);}
	ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;}
	ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;}
};
istream& operator>>(istream&i,ModInt&x){i>>x.val;return i;}
ostream& operator<<(ostream&o,const ModInt&x){o<<x.val;return o;}
const int SIZE = 100100;
ModInt inv[SIZE+10],fac[SIZE+10],facinv[SIZE+10];
// notice: 0C0 = 1 
ModInt nCr(int n,int r){
	assert(!(n<r));
	assert(!(n<0||r<0));
	return fac[n]*facinv[r]*facinv[n-r];
}
ModInt pow(ModInt a,ll x){
	ModInt res = ModInt(1ll);
	while(x){
		if(x&1)res *= a;
		x >>= 1;
		a = a*a;
	}
	return res;
}
void init(){
	fac[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)fac[i]=fac[i-1]*ModInt(i);
	inv[1]=ModInt(1ll);
	for(int i=2;i<=SIZE;i++)inv[i]=ModInt(0ll)-ModInt(MOD/i)*inv[MOD%i];
	facinv[0]=ModInt(1ll);
	for(int i=1;i<=SIZE;i++)facinv[i]=facinv[i-1]*inv[i];
	return;
}
int N;
int A,B,C,D;
ModInt dp[1005][1005];
int main(){
	init();
	cin >> N >> A >> B >> C >> D;
	for(int i=0;i<=B;i++)dp[0][i]=ModInt(1ll);
	for(int i=1;i<=N;i++){
		for(int j=A;j<=B;j++){
			dp[i][j]=dp[i][j-1];
			for(int k=C;k<=min(i/j,D);k++){
				dp[i][j] += (dp[i-j*k][j-1]*fac[i]*facinv[i-j*k]*facinv[k]*pow(facinv[j],k));
			}
		}
	}
	cout << dp[N][B] << endl;
    return 0;
}


Measured memory_bytes: 10496
s = input()
ans = 'AC'
if s[0] != 'A':
    ans = 'WA'
if not('C' in s[2:-1]):
    ans = 'WA'
s = s.replace('A','')
s = s.replace('C','',1)
for i in s:
    if ord(i) < ord('a') or ord(i) > ord('z'):
        ans = 'WA'
print(ans)


Measured memory_bytes: 9100
n = gets.to_i
as = gets.split.map(&:to_i)

as.sort!.reverse!

sum = as.sum
a_x = as.shift
sum -= a_x

ans = 1

as.each do |a|
  if sum * 2 >= a_x
    ans += 1
  else
    break
  end

  a_x = a
  sum -= a_x
end

puts ans


Measured memory_bytes: 21496
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((a + b) >= c)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 105
using namespace std;
int n,in[M],x;
int main()
{
    while (~scanf("%d %d", &n,&x)) {
        REP(i,1,n) scanf("%d", &in[i]);

        int cur=0;
        int ans=1;
        REP(i,1,n) {
            cur  += in[i];
            if (cur<=x) ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
def digit_sum n
    sum = 0
    n.to_s.chars do |c|
        sum += c.to_i
    end
    return sum
end

n = gets.to_i

min = 10000
(1..(n-1)).each do |a|
    b = n - a
    sum = digit_sum a
    sum += digit_sum b
    min = [min, sum].min
end

puts min

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void) {
    char day[5];
    scanf("%s", day);
    int num = 0;
    if (strcmp(day, "SUN") == 0) {
        num = 7;
    } else if (strcmp(day, "MON") == 0) {
        num = 6;
    } else if (strcmp(day, "TUE") == 0) {
        num = 5;
    } else if (strcmp(day, "WED") == 0) {
        num = 4;
    } else if (strcmp(day, "THU") == 0) {
        num = 3;
    } else if (strcmp(day, "FRI") == 0) {
        num = 2;
    } else if (strcmp(day, "SAT") == 0) {
        num = 1;
    }

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

    return 0;
}


Measured memory_bytes: 128
import std.stdio, std.string, std.array, std.algorithm, std.conv, std.typecons, std.numeric, std.math;

struct SegTree(alias _fun, alias def, T)
if (is(typeof(def) : T))
{
    import std.functional : binaryFun;
    alias fun = binaryFun!_fun;

    ///
    this(size_t n, T[] ts) {
        this.n = 1;
        while (this.n < n) this.n *= 2;
        this.tree.length = this.n * 2 - 1;
        foreach (ref e; this.tree) e = def;
        foreach (i, e; ts) this.put(i, e);
    }

    ///
    void put(size_t i, T e) {
        i += this.n - 1;
        this.tree[i] = e;
        while (i > 0) {
            i = (i-1) / 2;
            this.tree[i] = fun(this.tree[i*2+1], this.tree[i*2+2]);
        }
    }

    ///
    T query(size_t a, size_t b) {
        T impl(size_t i, size_t l, size_t r) {
            if (r <= a || b <= l) return def;
            if (a <= l && r <= b) return this.tree[i];
            return fun(
                impl(i*2+1, l, (l+r)/2),
                impl(i*2+2, (l+r)/2, r)
            );
        }
        return impl(0, 0, this.n);
    }

private:
    size_t n;
    T[] tree;
}

///
SegTree!(f, def, T) seg_tree(alias f, alias def, T)(size_t n, T[] arr = [])
{
    return SegTree!(f, def, T)(n, arr);
}

///
SegTree!(f, def, T) seg_tree(alias f, alias def, T)(T[] arr)
{
    return SegTree!(f, def, T)(arr.length, arr);
}

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];
    auto segt = seg_tree!("a + b", 0, int)(N+1);
    foreach (_; 0..Q) {
        auto cxy = readln.split.to!(int[]);
        auto c = cxy[0];
        auto x = cxy[1];
        auto y = cxy[2];
        if (c == 0) {
            auto o = segt.query(x, x+1);
            segt.put(x, o+y);
        } else {
            writeln(segt.query(x, y+1));
        }
    }
}


Measured memory_bytes: 4232
ary=$stdin.readlines
od=Array.new
ev=Array.new
n = ary[0].to_i
array=ary[1].split.map!(&:to_i)
p=0
while p<n
  od.push(array[p]) if p%2==0
  ev.push(array[p]) if p%2==1
  p+=1
end

  sd_n_ns_od = od.group_by{|i| i}.sort_by{|k,v| v.size}
  sd_n_ns_ev = ev.group_by{|i| i}.sort_by{|k,v| v.size}

if sd_n_ns_od.size == 1 && sd_n_ns_ev.size == 1
  if sd_n_ns_od.last.first == sd_n_ns_ev.last.first
    answer = n/2
  else
    answer= 0
  end
else
most_n_od = sd_n_ns_od.last.first
most_n_ev = sd_n_ns_ev.reject{|k,v| k == most_n_od}.last.first
answer1=0
answer1+=od.reject{|i| i==most_n_od}.size
answer1+=ev.reject{|i| i==most_n_ev}.size

most_n_ev = sd_n_ns_ev.last.first
most_n_od = sd_n_ns_od.reject{|k,v| k== most_n_ev}.last.first
answer2=0
answer2+=ev.reject{|i| i==most_n_ev}.size
answer2+=od.reject{|i| i==most_n_od}.size

 answer = (answer1 <= answer2)?  (answer1):(answer2)

 end
puts answer

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

int main(){
    int n;
    cin >> n;
    n = n%10;
    if(n == 3){
        cout << "bon" << endl;
    }else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}

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

using namespace std;

int main(void)
{

    int n;
    cin >>n;

    string s;
    cin >>s;

    if(n % 2){
        printf("No\n");
    }else{
        int len = n / 2;
        if(s.substr(0, len) == s.substr(len, len)){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
        int L = N.length();
        boolean ans = true;
        for(int i=0;i<1+L/2;i++){
        	if(N.charAt(i)!=N.charAt(L-1-i)) ans = false;
        }
        if(ans) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

int main()
{
    char c; cin >> c;
    cout << char(c+1) << endl;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int h[maxn];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n;
    cin>>n>>h[1];
    int low=h[1]-1,hih=h[1];
    bool f=true;
    for(int i=2;i<=n;i++)
    {
        cin>>h[i];
        if(h[i]>low)
        {
            low=h[i]-1;
        }
        else if(h[i]==low)
        {
            low=h[i];
        }
        else
        {
            f=false;
        }

    }
    if(f)
        cout<<"Yes";
    else
        cout << "No";
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e5+5;
const int mo=1e9+7;
int n,x,ans,a[26];
char s[N];
int main()
{
	scanf("%d\n",&n);
	scanf("%s",s+1);
	for (int i=1;i<=n;i++)
	{
		x=s[i]-'a';
		a[x]++;
	}
	ans=1;
	for (int i=0;i<=26;i++) ans=(long long)ans*(a[i]+1)%mo;
	ans=(ans-1+mo)%mo;
	printf("%d",ans);
	return 0;
}



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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int answer = 0;
    int count = 0;
    for(int i = 0; i < S.size(); i++)
    {
        if(S.at(i) == 'A' 
        || S.at(i) == 'T'
        || S.at(i) == 'G'
        || S.at(i) == 'C'){
            count++;
        }else{
            answer = max(answer, count);
            count = 0;
        }
    }
    answer = max(answer, count);
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
ll fastpower(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y&1)
        res*=x;

        y>>=1;
        x=x*x;
    }
    return res;
}

void swap(ll &a,ll &b)
{
    a ^= b; 
    b ^= a; 
    a ^= b;
}
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    VII arr(n);
    for(auto &x:arr)cin>>x;

    if(n<=k)cout<<0;
    else{
    sort(all(arr),greater<int>());
    ll cnt=0;
    for(int i=k;i<n;++i)
    cnt+=arr[i];

    cout<<cnt;
    }
    return 0;
}

Measured memory_bytes: 1024
/**
 *      purpose : ABC 100 D
 *      author  : kyomukyomupurin
 *      created : 2019-01-12 20:04:45
**/

#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int64 n, m; cin >> n >> m;
    int64 x[n], y[n], z[n];
    rep(i, n) cin >> x[i] >> y[i] >> z[i];
    int64 ans = -1e18;

    for (int bit = 0; bit < (1<<3); ++bit){
        vector<int> dir;
        for (int i = 0; i < 3; ++i){
            if (bit & (1<<i)){
                dir.PB(1);
            }
            else dir.PB(-1);
        }
        vector<int64> v;
        for (int i = 0; i < n; ++i){
            v.PB(x[i] * dir[0] + y[i] * dir[1] + z[i] * dir[2]);
        }
        sort(all(v), greater<int64>());
        int64 sum = accumulate(v.begin(), v.begin() + m, int64());
        ans = max(ans, sum);
    }
    print(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100010;

struct Edge{ int to, next;} edge[N * 2];
int head[N], num;
void add_edge(int a, int b) { edge[++ num] = (Edge){b, head[a]}, head[a] = num;}

int s[N], ans;

void dfs(int x, int f)
{
	int tmp = 0;
	RepG(i, x) if (v != f){
		dfs(v, x);
		int ts = (s[v] & s[x]), t0 = 20;
		if (ts) {
			while (!(ts & (1 << t0))) t0 --; 
			tmp = max(tmp, t0 + 1);
		}
		s[x] |= s[v];
	}
	if (tmp) Rep0(i, tmp - 1) if (s[x] & (1 << i)) s[x] ^= (1 << i);
	for (int i = tmp; i <= 20; i ++){
		if (!(s[x] & (1 << i))){
			s[x] |= (1 << i), ans = max(ans, i);
			break;
		}
		else s[x] ^= (1 << i);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	Rep(i, n - 1) {
		int a, b;
		scanf("%d%d", &a, &b);
		add_edge(a, b); add_edge(b, a);
	}
	
	dfs(1, 0);
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 5888
import java.util.Scanner;
public class Main {
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int a;
		while(sc.hasNextInt()) {
			a=sc.nextInt();
		for(int i=9;i>0;i--) {
			if(a%i==0) { 
				a=a/i;
			if(a>=1&&a<10) {
				System.out.println("Yes");
				break;
			}else {
			System.out.println("No");
			break;
			}
			}
		}
		}
		}
	}


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

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

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

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

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

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

#define F first
#define S second

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

int main ()
{
    fastio
    lli num ;
    cin >> num ;
    (num % 10 == 9 || num / 10 % 10 == 9 ? Yes : No) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    int N = scanner.nextInt();
    char[] S = scanner.next().toCharArray();

    int max = 0;
    for (int i = 0; i < N; i++) {
      Set<Character> left = new HashSet<>();
      Set<Character> right = new HashSet<>();
      for (int j = 0; j < i; j++) left.add(S[j]);
      for (int j = i; j < N; j++) right.add(S[j]);
      int cnt = 0;
      for (char ch : left) if (right.contains(ch)) cnt++;
      max = Math.max(max, cnt);
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 23252
import heapq as hp

N, M = map( int, input().split() )
L = [[]] * M

for i in range( N ):
  a, b = map( int, input().split() )
  if a - 1 < M:
    if L[ a - 1 ] == []:
      L[ a - 1 ] = [ b ]
    else:
      L[ a - 1 ].append( b )
      
ret = 0
C = []
hp.heapify( C )
for i in range( M ):
  for i in L[i]:
    hp.heappush( C, -i)
  if C != []:
    ret -= hp.heappop( C )

print( ret )


Measured memory_bytes: 16324
#takasa=2^(n+2)-3
#pathi=2^(n+1)-1
$P=[]
i=1
53.times{
	$P<<i
	i*=2
}

def maisu(n,x)
	if x==1
		return 0
	elsif x<=$P[n+1]-3
		return maisu(n-1,x-1)
	elsif x==$P[n+1]-2
		return $P[n]-1
	elsif x==$P[n+1]-1
		return $P[n]
	elsif x<=$P[n+2]-5
		return $P[n]+maisu(n-1,x-$P[n+1]+1)
	else
		return $P[n+1]-1
	end
end

N,X=gets.split(" ").map(&:to_i)
puts maisu(N,X)

Measured memory_bytes: 3836
import string

def solve():
	H, W = map(int, input().split())
	S = [list(input().split()) for i in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j]=='snuke':
				print(string.ascii_uppercase[j:j+1] + str(i+1))
				return

solve()

Measured memory_bytes: 3772
n,t=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
dp=[[0]*(t+1) for i in range(n+1)]
for i in range(1,n+1):
  for j in range(t+1):
    if j!=t:
      if j-l[i-1][0]>=0:
        dp[i][j]=max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+l[i-1][1])
    dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[n]))

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

int main() {
  int n, d;
  int ans = 0;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    if(i * (2 * d + 1) >= n) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
array = Array.new

while true
  nums = ARGF.gets.split(" ")
  break if nums[1] == "?"
  arr = nums[0].to_i + nums[2].to_i if nums[1] == "+"
  arr = nums[0].to_i - nums[2].to_i if nums[1] == "-"
  arr = nums[0].to_i * nums[2].to_i if nums[1] == "*"
  arr = nums[0].to_i / nums[2].to_i if nums[1] == "/"
  array.push arr
end

array.each { |ar| puts ar }

Measured memory_bytes: 6104
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// Data :
type Data struct {
	n, x, y int
	cost    int
}

// Datas :
type Datas []Data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].n < p[j].n
}

func main() {
	sc.Split(bufio.ScanWords)
	H, W, D := getInt(), getInt(), getInt()
	N := H * W
	n := make(Datas, N)
	idx := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			a := getInt()
			n[idx] = Data{a, j, i, 0}
			idx++
		}
	}
	sort.Sort(n)
	// out(n, D)

	for i := D; i < N; i++ {
		p := i - D
		d := asub(n[i].x, n[p].x) + asub(n[i].y, n[p].y)
		// out(n[p].x, n[p].y, "-", n[i].x, n[i].y, d)
		n[i].cost = n[p].cost + d
	}
	// out(n, D)

	Q := getInt()
	for i := 0; i < Q; i++ {
		l, r := getInt()-1, getInt()-1
		out(n[r].cost - n[l].cost)
	}

}


Measured memory_bytes: 6016
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

LL dp[100002][2];  // keta, smaller

LL add(LL a, LL b) { return (a+b) % kMod; }
LL mul(LL a, LL b) { return (a*b) % kMod; }

int main() {
  string L; cin >> L;
  dp[0][0] = 1, dp[0][1] = 0;  // tight, smaller
  for (int i = 0; i < L.size(); ++i) {
    if (L[i] == '1') {
      dp[i + 1][0] = mul(dp[i][0], 2);
      dp[i + 1][1] = add(dp[i][0], mul(dp[i][1], 3));
    } else {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = mul(dp[i][1], 3);
    }
  }
  cout << add(dp[L.size()][0], dp[L.size()][1]) << endl;
}


Measured memory_bytes: 5292
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int R;
	cin >> R;

	co(R * R);

	Would you please return 0;
}

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

n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for _ in range(m)]

for i in range(m):
    print(sum(t) - t[px[i][0]-1] + px[i][1])


Measured memory_bytes: 3060
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

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

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  int a;
  string s;cin>>a>>s;
  if(a < 3200)cout << "red" << endl;
  else cout << s << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0046
?¨???????
"""
import sys

def main(args):
    mountains = []
    for line in sys.stdin:  # ??????????????\???
        mountains.append(float(line.strip()))

    max_height = max(mountains)
    min_height = min(mountains)

    print(max_height - min_height)

if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7440
#include <iostream>
using namespace std;
struct point {
	int xi;
	int yi;
	int hi;
};
bool judge(int a, int b) {
	if (a == b || (a <= 0 && b == 0)) {
		return true;
	}
	else return false;
}
int main() {
	int H;
	int n,count, temp,t=0;
	cin >> n;
	point points[102];
	for (int i = 0; i < n; i++) {
		cin >> points[i].xi >> points[i].yi >> points[i].hi;
		if (points[i].hi != 0) t = i;
	}
	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 101; j++) {

			H = points[t].hi + abs(i-points[t].xi) +abs(j-points[t].yi);
			count = 0;
			for (int k = 0; k < n; k++) {
				temp = H-(abs(i - points[k].xi) + abs(j - points[k].yi));
				if (!judge(temp,points[k].hi) )break;
				if (count == n - 1) {
					cout << i << " " << j << " " << H << endl;
					return 0;
				}
				count++;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3152
import sys
input = sys.stdin.readline

N = int(input())
A = [0] * N
B = [0] * N
Sum = [[0] * 2 for i in range(N)]

for i in range(N):
    A[i], B[i] = map(int, input().split())
    Sum[i][0] = i
    Sum[i][1] = A[i] + B[i]
    
a = 0
b = 0
turn = 0

Sum.sort(key=lambda x:x[1], reverse=True)
    
for i in range(N):
    if turn == 0:
        a += A[Sum[i][0]]
        turn = 1
    else:
        b += B[Sum[i][0]]
        turn = 0

print(a - b)


Measured memory_bytes: 29152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int N, K;
    cin >> N >> K;

    vector<int> a(N);

    rep(_, K)
    {
        int d;
        cin >> d;

        rep(i, d)
        {
            int p;
            cin >> p;
            --p;
            a[p]++;
        }
    }


    int ans = 0;

    rep(i, N)
    {
        if (!a[i])
            ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define bitcount(b) __builtin_popcount(b)

int main(){
	int hand[5];
	while(1){
		int bit = 0;
		rep(i,5){
			if(cin >> hand[i])bit |= 1 << (--hand[i]) ;
			else  return 0;
		}
		if( bitcount(bit) != 2){
			rep(i,5) cout << 3 << endl;
		}else{
			rep(i,5) cout << 1 + !count( hand , hand+5 , (hand[i]+1)%3 ) << endl;
		}
	}
}

Measured memory_bytes: 0
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define INF 1000000000000000000

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int n;
ll h[100110];
ll dp[100110];
int k;

ll solve(int i) {
    if(i == n-1) return 0;
    if(i >= n) return INF;
    if(dp[i] != -1) return dp[i];

    for(int j = 1; j <= k; j++) {
        dp[i] = min(dp[i] == -1 ? INF : dp[i], min(abs(h[i] - h[i+j]) + solve(i+j), abs(h[i] - h[i+j]) + solve(i+j)));
    }
    return dp[i];
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> h[i];
    cout << solve(0) << "\n";
}


Measured memory_bytes: 9600
//B
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 998244353;
const double PI = 2 * acos(0);
LL dp[3001][3001][2];

int main() {
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);
	dp[A][B][1] = 1;
	for (int i = A; i <= C; i++) {
		for (int j = B; j <= D; j++) {
			if (j > B) {
				dp[i][j][1] += (dp[i][j - 1][0]);
				dp[i][j][1] %= MOD;
				dp[i][j][1] += (i * dp[i][j - 1][1]);
				dp[i][j][1] %= MOD;
			}
			if (i > A) {
				dp[i][j][0] += (j * dp[i - 1][j][0]);
				dp[i][j][0] %= MOD;
				dp[i][j][0] += (j * dp[i - 1][j][1]);
				dp[i][j][0] %= MOD;
			}
		}
	}
	printf("%lld\n", (dp[C][D][0] + dp[C][D][1]) % MOD);
}


Measured memory_bytes: 144488
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int maxn = 1e5+5;
typedef long long ll;
//int a[maxn], b[maxn], c[maxn];
struct Node {
	int num;
	int id;
	friend bool operator<(const Node& a, const Node& b) {
		if (a.num != b.num)return a.num > b.num;
		return a.id > b.id;
	}
};
Node d[maxn*3];
int main(void)
{
	int X, Y, A, B, C;
	scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
	for (int i = 0; i < A; i++)
		scanf("%d", &d[i].num), d[i].id = 1;
	for (int i = 0; i < B; i++)
		scanf("%d", &d[i + A].num),d[i + A].id = 2;
	for (int i = 0; i < C; i++)
		scanf("%d", &d[i + A + B].num), d[i + A + B].id = 3;
	int D = A + B + C;
	sort(d, d + D);
	int cnt = 0, lim = X + Y, i = 0;
	ll ans = 0;
	while (cnt < lim) {
		Node t = d[i++];
		if (t.id == 1) {
			if (X > 0)
				X--, ans += t.num, cnt++;
		}
		else if (t.id == 2) {
			if (Y > 0)
				Y--, ans += t.num, cnt++;
		}
		else
			ans += t.num, cnt++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

long long count;


void insertionSort(int n,int A[n],int g)
{
	int v;
	int j;
	for(int i=g;i<n;i++)
	{
		v = A[i];
		j = i-g;
		while(j>=0&&A[j]>v)
		{
			A[j+g]=A[j];
			j= j-g;
			A[j+g]=v;
			count++;
		}
	}
}
void shellSort(int n,int A[n])
{
	int m=0;
	int g[n];
	for(int h=1;;)
	{
		if(h>n)break;
		g[m]=h;
		m++;
		h=3*h+1;
	}
	printf("%d\n",m);
	printf("%d",g[m-1]);
	for(int i=m-2;i>=0;i--)
	{
		printf(" %d",g[i]);
	}
	printf("\n");
	count=0;
	for(int i=m-1;i>=0;i--)
	{
		insertionSort(n,A,g[i]);
	}
	printf("%d\n",count);

}
int main(void)
{
  int n;
  scanf("%d",&n);
	int a[n];
	count=0;

	for(int i=0;i<n;i++)
	{
    	scanf("%d",&a[i]);
	}
	int count =0;
	shellSort(n,a);
	for(int i=0;i<n;i++)
	{
		printf("%d\n",a[i]);
	}

  return 0;
}



Measured memory_bytes: 5596
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

void dfs(int pos, vector<vector<int>> &Gm , vector<int> &color){
    for(auto n_node : Gm[pos]){
        if(color[n_node]!=-1) continue;
        color[n_node]=1;
        dfs(n_node, Gm, color);
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> color(n,-1);
    vector<pair<int, int>> edges(m, make_pair(0,0));
    rep(i,m){
        int u,v;
        cin >> u >> v;
        edges[i].first = v-1;
        edges[i].second = u-1;
    }

    int cnt=0;
    for(int rem = 0; rem<m; rem++){
        fill(ALL(color),-1);
        vector<vector<int>> Gm(n, vector<int>(0));
        rep(i,m){
            if(i==rem) continue;
            Gm[edges[i].first].push_back(edges[i].second);
            Gm[edges[i].second].push_back(edges[i].first);
        }

        int trees=0;
        for(int node = 0; node < n; node++){
            if(color[node]!=-1) continue;
            color[node]=1;
            dfs(node, Gm, color);
            trees++;
        }
        // cout << "trees" << trees << endl;
        if(trees >= 2) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cost(m);
    vector<int> keys(m);
    rep(i, m) {
        int k;
        cin >> cost[i] >> k;
        int mask = 0;
        rep(j, k) {
            int x;
            cin >> x;
            mask |= (1<<(x-1));
        }
        keys[i] = mask;
    }
    vector<int> dp(1<<n, INF);
    dp[0] = 0;
    rep(mask, 1<<n) rep(i, m) {
        int nxt = mask | keys[i];
        chmin(dp[nxt], dp[mask] + cost[i]);
    }
    int ans = dp[(1<<n)-1];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int w[n],all, ans = 0, tmp = 0;
    for (int i = 0; i < n;i++){
        cin >> w[i];
        ans += w[i];
    }
    all = ans;
    for (int i = 0; i < n-1;i++){
        tmp += w[i];
        ans = min(abs(all - 2 * tmp), ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long [] A = new long [N];
        long number = 1;
        long max = 1000000000000000000L;
        
        for(int i=0; i<N; i++){
            A[i] = scanner.nextLong();
        }
        
        for(int i = 0; i<N; i++){ 
         
        if(A[i] ==0){
                number = 0;
                break;
            }
            else if(A[i]<=(max/number)){
                number *= A[i];
            }
            else{
                number = -1;
            }
        }
            
            System.out.println(number);
        
    }
}

Measured memory_bytes: 61324
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int n;
vector<int> v[100010];
vector<int> Root;
bool vis[100010];
int none;
int cnt=0;
bool dfs(int x){
	vis[x]=1;
	if(x==n)return 1;
	for(int i=0;i<v[x].size();i++){
		if(!vis[v[x][i]]){
			Root.push_back(v[x][i]);
			if(dfs(v[x][i]))return 1;
			Root.erase(Root.begin()+Root.size()-1);
		}
	}
	return 0;
}
void dfs2(int x){
	vis[x]=1;
	cnt++;
	for(int i=0;i<v[x].size();i++){
		if(!vis[v[x][i]]&&v[x][i]!=none){
			dfs2(v[x][i]);
		}
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	Root.push_back(1);
	dfs(1);
	none=Root[(Root.size()+1)/2];
	memset(vis,0,sizeof(vis));
	dfs2(1);
	if(cnt*2>n)cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(s.substr(0,s.size()/2)==s.substr(s.size()/2,s.size())){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
parent=list(range(n))
rank=[0]*n
def root(x):
	if x!=parent[x]:
		x=root(parent[x])
	return x
def same(x,y):
	return root(x)==root(y)
def unite(x,y):
	rx=root(x)
	ry=root(y)
	if rank[rx]<rank[ry]:
		parent[rx]=ry
	else:
		parent[ry]=rx
		if rank[rx]==rank[ry]:
			rank[rx]+=1
f_b=[0]*n
for i in range(m):
	a,b=map(int,input().split())
	unite(a-1,b-1)
	f_b[a-1]+=1
	f_b[b-1]+=1
for j in range(k):
	c,d=map(int,input().split())
	if root(c-1)==root(d-1):
		f_b[c-1]+=1
		f_b[d-1]+=1
p=[0]*n
ans=[]
for i in range(n):
	p[root(i)-1]+=1
for i in range(n):
	r=p[root(i)-1]-f_b[i]-1
	ans.append(r)
print(*ans)

Measured memory_bytes: 15728
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;

int fact(int x){
  if(x == 1){
    return 1;
  } else{
    return x * fact(x-1);
  }
}

int main(void){
  int n;
  int pos[8][2];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> pos[i][0] >> pos[i][1];
  }
  
  double sum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i > j) continue;
      int dx = pos[i][0] - pos[j][0];
      int dy = pos[i][1] - pos[j][1];
      double dist = sqrt(dx*dx + dy*dy);
      sum += dist;
    }
  }
  double ans = sum / n * 2;
  cout << setprecision(12) << ans;
  return 0;
}


Measured memory_bytes: 256