akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    char c[3][4];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 4; j++){
            scanf("%c",&c[i][j]);
        }
    }

    for(int i = 0; i < 3; i++){
        printf("%c",c[i][i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  ll n, t;
  cin >> n >> t;
  ll a[n];
  ll a_min, a_min_prev;
  int count = 0;
  REP(i, n){
    cin >> a[i];    
  }  
  ll diff_m=0LL;
  ll temp_m;
  a_min_prev = a[0];
  FOR(i, 1, n) {    
    a_min = min(a_min_prev, a[i]);
    temp_m = (a[i] - a_min_prev);
    if(temp_m > diff_m) {
      diff_m = temp_m;
      count = 1;
    }
    else if (temp_m == diff_m) {
      ++count;
    }
    a_min_prev = a_min;
  }
 
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

using namespace std;

class UnionFind {
  int n;
  vector<int> par, rk;
public:
  UnionFind(int n) : n(n) {
    par.resize(n);
    rk.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rk[i] = 0;
    }
  }

  int f(int i) {
    if (i == par[i]) return i;
    return par[i] = f(par[i]);
  }

  void unite(int x, int y) {
    x = f(x);
    y = f(y);
    if (rk[x] < rk[y]) {
      par[x] = y;
    } else if (rk[x] > rk[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      rk[y] += 1;
    }
  }
};

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

  UnionFind uf(N);

  for (int i = 0; i < M; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    uf.unite(x - 1, y - 1);
  }

  unordered_set<int> s;
  for (int i = 0; i < N; i++) {
    s.insert(uf.f(i));
  }

  cout << s.size() << endl;
}


Measured memory_bytes: 5156
// http://www.igaris.com/math/c.pdf

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define NEXTP(x) next_permutation(x.begin(),x.end())
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

class comb{
	public:
	vector<ll> f,fr;
	ll MOD;
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){//input max_n
		MOD = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
			fr[i] = calc(f[i],mod-2,mod);
		}
	}
	ll nCr(ll n,ll r){
		return f[n] * fr[r] % MOD * fr[n-r] % MOD;
	}
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,k;
	cin >> n >> k;
	comb co;
	if(n>k){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
	}
	
}


Measured memory_bytes: 3148
import fractions
import math

def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True


def divisor(n):
    divisor = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisor.append(i)
            if i != n // i:
                divisor.append(n // i)
    return divisor


a, b = map(int, input().split())
n = set(divisor(a)) & set(divisor(b))
r = len(n)
cnt = 0
for i in n:
    if isPrime(i):
        cnt += 1
print(cnt)


Measured memory_bytes: 7164
n, m = [int(x) for x in input().split()] # n: 頂点, m: 辺
line = [ tuple( int(x)-1 for x in input().split() ) for _ in range(m) ]

matrix = [ [False]*n for _ in range(n) ] # n x n 行列
for a, b in line:
    matrix[a][b] = True
    matrix[b][a] = True

visited = [False]*n

def dfs(point, depth):
    if visited[point]:
        return 0

    if depth == n - 1:
        return 1

    visited[point] = True
    total = 0
    for i, np in enumerate(matrix[point]):
        if np:
            total += dfs(i, depth + 1)

    visited[point] = False
    return total

print(dfs(0, 0))


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

int main() {
    int a,b;
    cin >> a >> b ; 
    int big = max (a,b);
    int small= min(a,b);
    ll i=1,ans;
    while(1){
        ans = big*i;
        if (ans % small ==0)
            break;
        i++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

//const int N=1e5+100;
using namespace std;

typedef long long ll;
int mod=2019;
int vis[2050];
int main()
{
    vis[0]++;
    string s;cin>>s;
    int base=1;
    ll sum=0;
    ll ans=0;
    for(int i=s.size()-1;i>=0;i--){
        sum=(sum+(s[i]-'0')*base)%mod;
        ans+=vis[sum];
        vis[sum]++;
        base=base*10%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3508
import java.math.BigDecimal
import java.math.MathContext

fun main(args : Array<String>) {
    val result = Begginer20190928A.exec(readLine()!!.toInt())
    println(result)
}


object Begginer20190928A {
    fun exec(input : Int) : String {
        val isOdd = input % 2 == 1

        val oddCount = if (isOdd) {
            (input - 1) / 2 + 1
        } else {
            (input) / 2
        }

        return BigDecimal(oddCount)
                .divide(BigDecimal(input), MathContext(10))
                .toString()
    }
}

Measured memory_bytes: 33572
#include <stdio.h>
int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
 
  int a, b;
 
  while(H!=0 || W!=0){
    for(a=0; a<H; a++){
      if(a%2==0){
	for(b=0; b<W; b++){
	  if(b%2==0){
	    printf("#");
	  }else{
	    printf(".");
	  }
	}
      }else{
	for(b=0; b<W; b++){
	  if(b%2==1){
	    printf("#");
	  }else{
	    printf(".");
	  }
	}
      }
      printf("\n");
    }
    printf("\n");
    scanf("%d %d", &H, &W);
  }
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<bool>> canmatch(n,vector<bool>(n));
    rep(i,0,n) rep(j,0,n) {
        int x;
        cin >> x;
        canmatch[i][j] = x==1;
    }
    vector<ll> dp(1<<n, 0);
    dp[0] = 1;
    const ll MOD = 1e9+7;
    rep(i,0,n) {
        vector<ll> next(1<<n,0);
        rep(mask,0,1<<n) if(dp[mask]!=0) {
            rep(j,0,n) if(canmatch[i][j] && (mask&(1<<j))==0) {
                next[mask|(1<<j)] = (next[mask|(1<<j)]+dp[mask])%MOD;
            }
        }
        swap(next,dp);
    }
    ll ans = dp[(1<<n)-1];
    cout <<ans << "\n";
}


Measured memory_bytes: 33024
#include "bits/stdc++.h"

using namespace std;

const int N = 5e5 + 5;

#define int long long

signed main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int s=1,ans=0;
	while(n>0)
	{
		ans=ans+s;
		s=s*2;
		n=n/2;
	}
	cout<<ans;
	return 0;
}

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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> dp(3);
    // dp[i] - the total cost such that we did activity i on the last considered day
    for(int day = 0; day < n; ++day) {
        vector<int> new_dp(3, 0);
        vector<int> c(3);
        for(int i = 0; i < 3; ++i) {
            scanf("%d", &c[i]);
        }
        // int a, b, c - a lot of implementation
        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 3; ++j) {
                if(i != j) {
                    new_dp[j] = max(new_dp[j], dp[i] + c[j]);
                }
            }
        }
        dp = new_dp;
    }
    printf("%d\n", max({dp[0], dp[1], dp[2]}));
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	string n;
	cin >> n;
	cout << "ABC" + n << endl;
	return 0;
}

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

using namespace std;

bool check(string &s, int b, int e) {
    if (s[e] == '#') {
        return 0;
    }
    for (int i = b; i < e; ++i) {
        if (s[i] == '#' && s[i + 1] == '#') {
            return 0;
        }
    }
    return 1;
}

bool check3(string &s, int b, int e) {
    for (int i = max(2, b); i <= e; ++i) {
        if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') {
            return 1;
        }
    }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    string s;
    cin >> s;
    s = '$' + s;

    if (!check(s, a, c) || !check(s, b, d)) {
        cout << "No";
        return;
    }
    if (c < d) {
        cout << "Yes";
        return;
    }
    cout << (check3(s, b, d) ? "Yes" : "No");
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);

    solve();
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ull unsigned long long 
    #define ld long double
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair
    ll mod=1e9+7;
 
     ll a[200005];
       ll b[200005];
 
     ll idx[100005][2];
    // ll cnt[200005];
     ll pre[200005];
    // ll end[200005];
     map<ll,ll> m;
 
    bool comp(const pair<ll,ll>& a, const pair<ll,ll>& b){
      return (a.fi-a.se)>(b.fi-b.se);
    }
 
    bool revcomp(const pair<ll,ll>& a, const pair<ll,ll>& b){
      return (a.fi)>(b.fi);
    }
 
 
    ll ceil1(ll a, ll b){
      if(a%b!=0)return a/b+1;
      else return a/b;
    }
    ll power(ll a,ll b,ll n){ll ans=1;while(b>0){if(b%2==1)ans=(ans*a)%n;a=(a*a)%n;b/=2;}return ans;}
 
    ll count1=0;
 
 
    ll gcd(ll a, ll b){
      //if(a<b)swap(a,b);
      if(b==0)return a;
      return gcd(b,a%b);
    }
 
  ll primepos(ll fact, ll p) 
  { 
      ll res = 0; 
      while (fact > 0) {         
          res += fact / p; 
          fact /= p;  
      } 
    
      return res; 
  } 
 
  // void dfs(ll n, ll p){
  //   if(vis[n]!=0){
  //     return;
  //   }
  //   else{
  //     vis[n]=1;
  //     b[n]=p;
  //     for(int i=0;i<v[n].size();i++){
  //       dfs(v[n][i],p);
  //     }
  //   }
  // }

   
   int main(){

      ios::sync_with_stdio(0);
      int n,k;
      cin>>n>>k;
      for(int i=0;i<n;i++){
        cin>>a[i];
      }
      int b[k+1];
      memset(b,0,sizeof b);
      for(int i=0;i<=k;i++){
        for(int j=0;j<n;j++){
          if(i>=a[j]&&b[i-a[j]]==0){
            b[i]=1;
          }
        }
      }
      if(b[k]==1)cout<<"First"<<endl;
        else cout<<"Second"<<endl;
      //cout<<b[k]<<endl;

      return 0;
}

Measured memory_bytes: 2688
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

s = LS2()

print(s[0]+str(len(s)-2)+s[-1])

Measured memory_bytes: 79820
#include<stdio.h>
#include<string.h>

int main(void){

  char S[100001];
  scanf("%s", S);
  int count = 0;

  for(int i = 0 ; i < strlen(S) - 1 ; i++){
    if(S[i] == '0' && S[i + 1] == '0'){
      S[i + 1] = '1';
      count++;
    }else if(S[i] == '1' && S[i + 1] == '1'){
      S[i + 1] = '0';
      count++;
    }
    
  }

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


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

int main ()
{
  string input;
  getline(cin, input);
  
  int answer_p1 = 0;
  int answer_p2 = 0;
  
  for (int i = 0; i < input.size(); i ++)
  {
    // 10101...
    if ((i % 2) == 0 && input[i] != '1')
    {
      ++ answer_p1;
    }
    else if ((i % 2) != 0 && input[i] != '0')
    {
      ++ answer_p1;
    }
    
    // 010101...
    if ((i % 2) == 0 && input[i] != '0')
    {
      ++ answer_p2;
    }
    else if ((i % 2) != 0 && input[i] != '1')
    {
      ++ answer_p2;
    }
  }
  
  if (answer_p1 < answer_p2)
    cout << answer_p1 << endl;
  else
    cout << answer_p2 << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int v[] = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(v);

        double maxValue = v[0];
        for (int i = 1; i < n; i++) {
            maxValue = (maxValue + v[i]) / 2;
        }

        System.out.println(maxValue);
    }
}


Measured memory_bytes: 23508
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
using namespace std;
const int MAX = 1e4+1;
const double EPS = 1e-6;
const double INF = 1e18;
const double PI = acos(-1);
typedef complex<double> P;

double angle(P a, P b){
    return abs(arg(a/b));
}

int main(){
    int n;
    double r, theta;
    cin >> n >> r >> theta;
    theta = theta/180*PI;

    vector<P> xy(n);
    for(int i=0; i<n; i++){
        double x,y;
        cin >> x >> y;
        xy[i] = P(x,y);
    }

    vector<vector<vector<double> > > dp(n+1, vector<vector<double> >(n, vector<double>(MAX, INF)));
    dp[n][0][0] = 0;
    vector<vector<vector<bool> > > cango(n+1, vector<vector<bool> >(n, vector<bool>(n, true)));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
                if(i==j || j==k || angle(xy[j]-xy[i], xy[k]-xy[j]) > theta +EPS){
                    cango[i][j][k] = false;
                }
            }
        }
    }
    int ans=0;
    for(int k=0; k<MAX-1; k++){
        for(int i=0; i<n+1; i++){
            for(int j=0; j<n; j++){
                if(dp[i][j][k]==INF) continue;
                for(int p=0; p<n; p++){
                    if(p==j) continue;
                    if(!cango[i][j][p]) continue;
                    double dist = dp[i][j][k] + abs(xy[p]-xy[j]);
                    if(dist < dp[j][p][k+1] && dist < r +EPS){
                        dp[j][p][k+1] = dist;
                        ans = k+1;
                    }
                }
            }
        }
        if(ans!=k+1) break;
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    int a, b;
    cin >> a >> b;
    for (int x = 0; x <= 1000; x++) {
        int y = (int)(x * 0.08);
        int z = (int)(x * 0.1);
        if (y == a && z == b) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

#define int_inf 1000000000 //1e9
#define ll_inf  100000000000000000 //1e17

using namespace std;

int solve();

int n;
int f[100][10];
int p[100][11];
int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		for(int j=0; j<10; j++){
			cin >> f[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<=10; j++){
			cin >> p[i][j];
		}
	}
//cout << "#" << endl;	
	cout << solve() << endl;
	
	return 0;
}

int solve(){
	vector<int> d;
	d.resize(10);
	int a;
	int count;
	int point=0;
	int ans=int_inf*(-1);
	for(long long i=1; i<pow(2.0,10); i++){
		point = 0;
		a = i;
		for(int j=0; j<10; j++){
			d[j] = a%2;
			a /= 2;
		}
		
		for(int j=0; j<n; j++){
			count = 0;
			for(int k=0; k<10; k++){ if(f[j][k]==1 && d[k]==1) count+=1; }
			point += p[j][count];
		}
//cout << point << endl;
		ans = max(ans, point);
	}
//for(int i=0; i<10; i++) cout << d[i] << " ";
//cout << endl;
	return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main(void)
{
    int k, s;
    cin >> k >> s;
    double verify = s / (k * 3);
    if (verify >= 1)
    {
        if (verify == 1)
        {
            cout << 1 << endl;
            return 0;
        }
        else
        {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = 0;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            int tmp = s - i - j;
            if (0 <= tmp && tmp <= k)
                ans += 1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3520
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

x=ii()
ans=0
p=x//500
ans+=p*1000

x-=p*500
if x>=0:
    q=x//5
    ans+=q*5

print(ans)






Measured memory_bytes: 65388
package main

import (
	"fmt"
)

func getDist(x, y int) int {
	if x < y {
		return y - x
	}
	return x - y
}

func getGcd(a, b int) int {
	if b == 0 {
		return a
	}
	return getGcd(b, a%b)
}

func main() {
	var N, X int
	fmt.Scan(&N, &X)

	points := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&points[i])
	}

	dists := make([]int, N)
	for i := 0; i < N; i++ {
		dists[i] = getDist(X, points[i])
	}

	gcd := 0
	for _, d := range dists {
		gcd = getGcd(gcd, d)
	}

	fmt.Println(gcd)
}


Measured memory_bytes: 7296
uses math;
var
  a,dp:array[0..101010] of int64;
  n,i,j,k:longint;
BEGIN
  ///assign(input,'a.in'); reset(input);
  readln(n,k);
  for i:=1 to n do read(a[i]);
  for i:=0 to n+1 do dp[i] := high(int64);
  dp[1]:=0;
  for i:=2 to n do 
    for j:=max(1,i-k) to i-1 do dp[i] := min(dp[i], dp[j] + abs(a[i]-a[j]));
  writeln(dp[n]);
END.

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<endl;
	return 0;
}


Measured memory_bytes: 384
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local mab = math.abs
local mod = 1000000007
local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function modpow(src, pow)
  local res = 1
  while (0 < pow) do
    if (pow % 2 == 1) then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res;
end

local str = io.read()
local n = #str
local t = {}
local a = {}
for i = 1, n do
  t[i] = tonumber(str:sub(n + 1 - i, n + 1 - i))
  a[i] = 0
end
a[1] = t[1] == 1 and 3 or 1
for i = 2, n do
  if t[i] == 0 then
    a[i] = a[i - 1]
  else
    a[i] = (modpow(3, i - 1) + bmul(2, a[i - 1])) % mod
  end
end
print(a[n])


Measured memory_bytes: 2652
//wxlcoder
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <numeric>
#include <utility>
#include <queue>
#include <memory>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <iterator>
#include <deque>
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MAXN 
#define MAXM
using namespace std;
/*********default*********/

int main()
{
	
	int a[7]={1,3,5,7,8,10,12};
	int b[4]={4,6,9,11};
	int c[1]={2};
	int x,y,cnt=0;
	scanf("%d%d",&x,&y);
	for(int i=0;i<7;i++)
	{
		for(int j=0;j<7;j++)
		{
			if(x==a[i]&&y==a[j])
			{
				cnt=1;
				break;
			}
		}
	}
	for(int i=0;i<4;i++)
	{
		for(int j=0;j<4;j++)
		{
			if(x==b[i]&&y==b[j])
			{
			    cnt=1;
				break;
			}
		}
	}
	if(x==c[0]&&y==c[0])
	{
		cnt=1;
	}
	if(cnt==1)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
} 

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int A, B, C, D, E;
    std::cin >> A >> B >> C >> D >> E;

    int res;
    if(A < 0){
        res = (-A) * C + D + B * E;
    }else{
        res = (B - A) * E;
    }

    std::cout << res << std::endl;
}



Measured memory_bytes: 3168
n,m = map(int,input().split())
s = input()

s_0 = []
for i in range(n+1):
    if(s[i] == '0'):
        s_0.append(i)

# 二分木
import bisect

now = n
ans_rev = []
while(now != 0):
    next_i = bisect.bisect_left(s_0, now-m)
    next = s_0[next_i]
    if(now == next):
        print(-1)
        exit()
    ans_rev.append(now-next)
    now = next

print(' '.join(map(str, ans_rev[::-1])))

Measured memory_bytes: 56604
#include <iostream>
using namespace std;
int main(){
 int a,b;
 cin>>a>>b;
 if(a<b){
  cout<<"a"<<" < "<<"b"<<endl;
 }
 if(a>b){
  cout<<"a"<<" > "<<"b"<<endl;
 }
 if(a==b){
  cout<<"a"<<" == "<<"b"<<endl;
 }
 return 0;
}

Measured memory_bytes: 1156
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;


#define int long long
// #define double ld
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void accell() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}


signed main() {
    srand(time(0));
    accell();
    int n;
    cin >> n;
    stack<pair<int, int> > st;
    st.push({n, 1});
    int ans = 0;
    while (!st.empty()) {
        int v = st.top().first;
        int num = st.top().second;
        ans += num;
        st.pop();
        if (v > 1)
            st.push({v / 2, 2 * num});
    }
    cout << ans;
    return 0;
}


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

int main(void){
    int a,b,c;cin>>a>>b>>c;
    int n=a+b+c;n/=3;
    if(a==n&&b==n&&c==n){cout<<"No\n";return 0;}
    if(a==b||b==c||c==a)cout<<"Yes\n";
    else cout<<"No\n";
    
    
    return 0;
}


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

namespace ABC131
{
    class C
    {
        static void Main(string[] args)
        {

            long[] a = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
            long A = a[0], B = a[1], C = a[2], D = a[3];
            long CD = GetLeastCommonMultiple(C, D);

            long total = B - A + 1;
            long divC = Count(A, B, C);
            long divD = Count(A, B, D);
            long divCD = Count(A, B, CD);
            long s = total - divC - divD + divCD;
            Console.WriteLine(s);

        }

        static long Count(long x, long y, long d)
        {
            long a = x / d; long ma = x % d;
            long b = y / d; 

            long r = b - a;
            if (ma == 0) r++; 
            return r;
        }

        //最大公約数(Euclid互除法:O(log n)
        public static long GetGreatestCommonFactor(long x, long y)
        {
            while (x > 0 && y > 0)
            {
                if (x > y)
                {
                    x %= y;
                }
                else
                {
                    y %= x;
                }
            }
            return Math.Max(x, y);
        }

        //最小公倍数
        public static long GetLeastCommonMultiple(long x, long y)
        {
            long gcf = GetGreatestCommonFactor(x, y);
            long zz = y / gcf;
            return x * zz;
        }


    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <cctype>

using namespace std;

class Parser{
    public:

    string s;
    int i, n;

    Parser(string s): s(s) {}

    int parse(){
        i = 0;
        n = s.length();
        return expr();
    }

    private:

    int expr(){
        int ret = term();
        while(s[i] != '='){
            if(s[i] == '+'){
                i++;
                ret += term();
            }else if(s[i] == '-'){
                i++;
                ret -= term();
            }else{
                break;
            }
        }
        return ret;
    }

    int term(){
        int ret = fac();
        while(i < n){
            if(s[i] == '*'){
                i++;
                ret *= fac();
            }else if(s[i] == '/'){
                i++;
                ret /= fac();
            }else{
                break;
            }
        }
        return ret;
    }

    int fac(){
        if(isdigit(s[i])) return num();
        i++;
        int ret = expr();
        // int ret = num();
        // while(s[i] != ')'){
        //     if(s[i] == '+'){
        //         i++;
        //         ret += num();
        //     }else if(s[i] =='-'){
        //         i++;
        //         ret -= num();
        //     }else{
        //         break;
        //     }
        // }
        i++;
        return ret;
    }

    int num(){
        int ret = s[i] - '0';
        i++;
        while(isdigit(s[i])){
            ret = ret * 10 + (s[i] - '0');
            i++;
        }
        return ret;
    }

};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        Parser p = Parser(s);
        cout << p.parse() << endl;
    }
}


Measured memory_bytes: 3156
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

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

	vector<int> a(3);
	cin >> a[0]>> a[1] >> a[2];

	sort(all(a));

	int diff = a[2] - a[0] + a[2] - a[1];
	int ans = diff / 2;
	if (diff % 2) ans += 2;

	out(ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAX = 2e3 + 10;
typedef long long i64;
using namespace std;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
#define mul(a, b) ((i64)(a) * b % MOD)


int minm(int low, int high, int target0, int target1){
	int a1 = -low + high - low + abs(target0 - high);
	int a2 = high + high - low + abs(target0 - low);
	int a3 = -low + high - low + abs(target1 - high);
	int a4 = high + high - low + abs(target1 - low);
	return min(min(a1, a2), min(a3, a4));
}
int main() {

    #ifdef LOCAL_DEBUG
    freopen ("data.in", "r", stdin );
    //freopen ("data.out", "w", stdout );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    #define endl '\n'

    int a[4];
	for(int i = 0; i < 4; i++)cin>>a[i];
    i64 n; cin >> n;
    n *= 4;
    i64 x[4] = {0, 0, 0, 0};
    x[0] = n;
    for(int i = 1; i < 4; i++){
    	for(int j = 0; j < i; j++){
    		if((1 << (i - j))* a[j] > a[i] ){
    			i64 cur = x[j] /(1 << (i - j));
    			x[i] += cur;
    			x[j] %= (1 << (i - j));
    		}
    	}
    }
    i64 ans = 0;
    for(int i = 0; i < 4 ;i++)
    	ans += (i64)x[i] * a[i];
    cout << ans;

}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>
 
#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;
 
int main()
{
	string str,bubu;
	cin >> str >> bubu;
	
	vector<string> v;
	
	REP(i,str.size() - bubu.size() + 1)
	{
		bool flag = false;
		REP(j,bubu.size())
		{
			if(!(str[i+j] == '?' || str[i+j] == bubu[j]))
			{
				flag = true;
				break;
			}
		}
		if(flag)continue;
		
		string inp = "";
		REP(j,str.size())
		{
			if(str[j] == '?')
				inp += "a";
			else
				inp += str[j];
		}
		
		REP(j,bubu.size())
		{
			inp[i+j] = bubu[j];
		}
		
		v.PB(inp);
		
	}
	
	sort(ALL(v));
	
	if(v.size() > 0)
	{
		cout << v[0] << endl;
	}
	else
	{
		cout << "UNRESTORABLE" << endl;
	}
		
		
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<list>
using namespace std;
#define i64 long long 

int main(){
    int N;
    cin >> N;
    list<int> B;
    for(int i=0;i<N;i++){
        int b;
        cin >> b;
        B.emplace_back(b);
    }

    list<int> ans;

    while(!B.empty()){
        int idx = B.size();
        for(auto b = B.rbegin(); b != B.rend(); b++){
            if(*b == idx){
                ans.emplace_front(*b);
                B.erase(next(B.begin(),idx-1));
                break;
            }
            idx--;
        }
        if(idx == 0) break;
    }

    if(ans.size() != N) cout << -1 << endl;
    else{
        for(auto b : ans) cout << b << endl;
    }

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import collections


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    As = LI()
    As.sort()
    As.reverse()
    As = collections.deque(As)
    ans = []
    tmp = As.popleft()
    ans.append(tmp)

    for i in range(len(As)):
        tmp = As.popleft()
        ans.extend([tmp, tmp])

    print(sum(ans[:N-1]))
    # print(ans)


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()


Measured memory_bytes: 124352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

signed main(void) {
    int l,n;
    cin >> l >> n;
    int t = 0;
    rep(i,n){
        int x,w;
        cin >> x >> w;
        t += x*w;
    }
    t *= -1;
    if(t > 0){
        cout << t << endl;
        rep(i,t)cout << "1 1" << endl;
    }else{
        cout << abs(t) << endl;
        rep(i,abs(t))cout << "-1 1" << endl;
    }
}



Measured memory_bytes: 3104
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		//int[] a = new int[n];
		boolean flg = true;
		for(int i=0; i<n; i++){
			//a[i] = sc.nextInt();
			int a = sc.nextInt();
			if(a%2 == 0){
				if(!(a%3==0 || a%5==0)){
					flg = false;
					
				}
			}
		}
		System.out.println(flg ? "APPROVED" : "DENIED");
	}
}


Measured memory_bytes: 36040
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	string s;
	cin >> N;

	bool has_yellow = false;
	for (int i = 0; i < N; i++) {
		cin >> s;
		if (s[0] == 'Y') has_yellow = true;
	}

	cout << (has_yellow ? "Four" : "Three") << endl;

	return 0;
}

Measured memory_bytes: 256
S=input()
def solve(query):
    while 1:
        if not query:
            print("YES")
            break

        for frag in ("erase","eraser","dream","dreamer"):
            if query.endswith(frag):
                query=query[:-len(frag)]
                break
        else:
            print("NO")
            break

solve(S)

Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll test,i,j,n;
    cin>>n;
    j=0;
    for(i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)continue;
        else j+=i;
    }
    cout<<j<<endl;
    return 0;
}


Measured memory_bytes: 3620
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.math.BigInteger;
 
public class Main implements Runnable {
	
	static int mod = 1000000007;
	
    public static void main(String[] args) {
    	new Thread(null, new Main(), "", 1024 * 1024 * 1024).start();
    }
    
    public void run() {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] c = sc.nextIntArray(m);
        
        System.out.println(minCoin(c,n));

    }
    
	//ちょうどm円払うためのコインの最小枚数（不可ならMAXVALUE-1）
	static int minCoin(int[] c, int m){
		int[] dp = new int[m+1];
		Arrays.fill(dp,Integer.MAX_VALUE-1);
		dp[0] = 0;
		
		for(int i=1;i<=m;i++){
			for(int v=0;v<c.length;v++){
				if(i-c[v]>=0){
					dp[i] = Math.min(dp[i],dp[i-c[v]]+1);
				}
			}
		}
		
		return dp[m];
	}
	
}



class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}
	public int[] nextIntArray(int n){
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = nextInt();
		}
		return a;
	}
	public Integer[] nextIntegerArray(int n){
		Integer[] a = new Integer[n];
		for(int i=0;i<n;i++){
			a[i] = nextInt();
		}
		return a;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 25284
/*
                " اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "
*/

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define intial(s1,s2,x,dp) f(int i = 0; i < s1; i++)f(int j = 0; j < s2; j++)dp[i][j] = x;
using namespace std;
#define BI  acos(-1)
#define all(a) a.begin(), a.end()
#define loop1(n) f(int i=0;i<n;i++)
#define loop2(n) f(int j=0;j<n;j++)
#define oo 1e9;
void Open()
{
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
}
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void madesetprobblem()
{
    //$ $
    //less than or equal => $ 1 \leq 100 $
    //  $(1 \le A,B \le 10^5 )$
    // a[i] => $a_i$
    // a[i][j] => $a_{i,j}$
    // double qoutes ''yext''
    /*
        image
        \begine{center}
        \includegraphics{image.jpg}
        \end{center}
    */
    /*
        list
        \begin{itemize}
            \item first one
            \item second one
        \end{itemize}
    */
}
ll n,k,*a;
ll dp[3001][3001][2];
ll ans(int i=0,int j=n-1,int p=0)
{
    //  cout<<x<<' ';
    if(i==j)
        return (p?-a[i]:a[i]);
    ll& ret=dp[i][j][p];
    if(~ret)
        return ret;
    if(!p)
    {
        return ret=max(ans(i+1,j,!p)+a[i],ans(i,j-1,!p)+a[j]);
    }
    else
    {
        return ret=min(ans(i+1,j,!p)-a[i],ans(i,j-1,!p)-a[j]);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    a=new ll[n];
    loop1(n)cin>>a[i];
    cout<<ans();
}


Measured memory_bytes: 144624
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$INF = 500;

$h = (int)$input[0];
$w = (int)$input[1];

$v_list = [];
for ($i=1; $i <= $h; $i++) { 
	$input = trim(fgets(STDIN));
	for ($j=1; $j <= $w ; $j++) { 
		if ($input[$j-1] == '.') {
			$v_list[] = [$i, $j];
		}
	}
}
// 距離を初期化
$v_length = count($v_list);
$dist = [];
for ($i=0; $i < $v_length; $i++) { 
	for ($j=0; $j < $v_length; $j++) { 
		if (isset($dist[$j][$i])) {
			$dist[$i][$j] = $dist[$j][$i];
			continue;
		}
		$d = $INF;
		if ($i == $j) {
			$d = 0;
		}else{
			$v1 = $v_list[$i];
			$v2 = $v_list[$j];
			if ($v1[0] === $v2[0] || $v1[1] === $v2[1]) {
				switch (abs($v1[1] - $v2[1]) + abs($v1[0] - $v2[0])) {
					case 0:
						$d = 0;
						break;
					case 1:
						$d = 1;
						break;
				}
			}
		}
		$dist[$i][$j] = $d;
	}
}
// ワーシャルフロイド
for ($i=0; $i < $v_length; $i++) { 
	for ($j=0; $j < $v_length; $j++) { 
		if ($i == $j || $dist[$i][$j] == $INF) {
			continue;
		}
		// 無向グラフなので
		for ($k=$j+1; $k < $v_length; $k++) { 
			if ($dist[$j][$k] > $dist[$j][$i] + $dist[$i][$k]) {
				$dist[$j][$k] = $dist[$j][$i] + $dist[$i][$k];
				$dist[$k][$j] = $dist[$j][$i] + $dist[$i][$k];
			}
		}
	}
}
$max = 0;
for ($i=0; $i < $v_length; $i++) { 
	for ($j=0; $j < $v_length; $j++) { 
		if ($dist[$i][$j] < $INF) {
			$max = max($max, $dist[$i][$j]);
		}
	}
}
echo $max;




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

int main(){
  vector<vector<int>> bingo(3, vector<int>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> bingo[i][j];
    }
  }
  
  int n; cin >> n;
  
  int check;
  for(int i=0; i<n; i++){
    cin >> check;
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        if(bingo[i][j]==check)bingo[i][j]=0;
      }
    }
  }
  
  vector<bool> tate(3,true),yoko(3,true);
  
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(bingo[i][j]!=0){
        yoko[i] = false;
        tate[j] = false;
      }
    }
  }
  
  for(int i=0; i<3; i++){
    if(tate[i]){
      cout << "Yes" << endl;
      return 0;
    }
    if(yoko[i]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  if(bingo[0][0]==0 && bingo[1][1]==0 && bingo[2][2]==0){
    cout << "Yes" << endl;
      return 0;
  }
  
  if(bingo[0][2]==0 && bingo[1][1]==0 && bingo[2][0]==0){
    cout << "Yes" << endl;
      return 0;
  }
  
  cout << "No" << endl;
  
  return 0;
}

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

using namespace std;
#define DIM 100007
#define INF 100007
#define MAXN 1023
#define LG 18
typedef int ll;
typedef long double ld;
typedef ll arr[DIM];
typedef vector<ll> vec;
typedef vector<ll> graph[DIM];
typedef pair<ll, ll> pll;

struct pp {
	ll a, b;
	bool operator <(const pp& V)const {
		if (a == V.a)return b < V.b;
		return a < V.a;
	}
	bool operator ==(const pp& V)const {
		if (a == V.a && b == V.b)return 1;
		return 0;
	}
};


ll n;
arr A,D;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> A[i];
	for (int i = n; i >= 1; i--) {
		if (i == n)D[i] = 0;
		else if (i == n - 1)D[i] = abs(A[i] - A[i + 1]);
		else D[i] = min(D[i + 1] + abs(A[i + 1] - A[i]), D[i + 2] + abs(A[i + 2] - A[i]));

	}
	cout << D[1] << endl;
}
// 11
// 

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

int main(){
	int N;
	int A, B;
	

	cin >> N;

	bool is = false;
	for (int i = 1; i < 10; i++){
		for (int j = 1; j < 10; j++){
			if (N == i*j){
				is = true;
			}
		}
	}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

//小数出力
double print_double(double d){printf("%.8f", d);}

long long m = 1e9+7, mod = 1e9+7;
//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

//約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


int main() {
  ll N,K,ans=0;
  cin >> N >> K;
  Vl h(N);
  rep(i,N){
    cin >> h[i];
  }
  if (N<=K) ans = 0;
  else {
  SORT(h);
  rep(i,N-K) ans += h[i] ;}
  cout << ans;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    int N = S.length();

    long ans = 0;
    int black = 0;

    for (int i = 0; i < N; i++) {
      char c = S.charAt(i);
      if (c == 'B') {
        black += 1;
      } else {
        ans += black;
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 27924
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      int W = Integer.valueOf(input.next());
      int H = Integer.valueOf(input.next());
      int x = Integer.valueOf(input.next());
      int y = Integer.valueOf(input.next());
      int r = Integer.valueOf(input.next());

      if (x + r > W || x - r < 0) {
        System.out.println("No");
      } else if (y + r > H || y - r < 0) {
        System.out.println("No");
      } else {
        System.out.println("Yes");
      }
  }
}


Measured memory_bytes: 26160