akhauriyash/Code-Regression huggingface dataset:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     #入力整数1つ
#right,up,n= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
s = pow(10,15)
for i in range(min(a),max(a)+1):
    c = 0
    for k in range(n):
        c+=pow(a[k]-i,2)
    s= min(c,s)
print(s)

Measured memory_bytes: 5972
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int K = nextInt();
        char[] S = next().toCharArray();

        int count = 0;
        boolean flag = false;
        for(int i=1; i<N; i++){
            if(flag && S[i-1] == S[i]){
                flag = false;
                if(count >= K) break;
            }
            if(flag && S[i-1] != S[i]){
                S[i] = S[i-1];
            }
            if(!flag && S[i-1] != S[i]){
                S[i] = S[i-1];
                flag = true;
                count++;
            }
        }

        int ans = 0;
        for(int i=0; i<N-1; i++){
            if(S[i] == S[i+1]) ans++;
        }

        println(ans);
    }

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

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 27056
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main() {
  int s;
  cin>>s;
  
  set<int> st; //集合
  int x=s;
  
  //集合に重複が見つかったら終わり
  while(st.count(x)==0){ 
    st.insert(x);
    if(x%2==0)
      x=x/2;
    else
      x=3*x+1;
  }

  cout<<st.size()+1<<endl;
}


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

int main(){
    int n;
    cin >> n;
    int value[n];
    int cost[n];
    for(int i=0; i<n; i++){
        cin >> value[i];
    }
    for(int i=0;i<n;i++){
        cin >> cost[i];
    }

    int benesum = 0;
    for(int i=0;i<n;i++){
        int benefit = value[i] - cost[i];
        if(benefit>0){
            benesum += benefit;
        }
    }
    cout <<  benesum << endl;
}

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

#define N 100005

int a[N],n;

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

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

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

void init(){
	read(n);
	for(int i=1;i<=n;++i)
	read(a[i]);
}

int main(){
	init();
	long long Sum=0;
	for(int i=1;i<=n;++i)
	Sum=Sum+a[i]-1;
	printf("%lld\n",Sum);
	return 0;
}

Measured memory_bytes: 256
a =int(input())
ans = 0

for j in range(a+1):
    count = 0
    for i in range(j+1):
        if i>=1:
            if j % i==0:
                count += 1
                
    if count == 8:
        
        if (j+1)%2==0:
            ans+=1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

#define MAX 10000

int top,S[MAX];

void push(int);
int pop();

int main(){
  int a,b;
  int top=0;
  char s[100];

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(s[0]=='-'){
      //順序注意!
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else push(atoi(s));

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

  return 0;
}

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2764
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;
 
long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}
 
ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  //cin >> q;
  while (q-- >0) {
    int n,m,k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; ++i) {
     cin >> a[i]; 
    }
    for (int i = 0; i + k < n; ++i) { 
      if (a[i] < a[i + k]) cout << "Yes\n";
      else cout << "No\n";
    }
  }

 
  return 0;
}


Measured memory_bytes: 4432
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op


# globals
inf = float('inf')
N = 0


def set_inputs():
    global N
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    n, k = get_li()
    s = get_lc()
    if s[k-1] == 'A':
        s[k-1] = 'a'
    elif s[k-1] == 'B':
        s[k-1] = 'b'
    else:
        s[k-1] = 'c'
    print(''.join(s))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65388
#include <algorithm>
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  bitset<32> s(in());
  cout << s << endl;
  cout << (~s) << endl;
  cout << (s<<1) << endl;
  cout << (s>>1) << endl;
}



Measured memory_bytes: 3316
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static int[] pre;
    private static int[] low;
    private static int count;
    private static int res;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        List<List<Integer>> g = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            g.add(new ArrayList<>());
        }

        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            g.get(a - 1).add(b - 1);
            g.get(b - 1).add(a - 1);
        }

        pre = new int[n];
        low = new int[n];

        dfs(0, new boolean[n], g, -1);
        System.out.println(res - 1);

    }

    private static void dfs(int num, boolean[] visited, List<List<Integer>> graph, int from) {
        pre[num] = count++;
        low[num] = pre[num];
        visited[num] = true;
        List<Integer> l = graph.get(num);
        for (Integer i : l) {
            if (visited[i]) {
                if (i != from) {
                    low[num] = Math.min(low[num], low[i]);
                }
                continue;
            }
            dfs(i, visited, graph, num);
            low[num] = Math.min(low[num], low[i]);
        }
        if (pre[num] == low[num]) {
            res++;
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> 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];
  }
  int ans=0;
  for (int i=0;i<n;i++){
    if(v[i]>=c[i]){
      ans+=v[i]-c[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  ll a, b, c, k, res;
  cin >> a >> b >> c >> k;

  if(k%2 == 0){
    res = a-b;
  }else{
    res = b-a;
  }
  if(res > 1000000000000000000){
    cout << "Unfair" << endl;
  }else{
    cout << res << endl;
  }
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;


int main(void) {
    ll n, k;
    cin >> n >> k;
    n = n%k;
    if(n > -(n-k)) cout << -(n-k) << endl;
    else cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl;
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl;
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl;
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl;
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl;
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl;
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

//関節点:  O(V + E)
class Articulation{
public:
  int V;
  vector<vector<int> > G;
  vector<int> ord;           //ord[i] := ノードiに訪れた順番
  vector<int> low;           //low[i] := ノードiから訪れることができる最小のord[j]の値。
  vector<int> articulation;
  int ok;

  Articulation():V(-1),ok(false){};
  Articulation(int V):V(V),G(V),ord(V),low(V),articulation(V),ok(false){};
  
  void add_edge(int a,int b){
    ok = false;
    assert(a < V && b < V);
    assert(a >=0 && b >= 0);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  void build(int start = 0){
    ok = true;
    ord.clear(); ord.resize(V,-1);
    low.clear(); low.resize(V,-1);
    articulation.clear(); articulation.resize(V,0);

    int cnt = 0;
    function<int(int,int)> dfs=[&](int pos,int pre){
      ord[pos] = low[pos] = cnt++;
      for(int to:G[pos]) {
        if(to == pre) continue; 
        if(ord[to] != -1) low[pos] = min(low[pos], ord[to]);
        else {
          low[pos] = min(low[pos], dfs(to, pos));
          
          if(pos == start) articulation[pos]++;
          else articulation[pos] |= ord[pos] <= low[to];
        }
      }
      if(pos == start) articulation[pos] = articulation[pos] >= 2;
      return low[pos];
    };
    dfs(start , -1);
  }

  int isBridge(int a,int b){
    assert(ok);
    assert(a < V && b < V);
    assert(a >= 0 && b >= 0);
    if(ord[a] > ord[b]) swap(a, b);
    return ord[a] < low[b];
  }

  int isArticulation(int a){
    assert(ok);
    assert(a >= 0 && a < V);
    return articulation[a];
  }

};

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int V, E;
  cin>>V>>E;
  
  Articulation A(V);
  for(int i=0;i<E;i++){
    int a,b;
    cin>>a>>b;
    A.add_edge(a,b);
  }
  
  A.build();
  vector<int> ans;
  for(int i=0;i<V;i++) if(A.isArticulation(i)) ans.push_back(i);
  for(int a:ans) cout<<a<<endl;

  return 0;
}



Measured memory_bytes: 5460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h[100005];
ll n, a, b;
bool valid (ll k) {
  ll temp = 0;
   for (int i = 0; i < n; i++) {
     if (b * k < h[i]) {
        //temp += (h[i] - b * k) / (a - b) + 1;
        temp += (h[i] - k * b + a - b - 1) / (a - b);
     }
  }
  return temp <= k;
}
int main() {
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  ll lo = 0, hi = 1e9;
  ll mid;
  while (lo < hi - 1) {
     mid = (lo + hi) / 2;
     if (valid(mid)) {
        hi = mid;
     } else {
       lo = mid;
     }
  }
  cout << hi << endl;
  //cout << lo << " " << mid << " " << hi << endl;
  return 0;
}


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

int main(){
  int k,l,i;
  char s[100];

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

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

  return 0;
}


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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String y = scan.next();
      	if(y.charAt(2) == y.charAt(3) && y.charAt(4) == y.charAt(5)){
         System.out.println("Yes"); 
        }
      else{
       System.out.println("No"); 
      }
	}

}


Measured memory_bytes: 21332
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

ll log_2(ll x){
	ll ans = 0;
	while (x % 2 == 0){
		x = x / 2;
		ans++;
	}
	return ans;
}

int main(){
	ll A, B, C;
	cin >> A >> B >> C;
	if ((A % 2 == 1 || B % 2 == 1) || C % 2 == 1){
		cout << 0 << endl;
	}
	else if (A == B&&B == C){
		cout << -1 << endl;
	}
	else{
		ll count = 0;
		while (1){
			count++;
			ll newA = (B + C) / 2;
			ll newB = (A + C) / 2;
			ll newC = (A + B) / 2;
			if ((newA % 2 == 1 || newB % 2 == 1) || newC % 2 == 1){
				cout << count << endl;
				break;
			}
			A = newA;
			B = newB;
			C = newC;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  long x;
  scanf("%ld", &x);

  long coinL,coinS;
  coinL = x/500;
  x -= 500*coinL;
  coinS = x/5;

  long answer;
  answer = coinL*1000+coinS*5;

  printf("%ld\n", answer);

  return 0;
}

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

using namespace std;

long long note[100000+1];

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

    unordered_map<long long, long long> rems;

    long long sum = 0;
    note[0] = x;
    rems[note[0]] = 0;
    sum = x;
    long long start = -1, end = -1;
    for(long long i = 1; i < n; i++) {
        note[i] = (note[i-1] * note[i-1]) % m;
        if(rems.find(note[i]) == rems.end()) {
            rems[note[i]] = i;
        }else {
            start = rems[note[i]];
            end = i;
            break;
        }
        sum += note[i];
    }

    if(start == -1) {
        cout << sum << endl;
        return 0;
    }

    long long count = 0;
    for(long long i = start; i < end; i++) {
        count += note[i];
    }

    sum += ((n - end) / (end - start)) * count;
    long long rest = (n - end) % (end - start);

    for(long long i = 0; i < rest; i++) {
        sum += note[start+i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 5560
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

const int mod=1e9+7;
string K;
int D;
int dp[10010][2][110];

int rec(int dgt,int isless,int d)
{
	if(dgt==K.length())
		return d==0;
	
	if(dp[dgt][isless][d]!=-1)
		return dp[dgt][isless][d];
	
	int res=0;
	int maxnd;
	if(isless)maxnd=9;
	else maxnd=K[dgt]-'0';
	for(int nd=0;nd<=maxnd;nd++)
	{
		int nisless;
		if(isless==1 || nd<maxnd)nisless=1;
		else nisless=0;
		res+=rec(dgt+1,nisless,(d+nd)%D);
		res%=mod;
	}
	
	dp[dgt][isless][d]=res;
	return res;
}

int main()
{	
	cin >> K >> D;
	
	for(int i=0;i<10010;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<110;k++)
				dp[i][j][k]=-1;
	
	cout << (rec(0,0,0)-1+mod)%mod << endl;
	
	return 0;
}

Measured memory_bytes: 9856
import static java.lang.System.out;
import java.lang.Math;
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.LinkedList;
import java.util.HashMap;
import java.util.Collections;

public class Main {
	public static void main(String args[]) {
		new Main().run();
	}

	MyInput in = new MyInput();
	public void run() {
      HashMap<Integer,Integer> dl = new HashMap<>();
      HashMap<Integer,Integer> tl = new HashMap<>();
      int N = in.nextInt();
      int tmp;
      for(int i = 0; i < N; i++) {
          tmp = in.nextInt();
          if(!dl.containsKey(tmp)) dl.put(tmp,1);
          else dl.put(tmp,dl.get(tmp)+1);
      }
      int M = in.nextInt();
      for(int i = 0; i < M; i++) {
          tmp = in.nextInt();
          if(!tl.containsKey(tmp)) tl.put(tmp,1);
          else tl.put(tmp,tl.get(tmp)+1);
      }
      if(M > N) {
          out.println("NO");
      }else {
          boolean flag = true;
          for(Integer a: tl.keySet()) {
              if(!dl.containsKey(a) || dl.get(a) < tl.get(a)) {
                  flag = false;
                  break;
              }
          }
          if(flag) {
              out.println("YES");
          }else {
              out.println("NO");
          }
      }
	}
}

class MyInput {
	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;
	}

	public int readByte() { 
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <=126;
	}

	private void skipUnprintable() {
		while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		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 double nextDouble() {
		return Double.parseDouble(next());
	}
}



Measured memory_bytes: 68940
import collections
n = int(raw_input())
h = collections.Counter()
for x in range(1,n+1):
	if x ** 2 > n:
		break
	for y in range(1,n+1):
		if x ** 2 + y ** 2 + x * y > n:
			break
		for z in range(1,n+1):
			q = x ** 2 + y ** 2 + z ** 2
			q += x*y + y*z + z * x
			if q > n:
				break
			h[q] +=1 
for i in range(1,n+1):
	print h[i]

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

int n,ta,ao,ans;
vector<int> g[100005];
int dis[100005];

void dfs(int x,int p,int d){
    if(d>=dis[x]){
        ans=max(ans,dis[x]);
        return;
    }
    for(int i=0;i<g[x].size();i++){
        int &y=g[x][i];
        if(y!=p){
            dfs(y,x,d+1);
        }
    }
    if(g[x].size()==1){
        ans=max(ans,dis[x]-1);
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>ta>>ao;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    memset(dis,-1,sizeof(dis));
    dis[ao]=0;
    {
        queue<int> q;
        q.push(ao);
        while(!q.empty()){
            int x=q.front();q.pop();
            for(int i=0;i<g[x].size();i++){
                int &y=g[x][i];
                if(dis[y]==-1){
                    dis[y]=dis[x]+1;
                    q.push(y);
                }
            }
        }
    }
    dfs(ta,-1,0);
    cout<<ans<<endl;

    return 0;
}

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

/* After reading the example */
int main(void)
{
    int N;
    cin >> N;

    vector<pair<pair<string, int>, int>> book(N);
    for (int i = 0; i < N; i++)
    {
        cin >> book[i].first.first >> book[i].first.second;
        // めっちゃ賢いやり方。これで、点数が高いものから紹介し
        book[i].first.second *= -1;
        book[i].second = i + 1;
    }

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

    for (int i = 0; i < N; i++)
    {
        cout << book[i].second << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,j;
    long long int a,b,c,d;
    scanf("%d",&n);
    a=0;
    for(i=1;i<=n;i++){
        if(i%3==0){
            i==b;
        }
        else if(i%5==0){
            i==c;
        }
        else if(i%3==0 && i%5==0){
            i==d;
        }
        else{
            a=a+i;
        }
    }
     printf("\n%lld",a);

}


Measured memory_bytes: 1708
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	while (cin >> n){
		vector<int>l;
		for (int i = 0; i < n; i++){
			int a; cin >> a;
			l.push_back(a);
		}
		sort(l.begin(), l.end());
		int num = 0;
		for (int i = 0; i < n; i++){
			num += l[i] * (n - i);
		}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    int k = -1;
    REP(i, N + 10) if(i * (i - 1) / 2 == N) k = i;

    if(k == - 1){
        cout << "No";
    }else{
        cout << "Yes" << endl;
        cout << k << endl;
        mat ans(k, vec(0));
        int n = 1;
        REP(i, k){
            FOR(j, i + 1, k){
                ans[i].push_back(n);
                ans[j].push_back(n);
                n++;
            }
        }
        REP(i, k){
            cout << ans[i].size() << " ";
            REP(j, ans[i].size()) cout << ans[i][j] << " ";
            cout << endl;
        }
    }
    
    return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<int>H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    vector<bool>ans(N,true);
    for(int i = 0; i < M; i++) {
        int a,b;
        cin >> a >> b;
        if(H[a-1] == H[b-1]) {
            ans[a-1] = false;
            ans[b-1] = false;
            continue;
        }
        int X = a-1;
        if(H[a-1] > H[b-1]) {
            X = b-1;
        }
        ans[X] = false;
    }
    int cnt = 0;
    for(int i = 0; i < N; i++) { 
        if(ans[i]) {
            cnt++;
        }
    } 
    cout << cnt << endl;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  ll n,m;cin>>n>>m;
  ll dp[3010][3010][2]={};
  for(int i=1;i<=n;i++)
    dp[0][i][0]=1;
  dp[0][0][1]=1;
  for(int i=1;i<=m;i++){
    for(int j=0;j<=n;j++){

      if(j==0){
	dp[i][0][1]=(dp[i][0][1]+dp[i-1][0][1])%MOD;
	dp[i][0][0]=(dp[i][0][0]+dp[i-1][0][0])%MOD;
	
	dp[i][1][1]=(dp[i][1][1]+dp[i-1][0][1])%MOD;
	dp[i][1][0]=(dp[i][1][0]+dp[i-1][0][0])%MOD;
	
      }
      else if(j==1){
       dp[i][0][1]=(dp[i][0][1]+dp[i-1][1][1])%MOD;
	dp[i][0][1]=(dp[i][0][1]+dp[i-1][1][0])%MOD;
	
	dp[i][1][1]=(dp[i][1][1]+dp[i-1][1][1])%MOD;
	dp[i][1][1]=(dp[i][1][1]+dp[i-1][1][0])%MOD;
	if(j<n){
	  dp[i][2][1]=(dp[i][2][1]+dp[i-1][1][1])%MOD;
	  dp[i][1][1]=(dp[i][1][1]+dp[i-1][1][1])%MOD;
	  dp[i][1][0]=(dp[i][1][0]+dp[i-1][1][0])%MOD;
	  dp[i][2][0]=(dp[i][2][0]+dp[i-1][1][0])%MOD;
	}
      }else{
	dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][1])%MOD;

	dp[i][j-1][1]=(dp[i][j-1][1]+dp[i-1][j][1])%MOD;


	dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][0])%MOD;
	dp[i][j-1][0]=(dp[i][j-1][0]+dp[i-1][j][0])%MOD;
	if(j<n){
	  dp[i][j+1][1]=(dp[i][j+1][1]+dp[i-1][j][1])%MOD;
	  dp[i][j+1][0]=(dp[i][j+1][0]+dp[i-1][j][0])%MOD;
	  dp[i][j][0]=(dp[i][j][0]+dp[i-1][j][0])%MOD;
	  dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][1])%MOD;
	}
      }
    }
  }
  ll ans=0;

  for(int i=0;i<=n;i++){
    ans=(ans+dp[m][i][1])%MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 141824
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--) 

long long int a, b, vis[int(3e5)], ct, mx;
vector<long long int> v[int(3e5)];

void dfs(long long int k)
{
	vis[k]=1;
	forr(i, 0, v[k].size())
	{
		if(!vis[v[k][i]])
		{
			dfs(v[k][i]);
			ct++;
		}
	}

}

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL);
	
	cin>>a>>b;
	forr(i, 0, b)
	{
		long long int x, y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	forr(i, 1, a+1)
	{
		if(!vis[i])
		{
			dfs(i);
			mx=max(mx, ct+1);
			ct=0;
			
		}
	}
	cout<<mx;
	
	return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,m,p;
    cin >> n >> m >> p;
    if(n==0) return 0;
    vector<int> x(n);
    int total=0;
    for(int i=0;i<n;i++){
      cin >> x[i];
      total+=x[i];
    }
    if(x[m-1]==0){
      cout << 0 << endl;
      continue;
    }
    cout << 100*total*(100-p)/100/x[m-1] << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        char[] s = Console.ReadLine().ToCharArray();
        int opening = 0, closing = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(') opening++;
            else if (s[i] == ')')
            {
                if (opening >= 1) opening--;
                else closing++;
            }
        }
        // for (int i = 0; i < closing; i++) Console.Write('(');
        // Console.Write(s);
        // for (int i = 0; i < opening; i++) Console.Write(')');
        // Console.WriteLine();
        var result = new string(Enumerable.Concat(Enumerable.Concat(Enumerable.Repeat('(', closing).ToArray(), s), Enumerable.Repeat(')', opening).ToArray()).ToArray());
        Console.WriteLine(result);
    }
}


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

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

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

    vector<int> a(n);

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

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

    int ans=a[0]+k-a[n-1];

    for(int i=1;i<n;i++) ans=max(ans,a[i]-a[i-1]);

    ans=k-ans;

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3996
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut all = 0;
    for i in 0..n {
        all ^= a[i];
    }

    let mut result = String::new();
    for i in 0..n {
        result.push_str(&format!("{} ", all ^ a[i]));
    }

    return result.trim().to_string();
}


Measured memory_bytes: 9948
fn input_one<T: std::str::FromStr> () -> Result<T, T::Err> {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    n.trim().parse()
}

fn main() {
    let ws = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    let n: String = input_one().unwrap();
    for (i, &w) in ws.iter().rev().enumerate() {
        if w == n {
            println!("{}", i + 1);
            break;
        }
    }
}


Measured memory_bytes: 2140
import numpy as np
n = int(input())
xs = list(map(int, input().split()))
xs = np.array(xs, dtype = np.int64)

res = 10000000000
for pi in range(100):
    re = xs - pi
    re = np.power(re, 2)
    re = np.sum(re)
    res = min(re, res)
print(res)

Measured memory_bytes: 21500
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#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;
  if (N <= 999) {
    cout << "ABC" << endl;
  }
  else {
    cout << "ABD" << endl;
  }
  return 0;
}

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

struct fast_io {
    fast_io() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} __fast_io;

int main() {
    int N, X, T; cin >> N >> X >> T;
    int q = N / X, r = N % X;
    if (r) cout << T * (q + 1) << endl;
    else cout << T * q << endl;
}


Measured memory_bytes: 3616
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vi  a(3*n);
    for (int &i: a) cin >> i;
    sort(a.begin(), a.end()) ; 
    int ans=0;
    for (int i=n;i<3*n;i+=2) ans += a[i]; 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define rep(i, a, b) for(int i=int(a); i<int(b); i++)

int32_t main()
{
    clock_t tStart = clock();
    IOS;

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

    vector<int> h(N);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    // dp[i] represents min cost to get to stone i
    // Subproblem - Prefix array
    vector<int> dp(N, INT_MAX);
    dp[0] = 0;

    for(int i=1; i<N; i++){
        
        // Reccurance relation
        // dp[i] = min(dp[i-j] + |hj - hi|), where i-K <= j <= i-1

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

            if(j >= 0){
                dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
            }

        }
    }

    // for(int i=0 ; i<N; i++){
    //     cout << dp[i] << " ";
    // }
    // cout << endl;

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

    // printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
int main() {
	double n, t, a;
	cin >> n >> t >> a;
	double mi = 10000000;
	double h[10000];
	int s = 0;
	for (int i = 1; i < n+1; i++) {
		cin >> h[i];
		double d = t*1000 - h[i] * 6 - a*1000;
		if (d < 0)d = -1 * d;
		if (mi > d) mi=d, s = i;
	}
	cout << s << endl;
}


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

int main(){
  int n,x,a[3],s[2];cin>>n>>x>>a[0]>>a[1];
  s[0]=a[0]+a[1];
  ll ans=0;
  REP(i,n-2){
    cin>>a[2];s[1]=a[1]+a[2];
    if(s[0]>x&&s[1]>x){
      int d=min({s[0]-x,s[1]-x,a[1]});
      s[0]-=d;
      s[1]-=d;
      a[1]-=d;
      ans+=(ll)d;
    }
    ans+=(ll)(max(s[0]-x,0));
    a[0]=a[1];
    a[1]=a[2];
    s[0]=a[0]+a[1];
  }
  if(n==2) s[1]=s[0];
  ans+=(ll)(max(s[1]-x,0));
  
  cout<<ans;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    VI V(N);
    REP(i, N) cin >> V[i];
    sort(all(V));
    int ans = INT_MAX;
    FOR(ss, 1, (1 << N) - 1) {
    	VI W;
    	for (int i = 0; i < N; i++) {
    		if (ss & (1 << i)) W.pb(V[i]);
    	}
    	do {
	    	int sz = SZ(W);
	    	FOR(i, 0, sz - 1) {
	    		FOR(j, i + 1, sz - 1) {
	    			int s1 = 0;
	    			FOR(l, i, j - 1) {
	    				s1 += W[l];
	    			}
	    			int cost1 = abs(C - s1) + (j - i - 1) * 10;
	    			FOR(k, j + 1, sz - 1) {
	    				int s2 = 0;
	    				FOR(l, j, k - 1) {
	    					s2 += W[l];
	    				}
	    				int cost2 = abs(B - s2) + (k - j - 1) * 10;
	    				int s3 = 0;
	    				FOR(l, k, sz - 1) {
	    					s3 += W[l];
	    				}
	    				int cost3 = abs(A - s3) + (sz - k - 1) * 10;
	    				int tcost = cost1 + cost2 + cost3;
	    				if (tcost < ans) {
	    					ans = tcost;
	    				}
	    			}
	    		}
	    	}
    	} while (next_permutation(all(W)));
    }
    cout << ans << '\n';
}

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

int main(){
    ll q,h,s,d;
    cin >> q >> h >> s >> d;
    ll n;
    cin >> n;
    vector<ll> a = {8*q, 4*h, 2*s, d};
    sort(a.begin(),a.end());
    vector<ll> b = {4*q, 2*h, s};
    sort(b.begin(),b.end());
    cout << (n/2)*a[0] + (n%2)*b[0] << endl;
} 

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

#define ll long long
// #define endl '\n'

// void max_self(int &a, int b){a = max(a, b);}
// void min_self(int &a, int b){a = min(a, b);}

const int MOD = 1e9 + 7;

void solve(){
	int n; cin>>n;
	vector< ll > v(n), pref;
	for(ll &i : v) cin>>i;
	pref = v;
	for(int i = 1; i<n; i++){
		pref[i] += pref[i - 1];
		if(pref[i] >= MOD){
			pref[i] -= MOD;
		}
	}
	ll ans = 0;
	for(int j = 1; j<n; j++){
		ans += v[j] * pref[j - 1];
		ans = ans % MOD;
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 6328
#include <iostream>
#include <string>
int NumA=97;
int NumZ=122;
int K=0;
int snum=0;
int main(void){
	std::string s;
	std::cin>>s;
	std::cin>>K;
	//std::cout<<s.length()<<std::endl;

	while(1){
		if(snum<s.length()-1){
			if(s[snum]=='a'){
				snum++;
//				continue;
			}else if(K>=NumZ-(int)s[snum]+1){
				K-=NumZ-(int)s[snum]+1;
				s[snum]='a';
				snum++;
//				continue;
			}else {
				snum++;
//				continue;
//				s[snum]+=K;
//				snum++;
//				break;
			}
		}else {
			K%=26;
			if(s[snum]+K>NumZ){
				s[snum]=(NumA-1)+(s[snum]-NumZ);
			}
			s[snum]+=K;
/*			if((int)s[snum]>NumZ){
				s[snum]=(NumA-1)+((int)s[snum]-NumZ);
			}
			if((int)s[snum]>NumZ){
				s[snum]=(NumA-1)+((int)s[snum]-NumZ);
			}
			if((int)s[snum]>NumZ){
				s[snum]=(NumA-1)+((int)s[snum]-NumZ);
			}*/

			//s[snum]+=NumA;
			break;
		}
/*		std::cout<<"............"<<std::endl;
		std::cout<<s<<std::endl;
		for(int i=0;i<s.length();i++){
			std::cout<<(int)s[i]<<std::endl;
		}
		std::cout<<K<<std::endl;
		std::cout<<"............"<<std::endl;*/
	}
	std::cout<<s<<std::endl;

/*		for(int i=0;i<s.length();i++){
			std::cout<<(int)s[i]<<std::endl;
//			std::cout<<K<<std::endl;
//			std::cout<<"............"<<std::endl;
		}*/

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=15;
int arr[N][N];
int n,d;
int distant(int i,int j){
    double sum=0;
    for(int k=0;k<d;k++){
        sum+=(arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
    }
    int y=sqrt(sum);
    if(y*y==sum){
        return 1;
    }else{
        return 0;
    }
}
int main(){
    cin>>n>>d;
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>arr[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=distant(i,j);
        }
    }
    cout<<ans<<endl;
    //system("pause");
}

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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( (T*)array, (T*)(array+N), val );
}

// binary search
ll BSearch(ll _begin, ll _end, bool (*f)(int)){
  ll mid;
  while(_end - _begin > 1LL) {
  mid = (_begin + _end) / 2LL;
  if(f(mid)) {
    debug("BSearch: f(%d) == true\n", mid);
    _end = mid;
  }
  else
  {
    debug("BSearch: f(%d) == false\n", mid);
    _begin = mid;
  }
  }
  return _end;
}


ll N,M,K,A[NMAX],B[NMAX],C,D,E;
int dp[NMAX] = {};

string S;
vec v;

ll ans = {};

void solve(){
  // main algorithm
  for (int i = 0; i < N ; ++i)
  {
    ans += B[i] - A[i] + 1;
  }
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // Fill(dp, -1);
  cin >> N;
  for (int i = 0; i < N; ++i)
  {
    scanf("%lld%lld", &A[i], &B[i]);
  }
  solve();
  #ifdef DEBUG
  debug();
  #endif
  answer();

  return 0;
}


Measured memory_bytes: 256