akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool compare_by_a(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    else return a.second<b.second;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
   ll n,m;
      cin>>n>>m;
      vector<ll> num(n);
      vector<pair<ll,ll>> a(m);
      rep(i,m){
          cin>>a[i].first>>a[i].second;
          if(n>=2 && a[i].first==1 && a[i].second==0){
              cout<<"-1"<<endl;
              return 0;
          }
      }
    
      rep(i,m) for(ll j=0;j<i;j++){
          if(a[i].first==a[j].first){
              if(a[i].second!=a[j].second){
                  cout<<"-1"<<endl;
                  return 0;
          }
        }
      }
    sort(ALL(a));
    rep(i,a.size()) if(a[i].first!=a[i+1].first) num[a[i].first-1]=a[i].second;
    
    if(n>=2 && num[0]==0) num[0]=1;
    rep(i,n) cout<<num[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

vector<int> G[51];
bool onTheWay[51][51][51][51];
vector<pii> stk;
void dfs(int u, int p, bool on[51][51][51]) {
    each(e, stk) {
        on[u][e.first][e.second] = true;
        on[u][e.second][e.first] = true;
    }
    each(v, G[u]) {
        if (v != p) {
            stk.emplace_back(u, v);
            dfs(v, u, on);
            stk.pop_back();
        }
    }
}

void solve() {
    int N;
    cin >> N;
    vi A(N - 1), B(N - 1);
    rep(i, N - 1) {
        cin >> A[i] >> B[i];
        --A[i]; --B[i];
        G[A[i]].emplace_back(B[i]);
        G[B[i]].emplace_back(A[i]);
    }
    rep(i, N) {
        dfs(i, -1, onTheWay[i]);
    }

    int M;
    cin >> M;
    vi U(M), V(M);
    rep(i, M) {
        cin >> U[i] >> V[i];
        --U[i]; --V[i];
    }

    vll dp(1 << M);
    dp[0] = 1;
    rep(i, N - 1) {
        int fulfilled = 0;
        rep(j, M) {
            if (onTheWay[U[j]][V[j]][A[i]][B[i]]) {
                fulfilled |= 1 << j;
            }
        }
        for (int S = (1 << M) - 1; S >= 0; --S) {
            dp[S | fulfilled] += dp[S];
        }
    }
    cout << dp.back() << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 14848
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      int MOD = 1000000007;
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] dp = new int[n+1];
      int m = sc.nextInt();
      for(int i = 0; i < m; i++)
        dp[sc.nextInt()] = -1;
      dp[0] = 1;
      if(dp[1] != -1)
        dp[1] = 1;
      for(int i = 2; i < dp.length; i++) {
        if(dp[i] == -1) continue;
        int prevPrev = dp[i-2] == -1 ? 0 : dp[i-2];
        int prev = dp[i-1] == -1 ? 0 : dp[i-1];
        dp[i] = (prevPrev + prev) % MOD;
      }

      System.out.println(dp[n]);
  }
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

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

void solve(long long A, long long B){
    cout << A * B << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == 5 && b == 5 && c == 7) || (a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
h,w = map(int,input().split())
s = []
for i in range(h):
    s.append(list(input()))

for i in range(h):
    for j in range(w):
        if(s[i][j]=="#"):
            if not ((s[i-1][j]=="#" if i>0 else 0) or (s[i][j-1]=="#" if j>0 else 0) or (s[i+1][j]=="#" if i<(h-1) else 0) or (s[i][j+1]=="#" if j<(w-1) else 0)):
                print("No")
                sys.exit(0)
print("Yes")


Measured memory_bytes: 3064
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        //  a1 * a2 + a1 * a3 + a1 * a4
        //+ a2 * a3 + a2 * a4
        //+ a3 * a4

        //  a1(a2 + a3 + a4)
        //+ a2(a3 + a4)
        //+ a3(a4)

        long sum = aa.Sum();

        long y = 0;

        for(int i=0; i<n; i++) {
            sum -= aa[i];
            y += (aa[i] * (sum % Mod)) % Mod;
            y %= Mod;
        }

        return y;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 46784
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
  int n,ans=0,t=0;
  scanf("%d",&n);
  for (int i=1;i<=n;i++)
  {
  	if (i%2==0) continue;
    int now=trunc(sqrt(i));
    ans=0;
    if (i==now*now) ans--;
    for (int j=1;j<=now;j++)
    if (i%j==0) ans+=2;
    if (ans==8) t++;
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#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 vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


int main() {
	ll N;
	ll a[100];
	ll sum = 0;
	ll ans;
	ll sum1 = 0;
	ll sum2 = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		sum += a[i];
	}
	sum /= N;
	for (int i = 0; i < N; i++) {
		sum1 += (a[i] - sum) * (a[i] - sum);
	}
	for (int i = 0; i < N; i++) {
		sum2 += (a[i] - sum-1) * (a[i] - sum-1);
	}
	if (sum2 >= sum1) {
		cout << sum1 << endl;
	}
	else cout << sum2 << endl;
	cin >> N;

	return 0;
}

Measured memory_bytes: 256
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from itertools import groupby
import sys
def main(s, x, y):
    g = [x, y]
    o = [[], []]

    direction = count = 0
    first = True
    for c in s:
        if c == 'T':
            if first:
                g[0] -= count
                first = False
            elif count > 0:
                o[direction].append(count)
            count = 0
            direction ^= 1
        else:
            count += 1
    if first:
        g[0] -= count
    elif count > 0:
        o[direction].append(count)

    for d in range(2):
        l = o[d]
        M = sum(l)
        M2 = M * 2
        if abs(g[d]) > M:
            print('No')
            return
        pre = [False] * (M2 + 1)
        pre[M] = True
        for i, v in enumerate(l):
            dp = [False] * (M2 + 1)
            for a in range(M2 + 1):
                if pre[a] == False: continue
                if a >= v:
                    dp[a - v] = True
                if a + v <= M2:
                    dp[a + v] = True
            pre = dp
        if pre[g[d] + M] == False:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    input = sys.stdin.readline
    s = input().rstrip()
    x, y = map(int, input().split())
    main(s, x, y)


Measured memory_bytes: 74800
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

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

  for(int i=0; i<S.size(); i++)
    cout << 'x' ;
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e18)

signed main(){
	int N, i;
	scanf("%lld", &N);
	vector<int> A(N + 2, 0);
	for(i = 2; i < N + 2; i++){
		scanf("%lld", &A[i]);
	}
	vector<int> odd_sum(N / 2 + 1, 0), sub_sum(N / 2 + 1, 0), sub_sum_max(N / 2 + 1, 0);
	for(i = 1; i <= N / 2; i++){
		odd_sum[i] = odd_sum[i - 1] + A[2 * i + 1];
		sub_sum[i] = sub_sum[i - 1] + A[2 * i] - A[2 * i + 1];
		sub_sum_max[i] = max(sub_sum_max[i - 1], sub_sum[i]);
	}
	int ans = -inf;
	if(N % 2 == 0){
		ans = odd_sum[N / 2] + sub_sum_max[N / 2];
	}
	else{
		int now = 0;
		for(i = N / 2; i >= 0; i--){
			ans = max(ans, odd_sum[i] + sub_sum_max[i] + now);
			now += A[2 * i + 2];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7240
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int main()
{
    long long int n, m = 10000000000000000L;
    cin >> n;
    for (int i = 1; i <= 5; i++)
    {
        long long int tmp;
        cin >> tmp;
        m = min(m, tmp);
    }

    cout << 4 + (n + (m - 1)) / m;
}

Measured memory_bytes: 256
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


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

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, m = LI()
    a = list(map(lambda x: -x, LI()))
    heapify(a)
    for i in range(m):
        highest = -heappop(a)
        heappush(a, -(highest // 2))
    print(-sum(a))


if __name__ == "__main__":
    main()


Measured memory_bytes: 36360
A, B = map(int, input().split())

if (A < B):
    i = 0
    while True:
        i+=1
        print(A, end="")
        if (B == i):
            break

else:
    i = 0
    while True:
        i += 1
        print(B, end="")
        if (A == i):
            break


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> v(2, vector<int>(n + 2));
  for (int i = 0; i < n; i++) {
    v[0][i + 1] = s[i] == '#';
    v[1][i + 1] = s[i] == '.';
  }
  for (int i = 0; i < n - 1; i++) {
    v[0][i + 2] += v[0][i + 1];
    v[1][n - i - 1] += v[1][n - i];
  }
  int r = n;
  for (int i = 0; i < n + 1; i++) {
    r = min(r, v[0][i] + v[1][i + 1]);
  }
  cout << r << endl;
}


Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll A, B, C, D, E, F, G, H, X, Y, Z, P, Q, M, N, T, R, K, W, L, ANS;
string S, S1, S2;
ll NXT[61][MAX_N];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    rep(i, N) {
        cin >> X;
        NXT[0][i] = X - 1;
    }

    rep(i, 60) {
        rep(j, N) { NXT[i + 1][j] = NXT[i][NXT[i][j]]; }
    }

    ANS = 0;

    while(K) {
        if(K % 2)
            ANS = NXT[A][ANS];
        A++;
        K /= 2;
        // cout << K << " " << ANS << endl;
    }

    cout << ANS + 1 << endl;
}

Measured memory_bytes: 99204
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

int main() {
	int n,a[100];
	cin >> n;
	for(int i=0;i<n;i++)	cin >> a[i];

	for(int i=n-1;i>0;i=i-1)	cout << a[i] << " ";
	cout << a[0] << endl;
	return 0;
}



Measured memory_bytes: 3080
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int array[]=new int[n];
        for(int i=0;i<n;i++){
          array[i]=sc.nextInt();
        }
        for(int i=n-1;0<i;i--) System.out.print(array[i]+" ");
        System.out.println(array[0]);  
        sc.close();
    }
}


Measured memory_bytes: 26272
#include <stdio.h>
int main(void){
    int H,W,i,j;
    while(1){
        scanf("%d",&H);
        scanf("%d",&W);
        if(H==0&&W==0)break;
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++){
                if(i>1&&i<H&&j<W&&j>1)
                printf(".");
                else
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2044
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
    if A[i] != B[i] and B[i] != C[i] and C[i] != A[i]:
        ans += 2
    elif A[i] != B[i] or B[i] != C[i]:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import math
sum=0
k=int(input())
for a in range(1,k+1):
  for b in range(a,k+1):
    for c in range(b,k+1):
      g=math.gcd(a,b)
      h=math.gcd(g,c)
      if a!=b!=c:
        sum+=(h*6)
      elif a==b==c:
        sum+=h
      else:
        sum+=(h*3)
print(sum)

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

int main(void) {
  int n, ans = 0;
  scanf("%d", &n);
  vector<int> v(n), c(n);

  for ( int i = 0; i < n; i++ ) cin >> v[i];
  for ( int i = 0; i < n; i++ ) cin >> c[i];
  
  for ( int i = 0; i < n; i++ ) {
    if ( v[i] > c[i] ) ans += v[i] - c[i];
  }

  printf("%d", ans);
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> ds(n, 0);
  for (int i=0;i<n;i++) {
    cin >> ds[i];
  }

  sort(ds.begin(), ds.end());

  cout << ds[ds.size() / 2] - ds[(ds.size() / 2) - 1] << endl;

}


Measured memory_bytes: 640
fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let n: u64 = rd.get();
    let x: usize = rd.get();
    let m: usize = rd.get();

    let b = 34;
    let mut nxt = vec![vec![0; m]; b];
    // dp[i][j]: x = j から始めたときの a[1] + a[2] + ... + a[2^i]
    let mut dp = vec![vec![0; m]; b];
    for y in 0..m {
        nxt[0][y] = (y * y) % m;
        dp[0][y] = y;
    }
    for i in 1..b {
        for j in 0..m {
            nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
            dp[i][j] = dp[i - 1][j] + dp[i - 1][nxt[i - 1][j]];
        }
    }
    let mut y = x;
    let mut ans = 0;
    for i in 0..b {
        if (n >> i & 1) == 1 {
            ans += dp[i][y];
            y = nxt[i][y];
        }
    }
    println!("{}", ans);
}

pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

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

typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

int main(){
  int a,b;
  cin >> a >> b;
  
  cout << max(a-2*b,0) << endl;
}

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

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  
  int a, b, c;
  if(A+B>C*2)c=min(X, Y)*2;
  else c=0;
  
  if(A>C*2&&X>Y)c=X*2;
  if(B>C*2&&X<Y)c=Y*2;
  
  a=X-min(X, c/2);
  b=Y-min(Y, c/2);
  
  cout << A*a +B*b+C*c << endl;
  
}

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    int N, X;
    std::cin >> N >> X;

    std::vector<int> m(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> m[i];
    }
    std::sort(m.begin(), m.end());

    int ret = N;
    int remaining = X - std::accumulate(m.cbegin(), m.cend(), 0);
    for (int i = 0; i < N; ++i) {
        const int num = remaining / m[i];
        if (num == 0) {
            break;
        } else {
            ret += num;
            remaining -= num * m[i];
        }
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int c[3][3];
    bool exist=true;
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            cin >> c[i][j];
        }
    }
    
       int a[3]={0};
       int b[3]={0};
     for(int i=0;i<3;++i){
        b[i]= c[0][i];
    }
    for(int i=0;i<3;++i){
        a[i]= c[i][0]-b[0];
    }

    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            if(c[i][j]!=a[i]+b[j]){
                exist=false;
                break;
                break;
            }
        }
    }

    if(exist==true){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

        
    }

Measured memory_bytes: 256
"""
def factorial(x):
    if x == 0:
        return 1
    return x * factorial(x - 1)

RuntimeError: maximum recursion depth exceeded
"""

from math import factorial
n, m = map(int, input().split())

dif = abs(n - m)
if dif >= 2:
    ans = 0
elif dif == 1:
    ans = factorial(n) * factorial(m) % (10 ** 9 + 7)
else:
    ans = factorial(n) * factorial(m) * 2 % (10 ** 9 + 7)

print(ans)

Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll dp[105][200005]={0};
ll solve(ll i,ll n,ll w[200005],ll v[200005],ll s)
{

  if(i==n-1)
  {
    if(w[i]<=s)
    return dp[i][s]=v[i];
    else
     return dp[i][s]=0;
  }
  if(dp[i][s]!=-1)
    return dp[i][s];
  if(s==0)
    return dp[i][s]=0;
  if(w[i]<=s)
    dp[i][s]=v[i]+solve(i+1,n,w,v,s-w[i]);
  return dp[i][s]=max(dp[i][s],solve(i+1,n,w,v,s));
  
}
int main()
{
  for(int i=0;i<105;i++)
    for(int j=0;j<200005;j++)
      dp[i][j]=-1;
  ll n,w[200005],wei,v[200005];
  cin>>n>>wei;
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>v[i];
  }
  ll ans=solve(0,n,w,v,wei);
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 167680
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a,b,c,cc,h;
    std::cin >> a>>b>>cc;
    cc=cc*M_PI/180;
    c=sqrt(a*a+b*b-2*a*b*cos(cc));
    h=b*sin(cc);
    //std::cout << a*h*0.5<<' '<<a+b+c<<' '<<h << std::endl;
    std::cout <<keta(10)<< a*h*0.5 << std::endl;
    std::cout <<keta(10)<< a+b+c << std::endl;
    std::cout <<keta(10)<< h << std::endl;
    
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int d, g;
    cin >> d >> g;
    vint p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];

    ll ans2 = INF;
    rep(bit, (1 << d))
    {
        ll sum = 0;
        ll ans = 0;
        rep(i, d)
        {
            if (bit & (1 << i))
            {
                sum += (i + 1) * 100 * p[i] + c[i];
                ans += p[i];
            }
        }

        if (sum >= g)
        {
            ans2 = min(ans2, ans);
            continue;
        }

        for (int i = d - 1; i >= 0; --i)
        {
            if (bit & (1 << i))
            {
                continue;
            }
            else
            {
                rep(j, p[i])
                {
                    sum += (i + 1) * 100;
                    ++ans;
                    if (sum >= g)
                        break;
                }
            }
            if (sum >= g)
            {
                ans2 = min(ans2, ans);
                break;
            }
        }
    }
    cout << ans2 << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] a) {
		BufferedReader br;
		br=new BufferedReader(new InputStreamReader(System.in));
		int[] mountains=new int[10];
        for(int i=0;i<10;i++){
            try {
                String str=br.readLine();
                mountains[i]=Integer.parseInt(str);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
		for(int h=mountains.length-1;h>0;h--){
			for(int i=1;i<=h;i++){
				if(mountains[i]>mountains[i-1]){
					int tmp=mountains[i];
					mountains[i]= mountains[i-1];
					mountains[i-1]=tmp;
				}
			}
		}
		for(int i=0;i<3;i++){
			System.out.println(mountains[i]);
		}
	}
}

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

using namespace std;
#define ll long long 
#define db long double
#define f(i,l,u) for(ll i=l;i<u;i++)
int main() {
ll n;
cin>>n;
ll a[n];

ll val=0;

f(i,0,n)
{
        cin>>a[i];
        val^=a[i];
}
ll ans[n];
f(i,0,n)
{
    ans[i]=val^a[i];
}

f(i,0,n)
cout<<ans[i]<<" ";


   return 0;
}

Measured memory_bytes: 6708
#include <cstdio>

int main(){
    int N;
    scanf("%d",&N);
    char CN[3];
    CN[0] = 'A';
    CN[1] = 'B';
    CN[2] = 'C' + (N + N / 1000) / 1000;
    printf("%c%c%c\n",CN[0],CN[1],CN[2]);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
using P = pair<ll, ll>;
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T a) { cin >> a; }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(V<T> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T> void scan(V<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
template <class T> V<T> press(V<T> &x){ 
    V<T> res = x;
    sort(all(res));
    res.erase(unique(all(res)), res.end());
    REP(i, SZ(x)){
        x[i] = lower_bound(all(res), x[i]) - res.begin();
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void First(bool b = true) {cout << (b ? "First" : "Second") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    STR(s);
    First(SZ(s) % 2 ^ s[0] == s[SZ(s) - 1]);
}

Measured memory_bytes: 3780
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;
const int N=2e5 + 5;
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    ll ans=1;
    ll ar[n];
    forn(i,n){
        cin>>ar[i];
        if(ar[i]==0){cout<<0;return 0;}
    }
    ll che=1000000000000000000;
    forn(i,n){
        //ans*=ar[i];
        //cout<<ans<<endl;
        if(ar[i]>che/ans){cout<<-1;return 0;}
        ans*=ar[i];
    }
    //if(ans>che)ans=-1;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 4444
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a[60],b[60];
	int n;
	int flag = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			continue;
		}
		else {
			flag++;
		}
	}
	if (flag <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N,K;
vll clu;
ll dp[110][50010];
ll sum[110][500010];
void make_cluster(){
  rep1(i,N){
    ll k=N/i;
    ll j=N/k;
    clu.pb(j-i+1);
    i+=j-i;
  }
}
void solve(){
  make_cluster();
  ll m=clu.size();
  fill(dp,0);
  fill(sum,0);
  rep(i,m+1){
    dp[0][i]=clu[i];
    sum[0][i+1]=(sum[0][i]+dp[0][i])%MOD;
  }
  rep(i,K-1){
    rep(j,m){
      dp[i+1][j]=(sum[i][m-j]*clu[j])%MOD;
      sum[i+1][j+1]=(sum[i+1][j]+dp[i+1][j])%MOD;
    }
  }
  prin(sum[K-1][m]);
}
int main(){
  cin>>N>>K;
  solve();
  return 0;
}


Measured memory_bytes: 473592
import sys
import math
from  collections import defaultdict

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')


def solve(test):
	n, k = map(int, input().split())
	a = list(map(int, input().split()))


	dp = [None for i in range(k + 1)]
	dp[0] = False
	for j in range(1, k + 1):
		dp[j] = False
		for i in range(n):
			if j >= a[i]:
				dp[j] = not dp[j - a[i]]
				if dp[j]:
					break

	print('First' if dp[k] else 'Second')

if __name__ == "__main__":
	test_cases = 1
	for t in range(1, test_cases + 1):
		solve(t)


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) {
    cin >> d[i];
  }
  int ans= 100100100;
  for (int i = 1; i < 101; i++) {
    int cost = 0;
    rep(j,n) {
      cost += (d[j]-i)*(d[j]-i);
    }
    ans = min(ans,cost);
  } 
  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 256
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n, k;
    long long h, ans=0;
    vector<long long> H;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> h;
        H.emplace_back(h);
    }

    sort(H.begin(), H.end(),greater<long long>());

    for (int i = k; i < n; i++) {
        ans += H[i];
       
    }
    
    cout << ans << endl;
    
}



Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <list>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdlib>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define INF 1000000007
using namespace std;
typedef long long LL;
//typedef pair<int,int> P;
//typedef priority_queue<P, vector<P>, greater<P> > minPQ;
struct edge {int to,cost;};
//const int SIZE = 1<<18;

int N,M;
int T[101];
int P[101],X[101];
int main() {
	cin >> N;
	REP(i,N) cin >> T[i];
	cin >> M;
	REP(i,M) cin >> P[i] >> X[i];
	int sum = 0;
	REP(i,N) sum += T[i];
	REP(i,M) cout << sum+(X[i]-T[P[i]-1]) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
vector<ll> a;
// index が条件を満たすかどうか
bool isOK(int index, int key)
{
    if (a[index] >= key)
        return true;
    else
        return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key)
{
    int ng = -1;            //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}
int main()
{
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    rep(i, n - 1)
    {
        if (s[i] == 'A' && s[i + 1] == 'C')
        {
            //この先頭のindexをどこかに保管する。
            //ループする時にrより大きくてlより小さいindexは何個あるのかをみる。
            a.push_back(i); //これは先頭なのでi+1も含むのが普通
        }
    }
    for (int i = 0; i < q; i++)
    {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        //愚直にループを回すと10^5*10^5 前処理をする
        ll w = binary_search(l);     //これだと
        ll v = binary_search(r + 1); //
                                     //v-１のインデックスの数字+1とrの大小関係
        if (v == 0)
        {
            cout << 0 << endl;
        }
        else
        {
            if (a[v - 1] + 1 > r)
            {
                cout << v - w - 1 << endl;
            }
            else
            {
                cout << v - w << endl;
            }
        }
    }
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

int n, dp[100005][3] = {0}, abc[3];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
            cin >> abc[j];
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
                if(j != k)
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[j]);
    }
    int ans = 0;
    for(int i = 0; i < 3; i++)
        ans = max(ans, dp[n][i]);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
import sys
import numpy as np
P = 998244353


def main(N, S, AS):
    DP = np.zeros((S + 1, N + 1), dtype=np.int64)
    DP[0, 0] = 1
    # print(DP)

    for i in range(N):
        for j in range(S + 1):
            v = DP[j, i] * 2
            if AS[i] <= j:
                v += DP[j - AS[i], i]
            DP[j, i + 1] = v % P

    # print(DP)
    print(DP[S, N])


if sys.argv[-1] == 'ONLINE_JUDGE':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'void(i8,i8,i8[:])')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
    exit()
else:
    # read parameter
    N, S = map(int, input().split())
    AS = np.array(list(map(int, input().split())))
    from my_module import main
    main(N, S, AS)


Measured memory_bytes: 97432
//Bismillahir rahmanir rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int arr[100005];
int dp[100005];
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
    for(int i=1;i<=n;i++) dp[i]=1e9;
    dp[1]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<=n){
                dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i]-arr[i+j]));
            }
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int a[105];
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<n;i++)
    {
        a[i]+=a[i-1];
    }
    int ans=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=x)
            ans++;
    }
    printf("%d",ans);
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif N%3!=0:
    print("No")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    xor=0
    for a in set(A):
        if A.count(a)==N/3:
            xor^=a
        else:
            print("No")
            exit()
    if xor==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 20536
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + 50 * k == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    long long int t,n,a,b,i,j,k,l,sum=0;
   cin>>n;
   for(i=1;i<=n;i++)
   {
       if(i%3==0||i%5==0)
       {
           continue;
       }
       else
       {
           sum=sum+i;
       }
   }
   cout<<sum<<endl;
    return 0;
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
void Yes(){
  cout << "Yes" << endl;
}
void YES(){
  cout << "YES" << endl;
}
void No(){
  cout << "No" << endl;
}
void NO(){
  cout << "NO" << endl;
}
int main(){
  string A,B,C;
  cin >> A >> B >> C;
  
  if(A.at(A.size()-1) == B.at(0) && B.at(B.size()-1) == C.at(0)) YES();
  else NO();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     siii(a,b,c)       scanf("%d%d%d",&a,&b,&c)
#define     si(a)             scanf("%d",&a)
#define     sii(a,b)          scanf("%d%d",&a,&b)
#define     sl(a)             scanf("%lld",&a);
#define     sll(a,b)          scanf("%lld%lld",&a,&b);
#define     slll(a,b,c)       scanf("%lld%lld%lld",&a,&b,&c);
#define     sd(a)             scanf("%lf",&a);
#define     sdd(a,b)          scanf("%lf%lf",&a,&b);
#define     pb(a)             push_back(a)
#define     deb(a)            printf("### %d ###\n",a)
#define     mp                make_pair
#define     pf                printf
#define     fl(a, b, c)       for(int a= b ;a<c;a++)
#define     mx                100000 //10^5
#define     fread             freopen("input.txt","r",stdin)
#define     CLR(a,b)          memset(a,b,sizeof(a))
#define     ll                long long
#define     D(x)              cout<<#x" = "<<x<<endl;
#define     sz                10000
#define     bl                printf("\n")
#define     spc               printf(" ")


int arr[mx+5], rgcd[mx+5], lgcd[mx+5],n,ans= 0;

int main()
{
    si(n);
    fl(i,0,n) si(arr[i]);
    lgcd[0] = 0;
    rgcd[n+1] = 0;

    fl(i,1,n+1){
        lgcd[i] = __gcd(lgcd[i-1],arr[i-1]);
        //cout<<lgcd[i];spc;
    }
    for(int i = n ; i>0 ; i--)
    {
        rgcd[i] = __gcd(rgcd[i+1],arr[i-1]);
        //cout<<rgcd[i];spc;
    }
    fl(i,1,n+1)
    {
        ans = max(ans,__gcd(lgcd[i-1],rgcd[i+1]));
    }
    cout<<ans<<endl;
    return 0;
}
































/*

int arr[mx+5],prime[mx+5],num[mx+5],n;

void seive(int num)
{
    arr[0] = arr[1] = -1;
    int sq = sqrt(num);
    for(int i = 2 ; i<= sq ; i++)
    {
        if(!arr[i]){
            for(int j = i*i ;j<num ; j+=i) arr[j] =-1;
        }
    }
    int j = 0;
    fl(i,0,num) if(arr[i]>=0) prime[j++] = i;

    //fl(i,0,j) D(prime[i]);

}
map<int, int>m ;
map<int, int> :: iterator itr;
int main(){
    seive(100000);
    si(n);
    fl(i,0,n){
        int x,j = 0;
        si(x);
        num[i] = x;
        int sq = sqrt(num[i]);
        fl(i,0,sq){
            if(prime[i]>sq) break;
            if(x%prime[i] == 0){
                m[prime[i]]++;
                while(x%prime[i]==0 && x>1){
                    x/=prime[i];
                }
            }
        }
       // D(x);
        m[x]++;
    }
    if(n == 2){
        cout<<max(num[0],num[1])<<endl;
        return 0;
    }
    sort(num,num+n);
    int cnt = 1, res = 1;
    fl(i,1,n){
        if(num[i-1] == num[i] ){
                cnt++;
        }
        else cnt = 1;
        res = max(cnt,res);
        //D(res);
    }
    if(res>=n-1){
        cout<<num[n/2]<<endl;
        return 0;
    }

    int ans = 1;
    for (itr = m.begin(); itr != m.end(); ++itr) {
        if(itr->second>=n-1) {
               // D(ans);
                ans*= itr->first;
                //D(ans);
        }
    }
    cout<<ans<<endl;

    return 0;

}\*/


Measured memory_bytes: 1408
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).

get_number(Number) :-
  get_string(String),
  number_string(Number, String).

fb(0, 0).
fb(N, S) :-
  N1 is N - 1,
  fb(N1, S1),
  ((N mod 3 =:= 0; N mod 5 =:= 0) ->
    S is S1;
    S is S1 + N).

main :-
  get_number(N),
  fb(N, S),
  write(S).

Measured memory_bytes: 117660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	string s;
	cin >> s;

	int ans = 0, cur = 0;
	for(auto &c : s){
		if(c == 'R')
			cur++;
		else{
			ans = max(ans, cur);
			cur = 0;
		}
	}

	ans = max(ans, cur);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3600
// AOJ 1030 Cubes Without Holes
// 2018.2.3 bal4u@uu

#include <stdio.h>

#include <stdio.h>
#include <string.h>
 
char buf[15], *p;

int in()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

char f[500][500][500];
int ans;
 
void cnt(int x, int y, int z) { if (!f[x][y][z]) f[x][y][z] = 1, ans++; }
 
int main()
{
	int n, h, a, b, x, y, z;
	char *c;

	while (fgets(p=buf, 15, stdin) && *p != '0') {
		n = in(), h = in();
		ans = 0;
		memset(f, 0, sizeof(f));
		while (h--) {
			fgets(p=buf, 15, stdin);
			c = p, p += 3, a = in()-1, b = in()-1;
			if (*c == 'x' && *(c+1) == 'y') {
				for (z = 0; z < n; z++) cnt(a, b, z);
			} else if (*c == 'x' && *(c+1) == 'z') {
				for (y = 0; y < n; y++) cnt(a, y, b);
			} else {
				for (x = 0; x < n; x++) cnt(x, a, b);
			}
		}
		printf("%d\n", n*n*n - ans);
	}
	return 0;
}


Measured memory_bytes: 123836