akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    ll a, b, c; cin >> a >> b >> c;
    ll res;
    if(a % 2 == 0 or b % 2 == 0 or c % 2 == 0) {
        res = 0LL;
    }
    else {
        res = min({a * b, b * c, c * a});
    }

    cout << res << endl;

    return 0;
}


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

class Node{
public:
	int depth;
	
	int parent;
	
	int degree;
	int *children;
	
	
};

void Depth(Node *node,int cur, int dp){
	
	node[cur].depth = dp;
	
	
	for(int i=0;i<node[cur].degree;++i){
		Depth(node,node[cur].children[i],dp+1);
	}
	
}

int main() {
	
	int n;
	Node *node;
	
	cin>>n;
	node = new Node[n];
	for(int i=0;i<n;++i)node[i].parent = -1;
	
	
	for(int i=0;i<n;++i){
		int id,k;
		
		cin>>id;
		cin>>k;
		node[id].degree = k;
		
		node[id].children = new int[k];
		for(int j=0;j<k;++j){
			int cid;
			cin>>cid;
			node[id].children[j] = cid;
			node[cid].parent = id;
		}
	}
	
	int root;
	for(int i=0;i<n;++i)if(node[i].parent == -1)root = i;
	
	Depth(node,root,0);
	
	for(int i=0;i<n;++i){
		cout<<"node "<<i<<": parent = "<<node[i].parent<<", depth = "<<node[i].depth<<
		", "<<( i==root?"root": ( node[i].degree == 0 ? "leaf" : "internal node" ) )<<", [";
		
		for(int j=0;j<node[i].degree;++j){
			cout<<(j?", ":"")<<node[i].children[j];
		}
		cout<<"]"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 7052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    cin >> n;
    map<ll, int> map;
    VL a(n);
    FOR(i, 0, n) {
        cin >> a[i];
        map[a[i]]++;
    }

    SORT(a);
    string ans = "Yes\n";
    if (map.size() == 3) {
        for (auto i : map)if (i.second != n / 3)ans = "No\n";
        if ((a[0] ^ a[n / 3] ^ a[n / 3 * 2]) != 0)ans = "No\n";
    }
    else if (map.size() == 2) {
        if (map[0] != n / 3)ans = "No\n";
        if (map[a[n - 1]] != n / 3 * 2)ans = "No\n";
    }
    else if (map.size() == 1) {
        if (a[0] != 0)ans = "No\n";
    }
    else ans = "No\n";

    cout << ans << "\n";
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
    int m,n;
    scanf("%d %d",&n,&m);
    m/=1000;
    bool flag=false;
    if(m<n||m>10*n) printf("-1 -1 -1\n");
    else
    {
        for(int i=0; i*10<=m&&i<=n; i++)
        {
            for(int j=0; i*10+j*5<=m&&i+j<=n; j++)
                if(i*10+j*5+(n-i-j)==m)
                {
                    flag=true;
                    printf("%d %d %d\n",i,j,n-i-j);
                    break;
                }
            if(flag) break;
        }
        if(!flag) printf("-1 -1 -1\n");
    }
    return 0;
}


Measured memory_bytes: 256
import itertools
import numpy as np

N,M,Q = map(int, input().split())

a = range(1,M+1)
arr = np.asarray(list(itertools.combinations_with_replacement(a,N))) #重複組み合わせ
#print(arr)

sc = np.zeros(arr.shape[0],dtype=int)
#print(sc)

for i in range(Q):
  abcd = list(map(int, input().split()))
  f = (arr[:,abcd[1]-1]-arr[:,abcd[0]-1])==abcd[2]
  sc += abcd[3]*f 
#
print(sc.max())


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

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	rep(i, N) cin >> s[i];
	sort(s.begin(), s.end());
	int ans = 1;
	rep(i, N - 1) {
		if (s[i] != s[i + 1]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 9596
from collections import Counter

n=int(input())
s=[input() for _ in range(n)]
c=Counter(s)
mx=c.most_common()[0][1]
ans=[]
for e in c.most_common():
    if mx==e[1]:
        ans.append(e[0])
ans.sort()
print(*ans,sep='\n')

Measured memory_bytes: 47232
#include <iostream>
using namespace std;
int main()
{
	int n, s[12], t[12], i, j, c;
	bool f;
	while (cin >> n, n)
	{
		for (i = 0; i < n; i++)
		{
			cin >> s[i];
		}
		c = 0;
		while (1)
		{
			f = false;
			for (i = 0; i < n; i++)
			{
				t[i] = 0;
				for (j = 0; j < n; j++)
				{
					if (s[i] == s[j])
						t[i]++;
				}
			}
			for (i = 0; i < n; i++)
			{
				if (s[i] != t[i])
				{
					for (j = 0; j < n; j++)
						s[j] = t[j];
					f = true;
					c++;
					break;
				}
			}
			if (!f)
			{
				cout << c << endl;
				for (i = 0; i < n; i++)
				{
					cout << t[i];
					if (i == n-1)
						cout << endl;
					else
						cout << " ";
				}
				break;
			}
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
    string S,T;
    cin >> S >> T;
    int c = 0;
    for(int i=0;i<3;i++){
        if(S[i] == T[i]){
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main() {
  ll n,k;
  cin >> n >> k;
  cout << n-(k-1);
}

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

int main(){
  string o,e; cin >>o>>e;
  for(int i=0; i<e.size(); i++){
    cout << o[i] << e[i];
  }
  if(o.size()!=e.size())
    cout << o[o.size()-1];
  cout << endl;
}

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

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<pair<int, int>>> s(d, vector<pair<int, int>>(26));
  for (int i = 0; i < 26; i++) cin >> c[i];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j].first;
      s[i][j].first = -s[i][j].first;  // -1倍
      s[i][j].second = j;
    }
  }
  for (int i = 0; i < d; i++) {
    sort(s[i].begin(), s[i].end());
  }
  vector<int> ret(d);
  for (int i = 0; i < d; i++) {
    ret[i] = s[i][0].second;
  }
  for (int i = 0; i < d; i++) {
    cout << ret[i] + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3312
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func Dijkstra(G [][]int, v int) []int {
  N := len(G)
  D := make([]int, N)
  for i := range D {
    D[i] = -1
  }
  D[v] = 0
  Q := make([]int, N)
  Q[0] = v
  pos := 1
  for _, q := range Q {
    for _, adj := range G[q] {
      if 0 <= D[adj] { continue }
      D[adj] = D[q] + 1
      Q[pos] = adj
      pos++
    }
  }
  return D
}

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

func Max(A []int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}

func main() {
  Nuv := NextIntVec()
  N, u, v := Nuv[0], Nuv[1] - 1, Nuv[2] - 1
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, 0)
  }
  for i := 1; i < N; i++ {
    ab := NextIntVec()
    a, b := ab[0] - 1, ab[1] - 1
    G[a] = append(G[a], b)
    G[b] = append(G[b], a)
  }
  T := Dijkstra(G, u)
  A := Dijkstra(G, v)
  D := make([]int, N)
  eq := N
  for i := range D {
    if A[i] < T[i] { continue }
    if T[i] == A[i] {
      eq = Min(A[i], eq)
    }
    if T[i] < A[i] { D[i] = A[i] - 1 }
  }
  if eq == N { eq = 0 }
  Write(Max([]int{Max(D), eq}))
  Output()
}

Measured memory_bytes: 12288
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int K = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		Arrays.sort(A);
		int ok = A[A.length - 1];
		int ng = 0;
		while (Math.abs(ok - ng) > 1) {
			int mid = (ok + ng) / 2;
			if (canBe(K,mid, A)) ok = mid;
			else ng = mid;
		}
		System.out.println(ok);
	}

	boolean canBe(int k, int x, int... A){
		for (int value : A) {
			k -= -Math.floorDiv(-value, x) - 1;
		}
		return k >= 0;
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 57956
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const ll mod = 1e9 + 7;

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

  int n;
  cin >> n;
  set<ll> a;
  rep(i, n) {
    ll b;
    cin >> b;
    if (a.count(b) != 0) a.erase(b);
    else a.insert(b);
  }

  cout << a.size() << endl;

  return 0;
}


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

int main()
{
  char s[100];
  char temp;
  char p[100];
  int string_length = 0;
  unsigned char flag = 0;

  scanf( " %s", s );
  scanf( " %s", p );

  string_length = strlen(s) - 1;

  for ( int i = 0; i <= string_length; i++ ){
    temp = s[string_length];
    for ( int j = string_length; j > 0; j-- ){
      s[j] = s[j-1];
    }

    s[0] = temp;

    if ( strstr( s, p ) != NULL ) {
      flag = 1;
      printf( "Yes\n" );
      break;
    }
  }

  if ( !flag ) printf( "No\n" );

  return 0;
}


Measured memory_bytes: 2116
package main

import "fmt"

func main() {
	c := make([][]int, 3)

	for i := range c {
		for j := 0; j < 3; j++ {
			var tmp int
			fmt.Scan(&tmp)
			c[i] = append(c[i], tmp)
		}
	}
	var a1, a2, a3, b1, b2, b3 int
	a1 = 0
	b1 = c[0][0]
	b2 = c[0][1]
	b3 = c[0][2]
	a2 = c[1][0] - b1
	a3 = c[2][0] - b1

	a := []int{a1, a2, a3}
	b := []int{b1, b2, b3}

	ans := "Yes"
LABEL:
	for i := range c {
		for j := range c {
			if c[i][j] != a[i]+b[j] {
				ans = "No"
				break LABEL
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  //assert(n >= 3)
  val numbers = readLine.trim.split(' ').map(_.toInt).toArray
  //assert(numbers.length >= 3)
  println(calMin(numbers))



  def calMin(numbers: Array[Int]): Int = {
    if (numbers.length < 3) return 0
    var array = numbers.clone()
    var result = Nil: List[Int]
    var temp = minToRight(1, true, array, 0)
    if (isZigZag(array))
      result ::= temp
    array = numbers.clone()
    temp = minToRight(1, false, array, 0)
    if (isZigZag(array))
      result ::= temp
    array = numbers.clone()
    array.swap(1, 2)
    temp = minToRight(1, true, array, 1)
    if (isZigZag(array))
      result ::= temp
    array = numbers.clone()
    array.swap(1, 2)
    temp = minToRight(1, false, array, 1)
    if (isZigZag(array))
      result ::= temp
    result.min
  }
  def isZigZag(numbers: Array[Int]): Boolean = {
    assert(numbers.length >= 3, numbers.mkString(","))
    if (numbers.length < 3) throw new UnknownError()
    val bool = numbers.indices.tail.map{i ⇒ numbers(i - 1) < numbers(i)}
    assert(bool.length >= 2)
    if (bool.length < 2) throw new UnknownError()
    bool.indices.tail.forall{i ⇒ bool(i) != bool(i - 1)}
  }
  @tailrec def minToRight(position: Int,ud: Boolean, numbers: Array[Int], result: Int): Int = {
    if (position >= numbers.length) result
    else {
      if (ud) {
        if (numbers(position - 1) > numbers(position)) minToRight(position + 1, !ud, numbers, result)
        else if (position + 1 < numbers.length) {
          numbers.swap(position, position + 1)
          if (numbers(position - 1) > numbers(position)) minToRight(position + 1, !ud, numbers, result + 1)
          else {
            numbers.swap(position, position + 1)
            numbers.swap(position - 1, position)
            minToRight(position + 1, !ud, numbers, result + 1)
          }
        }else {
          numbers.swap(position - 1, position)
          minToRight(position + 1, !ud, numbers, result + 1)
        }
      }else {
        if (numbers(position - 1) < numbers(position)) minToRight(position + 1, !ud, numbers, result)
        else if (position + 1 < numbers.length) {
          numbers.swap(position, position + 1)
          if (numbers(position - 1) < numbers(position)) minToRight(position + 1, !ud, numbers, result + 1)
          else {
            numbers.swap(position, position + 1)
            numbers.swap(position - 1, position)
            minToRight(position + 1, !ud, numbers, result + 1)
          }
        }else {
          numbers.swap(position - 1, position)
          minToRight(position + 1, !ud, numbers, result + 1)
        }
      }
    }
  }
  implicit class Wrap[T](val array: Array[T]) extends AnyVal {
    def swap(a: Int, b: Int): Unit = {
      val temp = array(a)
      array(a) = array(b)
      array(b) = temp
    }
  }
}


Measured memory_bytes: 105040
#include <cstdio>
#include <list>
#include <iostream>
using namespace std;

struct TreeNode{
  int parent;
  int right, left;
  TreeNode(){
    parent = -1;
    right  = -1;
    left   = -1;
  }
};

TreeNode tree[100000];

int height(int node, int h=0){
  if (tree[node].right==-1 && tree[node].left==-1)
    return h;
  if (tree[node].left == -1)
    return height(tree[node].right, h+1);
  if (tree[node].right == -1)
    return height(tree[node].left,  h+1);
  return max(height(tree[node].left, h+1), height(tree[node].right, h+1));
}

int getDepth(int node, int d=-1){
  if (node == -1) return d;
  return getDepth(tree[node].parent, d+1);
}

int getSubling(int node){
  if (tree[node].parent == -1) return -1;
  if (tree[tree[node].parent].right == node)
    return tree[tree[node].parent].left;
  else
    return tree[tree[node].parent].right;
}

int main(){
  int n;
  cin >> n;
  for (int i=0;i<n;++i){
    int id, left, right;
    cin >> id >> left >> right;
    tree[id].left  = left;
    tree[id].right = right;
    tree[left].parent = id;
    tree[right].parent = id;
  }
  for (int i=0;i<n;i++){
    cout << "node " << i << ": parent = " << tree[i].parent << ", sibling = " << getSubling(i) << ", degree = " << ((tree[i].right!=-1) + (tree[i].left!=-1)) << ", depth = " << getDepth(i) << ", height = " << height(i);
    if (tree[i].parent == -1){
      cout << ", root" << endl;
    }
    else if (tree[i].right != -1 || tree[i].left != -1)
      cout << ", internal node" << endl;
    else {
      cout << ", leaf" << endl;
    }
  }
}



Measured memory_bytes: 4276
import string
N = int(input())
alph = string.ascii_lowercase

ans = []
A = [0]
def search():
    if len(A) == N:
        ans.append(tuple(A))
        return

    mx = max(A)
    for i in range(mx + 2):
        A.append(i)
        search()
        A.pop()
    return

search()

for a in ans:
    print(''.join(alph[i] for i in a))


Measured memory_bytes: 20908
N = input()
nums = input().split()
nums = [int(n) for n in nums]
cnt = 0

while(True):
    e_nums = [n/2 for n in nums if n % 2 == 0]
#    print(nums, ":", e_nums)
    if len(nums) > len(e_nums):
        break
    cnt += 1
    nums = e_nums
print(cnt)



Measured memory_bytes: 2940
def solve(N, X, M):
    x = X
    table = [-1] * M
    a = []
    length = 0
    # ループするまで配列に値を入れていく
    while table[x] == -1:
        a.append(x)
        table[x] = length
        length += 1
        x = x**2 % M

    # ループの開始位置とループの合計値を求める
    start = table[x]
    loop_total = 0
    for i in range(table[x], length):
        loop_total += a[i]

    # 答えの計算
    ans = 0
    if N <= length:
        for i in range(N):
            ans += a[i]
    else:
        # フルで何周するかを計算
        count = N - start
        count //= (length-start)
        ans += count * loop_total
        count *= (length-start)
        count = N - count
        for i in range(count):
            ans += a[i]

    return ans


if __name__ == "__main__":
    N, X, M = map(int, input().split())
    print(solve(N, X, M))


Measured memory_bytes: 13236
N=int(input())
bord=[[] for i in range(N)]
for i in range(N):
  bord[i]=[int(x) for x in input().split()]
sales=[[] for i in range(N)]
for i in range(N):
  sales[i]=[int(x) for x in input().split()]

ans=-100000000000
for i in range(1,2**10):
  res=0
  for j in range(N):
    cnt=0
    for k in range(10):
      if (i>>k)%2 and bord[j][k]==1:
        cnt+=1
    res+=sales[j][cnt]
  ans=max(res,ans)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    for (int i=1; ; ++i) {
        cin >> n;
        if (n == 0) {
            break;
        }
        cout << "Case " << i << ": " << n << "\n";
    }

    return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#define NOT_FOUND -1
int binarySearch(int key);
int i,a[100000],b[50000],n,q,c=0;

int main()
{

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&b[i]);
    if(binarySearch(b[i])!=NOT_FOUND)
      c++;
  }
  printf("%d\n",c);
  return 0;
}




int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;  
  while (left < right){
    mid = (left + right) / 2;
    if (a[mid] == key)
      return mid;
    else if (key < a[mid])
      right = mid;
    else{
      left = mid + 1;
    
    }
      
  }

  return NOT_FOUND;
  
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t)); reverse(all(t));
    if(s < t) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max<R>(x, 0.0));}

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

// Problem Specific Parameter:

template <int depth>  struct Segment_tree {
	const static int h = depth;
	const static int n = 1 << h;

	using T = long long;
	T data[2 * n];
	const T out = (1LL << 31) - 1;

	inline T vmerge(T l, T r) {return min(l, r);}

	void init() {
		fill_n(data, 2 * n, out);
	}

	void update(int p, T x) { // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1) {
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(int l, int r) {  // sum on interval [l, r)
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};

Segment_tree<17> rmq;


int main(void) {
	int n, q;
	cin >> n >> q;

	rmq.init();

	rep(loop, q) {
		int com, x, y;
		cin >> com >> x >> y;
		if (com)
			cout << rmq.query(x, y + 1) << endl;
		else
			rmq.update(x, y);
	}
	return 0;
}

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

#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define rep(a, b, i) for(int i = a; i < b; i++)
#define repi(a, b, i) for(int i = a; i > b; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define __ ios_base::sync_with_stdio(cin.tie(0) && 0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef double ld;

const ld pi = 3.141592653589793;
const ll inf = 1e18 + 5;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 5;
const int mxn = 1e5 + 5;
const int mx = 1000;

string s, t;

int change(int x) {
  int res = 0;
  rep(x, x + sz(t), i) {
    if(s[i] != t[i - x]) res++;
  }
  return res;
}

int main() {
  __;

  cin >> s >> t;

  int mini = INT_MAX;
  rep(0, sz(s) - sz(t) + 1, i) {
    mini = min(change(i), mini);
  }

  cout << mini << '\n';

  return 0;
}


Measured memory_bytes: 3624
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    const auto f = [C, D](ll x)
    {
        return x - x / C - x / D + x / lcm(C, D);
    };
    cout << f(B) - f(A - 1);
    //
    return 0;
}

Measured memory_bytes: 3592
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, k;
    cin >> a >> b >> k;
    p_que ans;
    for (int i=1; i<=100; ++i){
        if(a % i == 0 && b % i == 0){
            ans.push(i);
        }
    }
    for (int i=1; i<=k; ++i){
        if(i < k){
            ans.pop();
        }
        else if(i == k){
            int n = ans.top();
            cout << n << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC57 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,a,b = map(int,input().split())
v = list(map(int,input().split()))
v.sort(reverse = True)
fact = [1]
for i in range(1,n+1):
    fact.append(fact[i-1]*(i))
def comb(n,r):
    return fact[n]// fact[r] //fact[n-r]
ans = sum(v[:a])/a
print(ans)
M,m = max(v[:a]),min(v[:a])
if M != m:
    c1,c2 = v[:a].count(m),v.count(m)
    print(comb(c2,c1))
else:
    ans = 0
    c = v.count(m)
    for i in range(a,b+1):
        if c >= i:
            ans += comb(c,i)
    print(ans)


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

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

typedef long double ld;

const int N = 300 + 5;
const ld EPS = 1e-9;

ld dp[N][N][N];
int mark[N][N][N];
int n, a, cnt[3]; 

ld dpf(int a, int b, int c) {
  if(mark[a][b][c]) return dp[a][b][c];
  mark[a][b][c] = 1;
  if(!a and !b and !c) return dp[a][b][c] = 0;
  
  ld nd = n, ad = a, bd = b, cd = c;
  ld part_a = 0, part_b = 0, part_c = 0;

  if(a-1 >= 0) part_a = ad/nd * dpf(a-1, b, c);
  if(b-1 >= 0) part_b = bd/nd * dpf(a+1, b-1, c);
  if(c-1 >= 0) part_c = cd/nd * dpf(a, b+1, c-1);
  
  return dp[a][b][c] = nd/(ad+bd+cd) * (1 + part_a + part_b + part_c);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a, cnt[a-1]++;
  cout << fixed << setprecision(20) << dpf(cnt[0], cnt[1], cnt[2]) << "\n";  
}


Measured memory_bytes: 549248
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int arr[100005];
int dp[3005][3005];
int anss  = 0 ;
char rep[100005];
int c=0;
string str1,str2;
int lcs(int first,int last)
    {
        if(first<=0|last<=0)
            {
                return 0;
            }
        if(dp[first][last]!=-1998)
            return dp[first][last];
        if(str1[first]==str2[last]&&(first!=str1.size()&&last!=str2.size()))
        {
            dp[first][last]=1+lcs(first-1,last-1);
            anss = max(anss,dp[first][last]);

        }
        else
            {
            dp[first][last] = max(dp[first][last],max(lcs(first-1,last),lcs(first,last-1)));
            }
        return dp[first][last];

    }
void printstring()
    {
        int i = str1.size();
        int j = str2.size();
        int idx = anss;
        char str[anss+1];
        str[idx+1]='\0';
        while(i>0&&j>0)
        {
            if(str1[i]==str2[j])
            {
                str[idx]= str1[i];
                idx--;
                i--;
                j--;
            }
            else if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
                j--;
        }
        cout<<str<<endl;
    }
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for(int i=0;i<3006;i++)
        for(int j=0;j<3006;j++)
            dp[i][j]=-1998;
    cin>>str1>>str2;
    str1="X"+str1;
    str2="Y"+str2;
    string ans="";
    int n = min(str2.size(),str1.size());
    int n1 = max(str2.size(),str1.size());
    lcs(str1.size()-1,str2.size()-1);
    printstring();

}













Measured memory_bytes: 39244
N, M = list(map(int,input().split()))

A = list(map(int, input().split()))

As = sorted(A,reverse=True)

flag = 0
for x in range(M):
    if As[x] < sum(A)/4/M:
        flag = 1
        break

if flag == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9080
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, S, L[509], R[509], p[509], W[509][509], dp[509];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> S; --S;
	for (int i = 0; i < N; ++i) cin >> L[i] >> R[i], p[i] = i;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> W[i][j];
		}
		dp[i] = -(1 << 30);
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				W[j][k] = min(W[j][k], W[j][i] + W[i][k]);
			}
		}
	}
	sort(p, p + N, [&](int i, int j) { return R[i] < R[j]; });
	for (int i = 0; i < N; ++i) {
		int v = p[i];
		int reach = max(L[v], W[S][v]);
		if (reach <= R[v]) dp[v] = R[v] - reach;
		for (int j = 0; j < N; ++j) {
			if (j == v) continue;
			int reachx = max(L[v], R[j] + W[j][v]);
			if (reachx <= R[v]) dp[v] = max(dp[v], dp[j] + R[v] - reachx);
		}
	}
	cout << *max_element(dp, dp + N) << endl;
	return 0;
}


Measured memory_bytes: 4224
n=gets.to_i
yn=0
for i in 0..25 do
  for j in 0...15 do
    if n==4*i+7*j then
      yn=1
      break
    end
  end
  if yn==1 then
    break
  end
end
if yn==1 then
  puts "Yes"
else
  puts "No"
end


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> good_squares;
    for (int i = 0; i <= n; ++i) {
        if (s[i] == '0') {
            good_squares.push_back(i);
        }
    }
    int good_pos = (int) good_squares.size() - 1;
    deque<int> moves;
    while (good_pos > 0) {
        int pos = good_squares[good_pos];
        int next_good_pos = good_pos - 1;
        int next_pos = good_squares[next_good_pos];
        if (pos - next_pos > m) {
            cout << -1 << endl;
            return 0;
        }
        while (next_good_pos > 0 && pos - good_squares[next_good_pos - 1] <= m) {
            --next_good_pos;
        }
        next_pos = good_squares[next_good_pos];
        moves.push_front(pos - next_pos);
        good_pos = next_good_pos;
    }
    for (auto move : moves) {
        cout << move << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1352
let m = 1000000007
let ( *^ ) x y = (x * y) mod m

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let pos, neg =
    List.partition (( <= ) 0) @@
    List.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let l = List.length pos in
  let l' = List.length neg in
  let pos' = Array.make (l + 1) 1 in
  let pos'' = Array.make (l + 1) 0.  in
  let neg' = Array.make (l' + 1) 1 in
  let neg'' = Array.make (l' + 1) 0.  in
  let neg''' = Array.make (l' + 1) 1 in
  let neg'''' = Array.make (l' + 1) 0.  in
  List.iteri (fun i a ->
    pos'.(i + 1) <- pos'.(i) *^ a;
    pos''.(i + 1) <- pos''.(i) +. log (float_of_int a)) (List.sort (Fun.flip compare) pos);
  List.iteri (fun i a ->
    neg'.(i + 1) <- neg'.(i) *^ (a + m);
    neg''.(i + 1) <- neg''.(i) +. log (float_of_int (~- a))) (List.sort compare neg);
  List.iteri (fun i a ->
    neg'''.(i + 1) <- neg'''.(i) *^ (a + m);
    neg''''.(i + 1) <- neg''''.(i) +. log (float_of_int (~- a))) (List.sort (Fun.flip compare) neg);
  Printf.printf "%d\n" @@
  snd @@
  snd @@
  Array.fold_left max (0, (neg_infinity, 0)) @@
  Array.init (1 + k) @@ fun i ->
    if l < k - i || l' < i then (0, (neg_infinity, 0))
    else if i mod 2 = 1
    then (0, (~-. (pos''.(k - i)) -. neg''''.(i), pos'.(k - i) *^ neg'''.(i)))
    else (1, (pos''.(k - i) +. neg''.(i), pos'.(k - i) *^ neg'.(i)))

Measured memory_bytes: 38760
#include <iostream>
#include<string>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    long long x;
    cin >> x;
    long long m = 100;
    int i =0;
    while (m < x) {
        m = m * 1.01;
        i++;
    }
    cout << i << endl;
    return 0;
}

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s;
	cin>>s;
	int n=s.size();
	int cnt=0, i=0;
	ll ans=0;
	while(i<n){
		if(s[i]=='A'){
			++i;
			++cnt;
		}
		else if(s[i]=='B'){
			if(i+1>=n){
				break;
			}
			if(s[i+1]=='C'){
				ans+=cnt;
				i+=2;
			}
			else{
				cnt=0;
				++i;
			}
		}
		else{
			cnt=0;
			++i;
		}
		// DEBUG(i);
		// DEBUG(ans);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	
	for(int i=0;i<c/2;i++){
		a = a/2;
		b = b+a;
		b = b/2;
		a = a+b;
	}
	
	if(c%2==1){
		a = a/2;
		b = b+a;
	}
	
	cout << a << ' ' << b << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}


signed main()
{
    // cin.tie(nullptr); ios::sync_with_stdio(false);

    i64 a[4];
    i64 v[4] = {250, 500, 1000, 2000};
    i64 N;

    for (int i = 0; i < 4; ++i) cin >> a[i];
    cin >> N;
    N *= 1000;


    i64 ans = LINF;
    for (int b = 1; b < (1 << 4); ++b) {
        bitset<4> bit(b);
        i64 n = N;
        i64 sum = 0;
        for (int i = 3; i >= 0; --i) {
            if (!bit[i]) continue;
            sum += (n / v[i]) * a[i];
            n %= v[i];
        }
        if (n <= 0) {
            chmin(ans, sum);
        }
    }

    cout << ans << endl;
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		String[] tmpArray = br.readLine().split(" ");

		int input[] = new int[n];
		long fixed[] = new long[n];

		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(tmpArray[i]);
			fixed[i] = input[i] - (i + 1);
		}

//		//debug
//		for(int i = 0; i < n; i++){
//			System.out.print(fixed[i] + " ");
//		}
//		System.out.println();

		Arrays.sort(fixed);

		long b = fixed[n/2];

		long result = 0;
		for(int i = 0; i < n; i++){
			result += Math.abs(fixed[i] - b);
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 61432
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


vector<int> m = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string getMax(string a, string b)
{
    if(a.length() > b.length())
    {
        return a;
    }
    else if(a.length() < b.length())
    {
        return b;
    }
    else  //如果长度相等，返回字典序较大的字符串
    {
        return a > b ? a : b;
    }
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M, 0);
    for(int i = 0; i < M; i++)
    {
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<int>());

    vector<string> dp(max(N+1,10), "");

    for(int i = 0; i < M; i++)
    {
        dp[m[A[i]]] = getMax(dp[m[A[i]]], to_string(A[i]));
    }

    for(int j = 0; j <= N; j++)
    {
        for(int i = 0; i < M; i++)
        {
            if(j - m[A[i]] >= 0 && dp[j-m[A[i]]] != "")
            {
                dp[j] = getMax(dp[j], dp[j-m[A[i]]] + to_string(A[i]));
            }
        }
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 32896
/* ex3_3
    suuxxu */

#include <stdio.h>

int main(void){
    int n, k, i; // integer n, base_K
    int fac; // factorial
    
    // get inputs
    scanf("%d %d", &n, &k);

    // calculate answer
    i = 0;
    fac = 1;
    while(1){
        i++;
        fac = fac * k;
        if(n < fac) break;
    }
    printf("%d\n", i);

    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    
    pair<int, int> lower_left = make_pair(0, 0);
    pair<int, int> upper_right = make_pair(W, H);

    while (N--) {
	int x, y, a;
	cin >> x >> y >> a;
	switch (a) {
	case 1:
	    if (x > lower_left.first) lower_left.first = x;
	    break;
	case 2:
	    if (x < upper_right.first) upper_right.first = x;
	    break;
	case 3:
	    if (y > lower_left.second) lower_left.second = y;
	    break;
	case 4:
	    if (y < upper_right.second) upper_right.second = y;
	    break;
	}
	
	if (upper_right.first <= lower_left.first ||
	    upper_right.second <= lower_left.second) {
	    break;
	}
    }

    int width = upper_right.first - lower_left.first;
    int height = upper_right.second - lower_left.second;
    int area = (width > 0 && height > 0 ? width * height : 0);
    
    cout << area << endl;
    
    return 0;
}


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

bool S[14], H[14], C[14], D[14];
int main() {
	int n; cin >> n;
	rep(i, n) {
		string s; int d; cin >> s >> d;
		if (s == "S")S[d] = true;
		if (s == "H")H[d] = true;
		if (s == "C")C[d] = true;
		if (s == "D")D[d] = true;
	}
	for (int i = 1; i <= 13; i++) {
		if (!S[i])cout << "S " << i << endl;
	}
	for (int i = 1; i <= 13; i++) {
		if (!H[i])cout << "H " << i << endl;
	}
	for (int i = 1; i <= 13; i++) {
		if (!C[i])cout << "C " << i << endl;
	}
	for (int i = 1; i <= 13; i++) {
		if (!D[i])cout << "D " << i << endl;
	}
}

Measured memory_bytes: 3120
s = input()
n = len(s)
box = []

l = 1
for i in range(n-1):
    if s[i+1] == s[i]:
        l += 1
    else:
        box.append(l)
        l = 1
box.append(l)

def sum_(a):
    return (a+1) * a // 2

ans = 0
if s[0] == '>':
    ans += sum_(box[0])
    if (len(box)-1) % 2 == 1:
        ans += sum_(box[-1])
        for i in range(1, len(box)-1, 2):
            if box[i+1] >= box[i]:
                ans += sum_(box[i+1]) + sum_(box[i]-1)
            else:
                ans += sum_(box[i]) + sum_(box[i+1]-1)
    else:
        for i in range(1, len(box)-1, 2):
            if box[i+1] >= box[i]:
                ans += sum_(box[i+1]) + sum_(box[i]-1)
            else:
                ans += sum_(box[i]) + sum_(box[i+1]-1)
else:
    if len(box) % 2 == 1:
        ans += sum_(box[-1])
        for i in range(0, len(box) - 1, 2):
            if box[i + 1] >= box[i]:
                ans += sum_(box[i + 1]) + sum_(box[i] - 1)
            else:
                ans += sum_(box[i]) + sum_(box[i + 1] - 1)
    else:
        for i in range(0, len(box) - 1, 2):
            if box[i + 1] >= box[i]:
                ans += sum_(box[i + 1]) + sum_(box[i] - 1)
            else:
                ans += sum_(box[i]) + sum_(box[i + 1] - 1)

print(ans)


Measured memory_bytes: 6432
s=int(input())
from collections import Counter
cc=Counter()
cc[s]=1
cnt=1
while True:
    if s%2==0:
        s=s/2
    else:
        s=3*s+1
    cnt+=1
    if cc[s]>0:
        print(cnt)
        import sys
        sys.exit()
    cc[s]+=1



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

using namespace std;

int main (void) {
  int n, a;
  cin >> n;
  cin.ignore();
  cin >> a;
  int t;
  t = n % 500;
  if (a - t >= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
//nCr mod m
#define MOD 1000000007
#define M 4000010
vector<ll> fact,inv;
bool h=false;
ll A,B;
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
	inv=vector<ll>(M);
	rep(i,M)inv[i]=powmod(fact[i],MOD-2,MOD);
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 0;//??????
	ll out=fact[n]*inv[r]%m*inv[n-r]%m;
	return out;
}
void f(ll n,ll r,ll m=MOD){
	if(n<0||r<0||n<r){
		A=0;
		return;
	}
	(A*=fact[n])%=MOD;
	(B*=fact[r]*fact[n-r]%MOD)%=MOD;
	return;
}
int main(){
	ll a,b,c,d,e;
	while(cin>>a>>b>>c>>d>>e,a+b+c+d+e){
		ll out=0;
		ll aa=nCr(a+b+c,a),bb=nCr(b+c,b);
		rep(s,d+1){
			A=B=1;
			ll t=e-d+s;
			if(t<0||t>e)continue;
			ll w=1;
			if(s||a){
				f(s-1,a-1);
				(A*=aa)%=MOD;
			}
			if(t||b){
				f(t-1,b-1);
				(A*=bb)%=MOD;
			}
			f(d-s+a+b+c-1,a+b+c-1);
			(out+=A*powmod(B,MOD-2,MOD))%=MOD;
		}
		cout<<out<<endl;
	}
}








Measured memory_bytes: 65292
#include<iostream>
#include<map>
#include<cstring>
#include<vector>
#include<algorithm> 
#define PII pair<int,int>

typedef long long ll;

using namespace std;
int n; 
int main()
{
	string str;
	int k;
	cin>>k;
	cin>>str;
	int len =str.length();
	if(len<=k) {
		cout<<str<<endl;	
		return 0;
	}
	string s;
	s=str.substr(0,k);
	s+="...";
	cout<<s<<endl;
}

Measured memory_bytes: 3596