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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
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;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll dp[105][5][2];

int main2() {
  CLR(dp, 0);
  string N; cin >> N;
  const int M = N.size();
  int K = nextInt();

  dp[0][0][0] = 1;
  for (int i = 0; i < M; i++) {
    for (int k = 0; k <= K; k++) {
      for (int d = 0; d <= 9; d++) {
        if (N[i] > '0' + d) {
          if (d == 0) {
            dp[i+1][k][1] += dp[i][k][0];
            dp[i+1][k][1] += dp[i][k][1];
          } else {
            dp[i+1][k+1][1] += dp[i][k][0];
            dp[i+1][k+1][1] += dp[i][k][1];
          }
        } else if (N[i] == '0' + d) {
          if (d == 0) {
            dp[i+1][k][0] += dp[i][k][0];
            dp[i+1][k][1] += dp[i][k][1];
          } else {
            dp[i+1][k+1][0] += dp[i][k][0];
            dp[i+1][k+1][1] += dp[i][k][1];
          }
        } else if (N[i] < '0' + d) {
          if (d == 0) {
            dp[i+1][k][1] += dp[i][k][1];
          } else {
            dp[i+1][k+1][1] += dp[i][k][1];
          }
        }
      }
    }
  }
  ll ans = dp[M][K][0] + dp[M][K][1];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.TreeSet;

public class Main {

	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	
	public static void main(String args[]) throws IOException {
		TreeSet<Job> ts = new TreeSet<Job>();
		int n = getInt();
		for ( int i = 0 ; i < n ; i++ ) {
			long a = getLong();
			long b = getLong();
			ts.add(new Job(a,b));
		}
		long t = 0L;
		for (Job j : ts) {
			t += j.a;
			if ( t > j.b ) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

class Job implements Comparable<Job>{
	long a;
	long b;
	Job(long a, long b) {
		this.a = a;
		this.b = b;
	}
	@Override
	public int compareTo(Job o) {
		if ( this.b != o.b ) {
			 if ( this.b > o.b ) {
				 return 1;
			 } else {
				 return -1;
			 }
		}
		return ((Object)this).hashCode() - ((Object)o).hashCode();
	}
	
	
}

Measured memory_bytes: 73292
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)


func main() {
	s := IOInitialize()
	s.Buffer([]byte{}, math.MaxInt64)
	in := String(s)
	out := String(s)
	inStrings := strings.Split(in, "")
	outStrings := strings.Split(out, "")
	inPermutation := make(map[string][]int)
	outPermutation := make(map[string][]int)

	inPermutation = getPermutation(inPermutation, inStrings)
	outPermutation = getPermutation(outPermutation, outStrings)

	ob := make(map[string]bool)

	for i, o := range outStrings {
		if ob[o] {
			continue
		}
		ob[o] = true
		inArray := inPermutation[inStrings[i]]
		outArray := outPermutation[outStrings[i]]
		if len(inArray) != len(outArray) {
			fmt.Println("No")
			return
		}
		for j := range inArray {
			if inArray[j] != outArray[j] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func String(s *bufio.Scanner) string {
	if !s.Scan() {
		panic("scan error")
	}
	return s.Text()
}


func getPermutation(permutation map[string][]int, chars[]string) map[string][]int {
	for i, c := range chars {
		arrayP := permutation[c]
		if arrayP == nil {
			arrayP = []int{}
		}
		arrayP = append(arrayP, i)
		permutation[c] = arrayP
	}
	return permutation
}

Measured memory_bytes: 18304
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int counter = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1')
            ++counter;
    }
    cout << counter << endl;
}


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

int main(void)
{
    char s[120];
    int k,i;

    scanf("%d",&k);
    scanf("%s",s);

    if(strlen(s)<=k) printf("%s",s);
    else
    {
        for ( i = 0; i < k; i++)
        {
            printf("%c",s[i]);
        }
        printf("...");
    }

    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n;
	cin >>n;
	ll a[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	ll dp[1<<n+1];
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	ll mod=1e9+7;
	for(int mask=0;mask<(1<<n)-1;mask++){
		int st =__builtin_popcount(mask);
		for(int i=0;i<n;i++){
			if(a[st][i]&& !(mask&(1<<i))){
				dp[mask|(1<<i)]+=dp[mask];
				dp[mask|(1<<i)]%=mod;
			}
		}
	}
	cout<<dp[(1<<n)-1];
	return 0;
	
}

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

const int maxn=1e5;
const int INF=~0U>>2;

int n,a,b;
int A[maxn+10];

inline LL f(LL x,LL y){return (x+y-1)/y;}

bool judge(int x){
	LL cnt=0;
	for(int i=1;i<=n;i++){
		if(A[i]>(LL)x*b)cnt+=f(A[i]-x*b,a-b);
	}
	return cnt<=x;
}

int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)scanf("%d",A+i);
	int L=0,R=INF;
	while(R-L>1){
		int mid=(L+R)>>1;
		if(judge(mid))R=mid;
		else L=mid;
	}
	printf("%d\n",R);
	return 0;
}


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

using namespace std;

#define LCM(a,b)                (a / __gcd(a,b) ) *b
#define GCD(a,b)                __gcd(a,b)
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define LL                      long long
#define ULL                     unsigned long long
#define pb                      push_back
#define tcase                   cout<<"Case "<<C++<<": ";
#define all(a)                  a.begin(),a.end()
#define Unique(a)               sort(all(a)),a.erase(unique(all(a)),a.end
#define ABS(x)                  ((x)<0?-(x):(x))
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(a,min(b,min(c,d)))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(a,max(b,max(c,d)))
#define PI                      acos(-1.0)
#define ff                      first
#define ss                      second
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define FastRead                ios_base::sync_with_stdio(0);cin.tie(NULL);
#define FOR(x, l, r)            for (LL x = l; x<=r; ++x)
#define REP(x,r)               for (LL x = 0; x <r; ++x)
#define NN                      cout<<"\n";
#define NNN                     cout<<"\n------------------------------\n";

//***********************************************************************//
//                      SHAHED AHMED, CSE'15, IUT                        //
//***********************************************************************//

LL n;
string s;

unordered_map<string , LL> mp;

void func(LL pos)
{
        if(pos==n)
        {
                string t;
                for(LL i=0;i<n;i++)
                {
                        if(s[i]>='a'&&s[i]<='z') t+=s[i];
                }
                for(LL i=0;i<n;i++)
                {
                        if(s[i]>='A'&&s[i]<='Z') t+=s[i];
                }

                mp[t]++;

                return;
        }

        func(pos+1);
        s[pos] += 'A' - 'a';
        func(pos+1);
        s[pos] -= 'A' -'a';

}


LL ans;

void func2(LL pos)
{
        if(pos==n)
        {

                string t;
                for(LL i=0;i<n;i++)
                {
                        if(s[i]>='a'&&s[i]<='z') t+=s[i];
                }
                for(LL i=0;i<n;i++)
                {
                        if(s[i]>='A'&&s[i]<='Z') t+=s[i];
                }

                ans+=mp[t];



                return;
        }

        func2(pos+1);
        s[pos] += 'A' - 'a';
        func2(pos+1);
        s[pos] -= 'A' -'a';

}


int main()
{

        cin>>n;
        cin>>s;

        func(0);
        reverse(all(s));

        func2(0);

        cout<<ans;

        //cout<<s;

}


Measured memory_bytes: 77556
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>

using namespace std;

#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;
const int MAXV = 1e6;


int main(){
  int H, W, K; cin >> H >> W >> K;
  char c[H][W];
  int bsum = 0;
  map<char, int> mh,mw;
  rep(i,H){
    rep(j,W){
      cin >> c[i][j];
      if (c[i][j] == '#'){
        bsum++;
        mh[char(i)]++;
        mw[char(j)]++;
      }
    }
  }
  int ans = 0;
  for (int bitH = 0; bitH < (1<<H); bitH++){
    vector<int> hvec;
    for (int i = 0; i < H; ++i){
      if(bitH & (1<<i)){
        hvec.push_back(i);
      }
    }
    for (int bitW = 0; bitW < (1<<W); bitW++){
      vector<int> wvec;
      for (int j = 0; j < W; j++){
        if(bitW & (1<<j)){
          wvec.push_back(j);
        }
      }
      int temp = bsum;
      for (int h = 0; h<hvec.size(); h++){
        temp -= mh[char(hvec[h])];
      }
      for (int w = 0; w < wvec.size(); w++){
        temp -= mw[char(wvec[w])];
      }
      for (int h = 0; h<hvec.size(); h++){
        for (int w = 0; w< wvec.size(); w++){
          if(c[hvec[h]][wvec[w]] == '#'){
            temp++;
          }
        }
      }
      if (temp == K){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
import math
import sys
import numpy

a = []
for _ in range(5):
    a.append(int(input()))

ans = 0
Q = []
for i in a:
    if i % 10 != 0:
        Q.append(10 - i%10)
    ans += i
Q.sort(reverse=True)
print(ans + sum(Q[1:]))

Measured memory_bytes: 12392
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
ll G[309][309];

void warshallFloyd(){
    
    for(int k=0; k<N; k++ ){
        for(int i=0; i<N; i++ ){
            for(int j=0; j<N; j++ ){
                if(G[i][j] > G[i][k]+G[k][j] ){
                    cout1(-1);
                    exit(0);
                }
            }
        }
    }
}

ll wf(){
    ll res=0;
    rep(i,N){
        rep(j,N){
            bool f=true;
            rep(k,N){
                if(i==k||j==k) continue;
                if(G[i][j]>=G[i][k]+G[k][j]){
                    f=false;
                    break;
                }
            }
            if(f) res+=G[i][j];
        }
    }
    return res/2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    cin>>N;
    
    rep(i,N)rep(j,N) cin>>G[i][j];
    warshallFloyd();
    ll ans=wf();
    cout1(ans);
}

Measured memory_bytes: 1024
//    freopen("/Users/wangjiaolv/Desktop/test/in.txt", "r", stdin);
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int is_prime[N], n, m, prime[N], sz = 0;
int a[N], b[N], cnt = 0;
LL fac[N];
LL qkm(LL base, LL mi) {
    LL ans = 1;
    while(mi) {
        if(mi & 1) ans = ans * base % mod;
        base = base * base % mod;
        mi >>= 1;
    }
    return ans;
}
LL C(LL n, LL m) {
    return fac[n] * qkm(fac[m]*fac[n-m]%mod, mod-2) % mod;
}
int main()
{
//    freopen("/Users/wangjiaolv/Desktop/test/in.txt", "r", stdin);
    scanf("%d%d", &n, &m);
    fac[0] = 1;
    for (int i=1; i<=N-10; i++) fac[i] = fac[i-1] * i % mod;
    int sqm = sqrt(m);
    for(int i=2;i<=sqm;i++) {
        if(!is_prime[i]) {
            prime[sz++] = i;
            for(int j=i+i;j<=sqm;j+=i) is_prime[j] = 1;
        }
    }
    for(int i=0;i<sz && m-1;i++) {
        if(m % prime[i] == 0) {
            cnt ++;
            while(m % prime[i] == 0) {
                m /= prime[i];
                b[cnt] ++;
            }
        }
    }
    if(m-1) b[++cnt] = 1;
    LL ans = 1;
    for(int i=1;i<=cnt;i++) {
        ans = ans * C(b[i]+n-1, n-1) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 3840
#include<bits/stdc++.h>
//g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG b.cpp
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define scll(x) scanf("%lld", &x)

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする

    string s;
    cin >> s;
    int n = s.length();
    int i = n - 1;
    while(i > 5){//dreamerが最初に来るのが最長の残り
        string sub = s.substr(i - 4, 5);
        if(sub == "dream" || sub == "erase"){
            i -= 5;
            continue;
        }else if(sub == "raser"){
            if(s[i - 5] == 'e'){
                i -= 6;
                continue;
            }
        }else if(sub == "eamer"){
            if(s.substr(i - 6, 2) == "dr"){
                i -= 7;
                continue;
            }
        }
        cout << "NO" << "\n";
        return 0;
    }
    //残り文字数が5 -> erase or dreamと一致するかみる，6 -> eraser, 7 -> dreamerほかはきる
    if(i == -1){
        cout << "YES" << "\n";
        return 0;
    }else if(i == 4){
        if(s.substr(0, 5) == "dream" || s.substr(0, 5) == "erase"){
            cout << "YES" << "\n";
            return 0;
        }
    }else if(i == 5){
        if(s.substr(0, 6) == "eraser"){
            cout << "YES" << "\n";
            return 0;
        }
    }else if(i == 6){
        if(s.substr(0, 6) == "dreamer"){
            cout << "YES" << "\n";
            return 0;
        }
    }

    cout << "NO" << "\n";
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
 #include<cmath>
using namespace std;
typedef long long ll;
ll max(int a, int b) 
{ 
	return (a > b) ? a : b; 
} 
int main()
{
int n;
cin>>n;
ll c;
cin>>c;
ll w[n+1];
w[0]=0;
ll v[n+1];
v[0]=0;
for(ll i=1;i<=n;i++){
    cin>>w[i];
    cin>>v[i];
}
ll dp[c+1][n+1];
for(ll i=0;i<=c;i++){
    for(ll j=0;j<=n;j++){
        dp[i][j]=0;
        }
}
for(ll i=0;i<=c;i++){
    for(ll j=0;j<=n;j++){
        if(i==0 || j==0){
            dp[i][j]=0;
        }
        else if(w[j]<=i){
            dp[i][j]=max(v[j]+dp[i-w[j]][j-1],dp[i][j-1]);
        }
        else{
            dp[i][j]=dp[i][j-1];
        }
    }
}
cout<<dp[c][n]<<endl;
    return 0;
}

Measured memory_bytes: 79104
import numpy as np
MOD = 10**9 + 7

def fft_convolve(f, g):
  Lf, Lg = f.shape[-1], g.shape[-1]
  L = Lf + Lg - 1
  fft_len = 1 << L.bit_length()
  fh, fl = f >> 15, f & (1 << 15) - 1
  gh, gl = g >> 15, g & (1 << 15) - 1
  def conv(f, g):
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    h = np.fft.irfft(Ff * Fg)
    return np.rint(h)[..., :L].astype(np.int64) % MOD
  x = conv(fl, gl)
  z = conv(fh, gh)
  y = conv(fl + fh, gl + gh) - x - z
  return (x + (y << 15) + (z << 30)) % MOD

s = input()
x, y = map(int, input().split())

Rob = list(s.split("T"))

X = [len(r) for r in Rob[::2]]
Y = [len(r) for r in Rob[1::2]]

if x < 0:
  y = abs(y)
  Xst = X[0]
  X = sorted(X[1:])
  if abs(x-Xst) <= sum(X) and y <= sum(Y):
    f = np.array([1], np.int64)
    for i in X:
      L = [0]*(2*i+1)
      L[0], L[-1] = 1, 1
      f = np.convolve(f, np.array(L, np.int64))
    FlagX = f[abs(x-Xst)+sum(X)]
    g = np.array([1], np.int64)
    for j in Y:
      L = [0]*(2*j+1)
      L[0], L[-1] = 1, 1
      g = np.convolve(g, np.array(L, np.int64))
    FlagY = g[y+sum(Y)]
    if FlagX and FlagY:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  x, y = abs(x), abs(y)
  if x <= sum(X) and y <= sum(Y):
    f = np.array([1], np.int64)
    for i in X:
      L = [0]*(2*i+1)
      L[0], L[-1] = 1, 1
      f = np.convolve(f, np.array(L, np.int64))
    FlagX = f[x+sum(X)]
    g = np.array([1], np.int64)
    for j in Y:
      L = [0]*(2*j+1)
      L[0], L[-1] = 1, 1
      g = np.convolve(g, np.array(L, np.int64))
    FlagY = g[y+sum(Y)]
    if FlagX and FlagY:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

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

int main() {
 long long a,b,c,d;
 cin >> a >> b >> c >> d;
 
 long long x;
 x = b - a + 1;
 
 long long divall = b/c + b/d - b/lcm(c,d);
 long long divpart = (a-1)/c +(a-1)/d - (a-1)/lcm(c,d);
 
 
 

 cout << x - (divall-divpart);


  }

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
	int a=0,b=0;
	string s;
	cin>>s;
	for (int i = 0; i < s.length(); ++i)
	{
		if(s[i]=='A')a=1;
		if(s[i]=='B')b=1;
	}
	if(a==1&&b==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <ctype.h>
#include <fstream>
#include <unordered_map>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n,k;
LL a[200005],dp[200005];
int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		scanf("%lld", a + i);

	for (int i = 0; i <= n + k; i++)
		dp[i] = mod * mod;

	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
		}
	}

	cout << dp[n - 1] << endl;

	return 0;
}

/*



*/

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, q; vector<ll> s, t;
	cin >> a >> b >> q;
	REP(i, a){ll tmp; cin >> tmp; s.pb(tmp);}
	REP(i, b){ll tmp; cin >> tmp; t.pb(tmp);}
	REP(i, q){
		ll x; cin >> x;
		ll ans = 5000000000000000000;
		// s -> t
		REP(j, 4){
			ll pos = x, num = 0;
			int bit = j;
				auto itr = lower_bound(ALL(s), pos);
				if(bit % 2){
					if(itr == s.end()) continue;
					num += *itr - pos;
					pos = *itr;
				} else {
					itr--;
					if(itr < s.begin()) continue;
					num += pos - *itr;
					pos = *itr;
				}
				bit /= 2;
			
				itr = lower_bound(ALL(t), pos);
				if(bit % 2){
					if(itr == t.end()) continue;
					num += *itr - pos;
					pos = *itr;
				} else {
					itr--;
					if(itr < t.begin()) continue;
					num += pos - *itr;
					pos = *itr;
				}
				bit /= 2;

			ans = min(ans, num);
		}
		// t -> s
		REP(j, 4){
			ll pos = x, num = 0;
			int bit = j;
				
				auto itr = lower_bound(ALL(t), pos);
				if(bit % 2){
					if(itr == t.end()) continue;
					num += *itr - pos;
					pos = *itr;
				} else {
					itr--;
					if(itr < t.begin()) continue;
					num += pos - *itr;
					pos = *itr;
				}
				bit /= 2;

				itr = lower_bound(ALL(s), pos);
				if(bit % 2){
					if(itr == s.end()) continue;
					num += *itr - pos;
					pos = *itr;
				} else {
					itr--;
					if(itr < s.begin()) continue;
					num += pos - *itr;
					pos = *itr;
				}
				bit /= 2;

			ans = min(ans, num);
		}
		cout << ans << endl;
	}

	return 0;
}

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

int N;
vector<int>L, R;

ll solve(int k) {
    auto cmpL = [&](int a, int b){ return L[a] < L[b]; };
    auto cmpR = [&](int a, int b){ return R[a] > R[b]; };
    priority_queue< int, vector<int>, decltype(cmpL) > que_left {cmpL};
    priority_queue< int, vector<int>, decltype(cmpR) > que_right (cmpR);
    for (int i = 0; i < N; ++i) {
        que_left.push(i); que_right.push(i);
    }

    ll ans = 0;
    vector<int>flag(N, 0);
    int cur = 0;
    for (int i = 0; i < N; ++i) {
        if ((i + k) % 2) {
            while (flag[que_right.top()]) que_right.pop();
            int t = que_right.top();
            if (R[t] >= cur) break;
            ans += cur - R[t];
            cur = R[t];
            flag[t] = 1;
        } else {
            while (flag[que_left.top()]) que_left.pop();
            int t = que_left.top();
            if (L[t] <= cur) break;
            ans += L[t] - cur;
            cur = L[t];
            flag[t] = 1;
        }
    }

    ans += abs(cur);
    return ans;
}

int main() {
    cin >> N;
    L.resize(N); R.resize(N);
    for (int i = 0; i < N; ++i) {
        cin >> L[i] >>  R[i];
    }

    ll ans = max(solve(0), solve(1));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2676
import bisect
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
C.sort()
ans = 0

for item in B:
    ans += bisect.bisect_left(A,item) * (n - bisect.bisect_right(C,item))

print(ans)

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

using namespace std;

void execute()
{
	int N, K;
	int K2;
	int x, y;
	int ans = 0;
	char color;
	int count;
	int a, b, c, d, e;

	cin >> N >> K;
	K2 = K * 2;
	int black[K2 + 1][K2 + 1] = {};

	for (int i = 0; i < N; i++)
	{
		cin >> x >> y >> color;
		if (color == 'B')
		{
			black[x % K2 + 1][y % K2 + 1]++;
		}
		else
		{
			black[(x + K) % K2 + 1][y % K2 + 1]++;
		}
	}

	for (int i = 0; i <= K2; i++)
		for (int j = 0; j <= K2 - 1; j++)
			black[i][j + 1] = black[i][j + 1] + black[i][j];

	for (int i = 0; i <= K2; i++)
		for (int j = 0; j <= K2 - 1; j++)
			black[j + 1][i] = black[j + 1][i] + black[j][i];

	for (int i = 0; i <= K; i++)
		for (int j = 0; j <= K; j++)
		{
			count = 0;

			count += black[i][j];
			count += black[K2][j] - black[i + K][j];
			count += black[i][K2] - black[i][j + K];
			count += black[K2][K2] - black[K2][j + K] - black[i + K][K2] + black[i + K][j + K];
			count += black[i + K][j + K] - black[i][j + K] - black[i + K][j] + black[i][j];

			ans = max(ans, count);
			ans = max(ans, black[K2][K2] - count);
		}

	cout << ans << endl;
}

int main()
{
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 15872
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const B = 20 , N = (1 << B) , ROOT = 2187 , mod = 924844033 ;
int n , a[N] , b[N] , res[N] ;
int sz[N] , cnt[N] ;
int fac[N] , rev[N] ;
int swn[N + 5] , sinvwn[N + 5] , invnn ;
vector <int> g[N] ;

inline int pw (int a , int b) {
	int res = 1 ;
	for (; b ; b >>= 1 , a = 1ll * a * a % mod)
		if (b & 1) res = 1ll * res * a % mod ;
	return res ;
}

inline int inv (int a) { return pw(a , mod - 2) ; }

void dfs (int v , int par = -1) {
	sz[v] = 1 ;
	for (int u : g[v]) {
		if (u == par) continue ;
		dfs(u , v) ;
		sz[v] += sz[u] ;

		cnt[sz[u]] ++ ;
		cnt[n - sz[u]] ++ ;
	}
}

void ntt (int a[N] , bool inve) {
	for (int i = 0 ; i < N ; i ++) {
		int x = 0 ;
		for (int j = 0 ; j < B ; j ++) if (i >> j & 1) x |= (1 << (B - j - 1)) ;
		if (x > i) swap(a[i] , a[x]) ;
	}

	for (int len = 2 ; len <= N ; len *= 2) {
		int wn = swn[len] ;
		if (inve) wn = sinvwn[len] ;

		for (int i = 0 ; i < N ; i += len) {
			int w = 1 ;
			for (int j = 0 ; j < len / 2 ; j ++) {
				int ex1 = (a[i + j] + 1ll * w * a[i + j + len / 2]) % mod ;
				int ex2 = (a[i + j] + 1ll * (mod - w) * a[i + j + len / 2]) % mod ;

				a[i + j] = ex1 ;
				a[i + j + len / 2] = ex2 ;

				w = 1ll * w * wn % mod ;
			}
		}
	}

	if (inve)
		for (int i = 0 ; i < N ; i ++)
			a[i] = 1ll * a[i] * invnn % mod ;
}

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

	cin >> n ;
	for (int i = 0 , u , v ; i < n - 1 ; i ++) {
		cin >> u >> v ;
		u -- , v -- ;
		g[u].push_back(v) ;
		g[v].push_back(u) ;
	}

	dfs(0) ;
	for (int i = 0 ; i < n ; i ++) cnt[i] = mod - cnt[i] ;
	cnt[n] = n ;

	fac[0] = rev[0] = 1 ;
	for (int i = 1 ; i <= n ; i ++) fac[i] = 1ll * fac[i - 1] * i % mod , rev[i] = inv(fac[i]) ;

	for (int i = 0 ; i <= n ; i ++) a[i] = 1ll * cnt[i] * fac[i] % mod ;
	for (int i = 0 ; i <= n ; i ++) b[i] = rev[n - i] ;

	for (int len = 2 ; len <= N ; len *= 2)
		swn[len] = pw(ROOT , N / len) , sinvwn[len] = pw(swn[len] , mod - 2) ;
	invnn = pw(N , mod - 2) ;

	ntt(a , 0) ;
	ntt(b , 0) ;
	for (int i = 0 ; i < N ; i ++) res[i] = 1ll * a[i] * b[i] % mod ;
	ntt(res , -1) ;

	for (int i = 1 ; i <= n ; i ++) cout << 1ll * res[n + i] * rev[i] % mod << '\n' ;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n;
    set<ll> a;
    cin >> n;
    for (ll i = 1;i < 1000010;++i) {
        if (i*i > n) break;
        a.insert(i);
        a.insert(n/i);
    }
    ll ans = 0;
    for (ll i : a) {
        // cout << i << endl;
        if (n%i == 0 && i < n/i-1) {
            ans += n/i-1;
            // cout << i << " " << n/i-1 << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 93952
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  map<string,int> siritori;
  siritori[s]++;
  rep(i,n-1){
    char last=s[s.size()-1];
    cin>>s;
    if(last!=s[0]){
      cout<<"No"<<endl;
      return 0;
    }
    siritori[s]++;
    if(siritori[s]>1){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using ll = long long;
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<int> sum(n,0);
	string s_;
	int k = 0;
	s += " ";
	while (k<n) {
		int c = 0,first=k;
		while (s[k] == 'R')k++;
		int r = k - 1, l = k;
		while (s[k] == 'L')k++;
		int end = k - 1;
		s_=s.substr(first, k - first);
		sum[r] += (r - first + 1) / 2;
		sum[l] += (r - first + 1) / 2;
		sum[r] += (end - l + 1) / 2;
		sum[l] += (end - l + 1) / 2;
		if ((r - first) % 2 == 0)sum[r]++;
		if ((end - l) % 2 == 0)sum[l]++;
	}
	REP(i, n)cout << sum[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

unsigned int y=11451419;

int rand_int(int l=0,int r=11451419){
	y=y^(y<<13);
	y=y^(y>>17);
	y=y^(y<<5);
	return y%(r-l+1)+l;
}


template<class T>
struct treap{
	struct node_t{
		T val; // 値
		node_t *lch, *rch;
		int pri; // 優先度
		int cnt; // 部分木のサイズ
		T sum; // 部分木の値の和
		node_t(T v, int p):val(v), pri(p), cnt(1), sum(v){
			lch = rch = NULL;
		}
	};
	node_t *root;
	treap():root(NULL){}

	int count(node_t *t){ return t ? t->cnt : 0; }
	T sum(node_t *t){ return t ? t->sum : 0; }
	node_t *update(node_t *t){
    	t->cnt = count(t->lch) + count(t->rch) + 1;
    	t->sum = sum(t->lch) + sum(t->rch) + t->val;
    	return t;
    }

    //木rを木lの後に追加する
    node_t *merge(node_t *l, node_t *r){
    	if(!l || !r) return l?l:r;
        if(l->pri > r->pri){ // 左の部分木の根のほうが優先度が高い
        	l->rch = merge(l->rch, r);
        	return update(l);
        }else{
        	r->lch = merge(l, r->lch);
        	return update(r);
        }
    }

    pair<node_t*, node_t*> split(node_t *t, int k){ // [0,k), [k,n)
    	if(!t) return {NULL,NULL};
    	if(k <= count(t->lch)){
    		pair<node_t*,node_t*> s = split(t->lch,k);
    		t->lch = s.second;
    		return {s.first, update(t)};
    	}else{
    		pair<node_t*,node_t*> s = split(t->rch, k-count(t->lch)-1);
    		t->rch = s.first;
    		return {update(t), s.second};
    	}
    }

    node_t *insert(node_t *t, int k, T val, int pri){
    	pair<node_t*,node_t*> s = split(t,k);
    	t = merge(s.first, new node_t(val,pri));
    	t = merge(t, s.second);
    	return update(t);
    }

   	// eraseによってsiz=0になるとバグって使えなくなるので注意
    node_t *erase(node_t *t, int k){
    	pair<node_t*,node_t*> s2 = split(t,k+1);
    	pair<node_t*,node_t*> s1 = split(s2.first, k);
    	t = merge(s1.first, s2.second);
    	return update(t);
    }

    node_t *find(node_t *t, int k){
    	int c = count(t->lch);
    	if(k < c) return find(t->lch,k);
    	if(k == c) return t;
    	return find(t->rch, k-c-1);
    }

    void insert(int k, T val){ root = insert(root, k, val, rand_int()); }
    void erase(int k){ root = erase(root, k); }
    node_t *find(int k){ return find(root,k); }

};

treap<char> tr[100005];
int n,q;

int main(void){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		for(int j=0;j<str.size();j++){
			tr[i].insert(j,str[j]);
		}
	}
	for(int i=0;i<q;i++){
		int type;
		scanf("%d",&type);
		if(type==1){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);
			a--;
			b--;
			c--;
			d--;
			auto sa=tr[a].split(tr[a].root,b);
			auto sc=tr[c].split(tr[c].root,d);
			tr[a].root=tr[a].merge(sa.first,sc.second);
			tr[c].root=tr[c].merge(sc.first,sa.second);
		}else{
			int a,b;
			char c;
			scanf("%d%d%*c%c%*c",&a,&b,&c);
			a--;
			b--;
			tr[a].insert(b,c);
			tr[a].erase(b+1);
		}
	}
	for(int i=0;i<n;i++){
		int v=tr[i].count(tr[i].root);
		for(int j=0;j<v;j++){
			printf("%c",tr[i].find(j)->val);
		}
		printf("\n");
	}
	return 0;
} 


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

#define endl '\n'
#define left aba
#define right abc
#define oo if(LOG)
#define pb push_back
#define FIO ios_base::sync_with_stdio(0); cin.tie(0)

#ifdef LOCAL
#define LOG 1
#else
#define LOG 0
#endif

using namespace std;

const int N = 3003;

int n;

int a[N];
long long dp[N][N][2];

long long go2(int left, int right);

long long go1(int left, int right) {
    if(left == right) return a[left];
    if(dp[left][right][0] != -1) return dp[left][right][0];
    return dp[left][right][0] = max(go2(left + 1, right) + a[left], go2(left, right - 1) + a[right]);
}

long long go2(int left, int right) {
    if(left == right) return -a[left];
    if(dp[left][right][1] != -1) return dp[left][right][1];
    return dp[left][right][1] = min(go1(left + 1, right) - a[left], go1(left, right - 1) - a[right]);
}

int main() {
    FIO;

    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) for(int k = 0; k < 2; ++k) dp[i][j][k] = -1;
    cout << go1(0, n - 1) << endl;

    oo cout << "Time: " << (double)clock() / CLOCKS_PER_SEC << "s" << endl;
    return 0;
}


Measured memory_bytes: 141184
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> li = new ArrayList<>();
    for(int i = 0;i < N;i++){
      li.add(sc.nextInt());
    }
    int total = 0;
    for(int j = N - 1;j > 0;j--){
      for(int k = 0;k < j;k++){
        total += li.get(j) * li.get(k);
      }
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 23764
N=int(input())
S=input()
d = [0]*(N+1) # d[i]: Sの最初のi文字における
              # "(" - ")"
for i in range(1, N+1):
    d[i] = S[:i].count("(") - S[:i].count(")")
x = min(d)
# x = 0 かつ d[N]=0ならよい
if x == 0 and d[N] == 0:
    print(S)
    exit()

ans = "("*abs(x) + S + ")"*(d[N]+abs(x))
print(ans)

Measured memory_bytes: 61956
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());


            if (x == 3 || x == 5 || x == 7)
                Console.WriteLine("YES");

            else
                Console.WriteLine("NO");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
N, K = map(int, input().split())
     
if K == 0:
    print(N**2)
    exit()
     
cnt = 0
for b in range(1, N+1):
    p = N // b
    r = N % b
    cnt += max(0, b-K) * p
    cnt += max(0, r-K+1)
     
print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<vector<int>> a = {{3, 5, 7}, {3, 5}, {5, 7}, {3, 7}, {3}, {5}, {7}};
    int count = 0;
    rep(j, 0, 7){
        queue<int64_t> q;
        rep(i, 0, a.at(j).size()) q.push(a.at(j).at(i));
        while(true){
            int64_t x = q.front();
            if (x > N) break;
            if ((j == 0)||(j >= 4)) count++;
            else count--;
            q.pop();
            rep(i, 0, a.at(j).size()){
                int64_t y = x * 10 + a.at(j).at(i);
                q.push(y);
            }
        }
    }
    cout << count << endl;
}

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

int main(void) {
	string S;
	cin >> S;

	int ss = S.size();
	string A = "x";
	string Ans;
	for (int i = 0; i < ss; i++) {
		Ans += A;
	}

	cout << Ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 200005
#define LL long long
int n,m,k;
string s;
int sum[12][1005];
bool mp[12][1005];
int ans=99999999;
int a[12];

bool check(int cnt,int j,int la){  
    int s=0;
    for(int i=1;i<=cnt;i++){
        s=sum[a[i]][j]-sum[a[i]][la]-sum[a[i-1]][j]+sum[a[i-1]][la];
        if(s>k)return 0;
    }
    return 1;
}

void work(int t){     
    int s=t,la=0;
    a[t+1]=n;
    for(int i=1;i<=m;i++)if(!check(t+1,i,la))s++,la=i-1;
    if(check(t+1,m,m-1))ans=min(ans,s); 
}

void dfs(int now,int t){ 
    if(now==n){
        work(t);
        return;
    }
    a[t+1]=now,dfs(now+1,t+1);
    dfs(now+1,t);
}
int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>s;
        for(int j=1;j<=m;j++)
            mp[i][j]=s[j-1]-'0',sum[i][j]=sum[i][j-1]+mp[i][j]+sum[i-1][j]-sum[i-1][j-1];
    }
    dfs(1,0);
    cout<<ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, k, *a = map(int, open(0).read().split())
m = 10**9 + 7
c = [0] * 2001
t1 = [0] * n
for i in range(n):
    c[a[i]] += 1
    t1[i] = sum(c[a[i] + 1:])
t2 = [0] * n
for i in range(n):
    c[a[i]] += 1
    t2[i] = sum(c[a[i] + 1:])
s1 = sum(t1)
s2 = sum(t2)
print((s1 * k % m + k * (k - 1) // 2 * (s2 - s1) % m) % m)


Measured memory_bytes: 73676
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct Maze {
  int id;
  int parent;
  int cost;
};
int N;

vec< vec< int > > g;
vec< int > c;
queue< Maze > q;
vec< int > parent;

int bfs() {
  Maze s = {N - 1, N - 1, 0};
  parent[N - 1] = N - 1;
  q.push(s);
  while (!q.empty()) {
    Maze now = q.front();
    q.pop();
    if (now.id == 0) {

      return now.cost;
    }
    FORA(e, g[now.id]) {
      Maze next = {e, now.id, now.cost + 1};
      if (parent[e] == -1) { //  注意
        parent[e] = now.id;
        q.push(next);
      }
    }
  }
  return -1;
}
void dfs(int id, int color) {
  c[id] = color;
  FORA(e, g[id]) {
    if (c[e] == -1) {
      dfs(e, color);
    }
  }
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> N;
  g.resize(N, vec< int >());
  REP(i, N - 1) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    g[p].pb(q);
    g[q].pb(p);
  }
  c.assign(N, -1);
  parent.assign(N, -1);
  bfs();

  // find path
  int now = 0;
  vec< int > path;
  while (now != N - 1) {
    path.pb(now);
    now = parent[now];
  }
  path.pb(N - 1);
  int pathsize = path.size();
  // PRINTALL(path);

  // REP(i, ((pathsize + 1) / 2)) { c[path[i]] = 1; }
  FOR(i, ((pathsize + 1) / 2), pathsize) { c[path[i]] = 0; }
  int col = 1;
  dfs(0, col);
  //  REP(i, (int)path.size() / 2) { c[path[i]] = 1; }
  int ans = 0;
  REP(i, N) {
    if (c[i] == col) {
      ans++;
      //     DEBUG(i);
    }
  }
  // DEBUG(ans);
  //  DEBUG(N);
  if (ans > N / 2) {
    print("Fennec");
  } else {
    print("Snuke");
  }
}

Measured memory_bytes: 9716
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

A,B,C,X,Y = inpl()

#X<=Yに固定
if X > Y:
	X,Y = Y,X
	A,B = B,A

ans = 0
if A+B <= C*2: #セットがゴミ
	ans += X*A + Y*B
else:
	ans += X*2*C
	Y -= X
	ans += min(B*Y,C*2*Y)

print(ans)

Measured memory_bytes: 4208
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  ll l, r;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <cstdio>

int main(){
  int n;
  int R[200000];
  int cur_min = 0;
  int max = 0x80000000;
  scanf("%d", &n);

  scanf("%d", &R[0]);
  cur_min = R[0];

  for(int i = 1; i < n; i++){
    scanf("%d", &R[i]);
    max = (R[i] - cur_min > max) ? R[i] - cur_min : max;
    if(cur_min > R[i]){
      cur_min = R[i];
    }
  }
  printf("%d\n", max);
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K, tmp_h;

  int result = 0;

  cin >> N >> K;
  REP(i, N) {
    cin >> tmp_h;
    if(tmp_h >= K){
      ++result;
    }
  }

  cout << result << endl;
  
  return 0;
}


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

struct Node
{
	int key;
	Node* prev;
	Node* next;
};

Node* nil;

void init()
{
	nil = (Node*)calloc(1, sizeof(Node));
	if (nil == NULL) cout << "記憶域の確保に失敗しました。" << endl;
	else {
		nil->key = 0;
		nil->prev = nil;
		nil->next = nil;
	}
}

void insert_node(int key)
{
	Node* ptr = (Node*)calloc(1, sizeof(Node));
	if (ptr == NULL) cout << "記憶域の確保に失敗しました。" << endl;
	else {
		ptr->key = key;
		ptr->next = nil->next;
		nil->next->prev = ptr;
		nil->next = ptr;
		ptr->prev = nil;
	}
}

Node* list_search(int key)
{
	Node* ptr = nil->next;
	while (ptr != nil && ptr->key != key) {
		ptr = ptr->next;
	}
	return ptr;
}

void delete_node(Node* ptr)
{
	if (ptr == nil) return;
	ptr->prev->next = ptr->next;
	ptr->next->prev = ptr->prev;
	free(ptr);
}

void delete_key(int key)
{
	delete_node(list_search(key));
}

void delete_first()
{
	delete_node(nil->next);
}

void delete_last()
{
	delete_node(nil->prev);  // これで本当に消える？納得がいかない...
}

void print_node()
{
	Node* ptr = nil->next;
	int i = 0;
	while (ptr != nil) {
		if (0 < i++) printf(" ");
		printf("%d", ptr->key);
		ptr = ptr->next;
	}
	printf("\n");
}

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

	for (int i = 0; i < n; i++) {
		char cmd[20];
		int key;
		scanf("%s", cmd);
		if (cmd[0] == 'i') {
			scanf("%d", &key);
			insert_node(key);
		}
		else if (cmd[0] == 'd') {
			if (6 < strlen(cmd)) {
				if (cmd[6] == 'F') delete_first();
				else if (cmd[6] == 'L') delete_last();
			}
			else {
				scanf("%d", &key);
				delete_key(key);
			}
		}
	}
	print_node();
}


Measured memory_bytes: 34488
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String s1 = sc.next();
   String s2 = sc.next();
   String s3 = sc.next();
   
   String anslow = s1.substring(0,1)+s2.substring(0,1)+s3.substring(0,1);
   anslow = anslow.toUpperCase();
   System.out.println(anslow);
 }
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    int num,count=0;
    for(int i=0;i<n;++i){
        cin >> num;
        if(num>=k) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forit(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define REP(i,f,t) for(int i=f;i<(int)t;++i)
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int inf = 1e9+5;

int n,k,i,j;
int main(){
	fast_io;
	cin >> n >> k;
	vector<int> a(n);
	for(int &s : a)cin>>s;
	vector<bool> dp(k+1);

	for(i=0;i<=k;++i){
		for(int s : a){
			if(i-s>=0 && !dp[i-s])dp[i]=true;
		}
	}
	cout << (dp[k]? "First" : "Second") << '\n';
}


Measured memory_bytes: 256