akhauriyash/Code-Regression huggingface dataset:
def resolve():
    n, m = map(int, input().split())
    xyz = [list(map(int, input().split())) for _ in range(n)]
    #+++
    xyz1 = []
    for i in range(n):
        xyz1.append(xyz[i][0] + xyz[i][1] + xyz[i][2])
    xyz1 = sorted(xyz1, reverse=True)
    sxyz1 = sum(xyz1[:m])

    #++-
    xyz2 = []
    for i in range(n):
        xyz2.append(xyz[i][0] + xyz[i][1] - xyz[i][2])
    xyz2 = sorted(xyz2, reverse=True)
    sxyz2 = sum(xyz2[:m])

    #+-+
    xyz3 = []
    for i in range(n):
        xyz3.append(xyz[i][0] - xyz[i][1] + xyz[i][2])
    xyz3 = sorted(xyz3, reverse=True)
    sxyz3 = sum(xyz3[:m])

    #+--
    xyz4 = []
    for i in range(n):
        xyz4.append(xyz[i][0] - xyz[i][1] - xyz[i][2])
    xyz4 = sorted(xyz4, reverse=True)
    sxyz4 = sum(xyz4[:m])

    # -++
    xyz5 = []
    for i in range(n):
        xyz5.append(-1*xyz[i][0] + xyz[i][1] + xyz[i][2])
    xyz5 = sorted(xyz5, reverse=True)
    sxyz5 = sum(xyz5[:m])

    # -+=
    xyz6 = []
    for i in range(n):
        xyz6.append(-1*xyz[i][0] + xyz[i][1] - xyz[i][2])
    xyz6 = sorted(xyz6, reverse=True)
    sxyz6 = sum(xyz6[:m])

    # --+
    xyz7 = []
    for i in range(n):
        xyz7.append(-1*xyz[i][0] - xyz[i][1] + xyz[i][2])
    xyz7 = sorted(xyz7, reverse=True)
    sxyz7 = sum(xyz7[:m])

    # ---
    xyz8 = []
    for i in range(n):
        xyz8.append(-1*xyz[i][0] - xyz[i][1] - xyz[i][2])
    xyz8 = sorted(xyz8, reverse=True)
    sxyz8 = sum(xyz8[:m])

    print(max(sxyz1, sxyz2, sxyz3, sxyz4, sxyz5, sxyz6, sxyz7, sxyz8))
resolve()

Measured memory_bytes: 39408
import math


res = 0
d_min = 10
for i in range(5):
    dish = int(input())
    if dish % 10 == 0:
        res += dish
    else:
        res += math.ceil(dish / 10) * 10
        if dish % 10 < d_min:
            d_min = dish % 10
res -= 10 - d_min
print(res)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){int N;long long x=1,b=0;cin>>N;long long a[N];
           for(int i=0;i<N;i++){
cin>>a[i];if(a[i]==0)x=0;}
for(int i=0;i<N;i++){b*=a[i];x*=a[i];b+=x/1000000000;x%=1000000000;if(b>1000000000||(b>=1000000000&&x)){x=-1;break;}}
if(x==-1)cout<<"-1"<<endl;else cout<<x+1000000000*b<<endl;}

Measured memory_bytes: 4388
/*
csc -debug A.cs && mono --debug A.exe <<< "3 1
ABC"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var N = cin.NextInt();
        var K = cin.NextInt();
        var S = Console.ReadLine().ToCharArray();
        S[K-1] = char.ToLower(S[K-1]);
        System.Console.WriteLine(string.Join("", S));
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b-a==c-b)
	{
		printf("YES\n");
	}
	if(b-a!=c-b)
	{
		printf("NO\n");
	}
//printf("%d %d",b-a,c-b);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(string, s);
    string ans = "";

    for (char c: s) {
        if (c == 'B') {
            if (!ans.empty()) ans.pop_back();
        } else
            ans += c;
    }

    print(ans);

    return 0;
}


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

void Fibonachi(int F[], int n) {
	F[0] = F[1] = 1;
	for (int i = 2; i <= n; i++) {
		F[i] = F[i - 2] + F[i - 1];
	}
}

int main() {
	int n,F[MAX];
	cin >> n;
	Fibonachi(F,n);
	cout << F[n] << endl;
	return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}






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

int main(){
    int H, W; std::cin >> H >> W;
    int Ch, Cw; std::cin >> Ch >> Cw;
    int Dh, Dw; std::cin >> Dh >> Dw;
    --Ch; --Cw; --Dh; --Dw;
    std::vector<std::string> S(H);
    for(int i(0); i < H; ++i) std::cin >> S[i];
    std::queue<std::pair<int, int>> que;
    std::vector<std::vector<int>> d(H, std::vector<int>(W, INF));
    
    d[Ch][Cw] = 0;
    que.emplace(Ch, Cw);
    for(int k(0); k < 2'000'000; ++k){
        std::set<std::pair<int, int>> cur, nxt;
        while(!que.empty()){
            auto [h, w] = que.front();
            if(h == Dh &&  w == Dw){
                std::cout << d[Dh][Dw]  << std::endl;
                return 0;
            }
            cur.emplace(que.front());
            que.pop();
            {
                int nh, nw;
                for(int i(0); i < 4; ++i){
                    nh = h + dx[i]; nw = w + dy[i];
                    if(nh < 0 || H <= nh || nw < 0 || W <= nw || S[nh][nw] == '#') continue;
                    if(chmin(d[nh][nw], d[h][w])){
                        que.emplace(nh, nw);
                        cur.emplace(nh, nw);
                        if(nh == Dh &&  nw == Dw){
                            std::cout << d[Dh][Dw]  << std::endl;
                            return 0;
                        }
                    }
                }
            }
        }

        for(auto [a, b]: cur){
            int nh, nw;
            for(int i(-2); i <= 2; ++i){
                for(int j(-2); j <= 2; ++j){
                    nh = a + i; nw = b + j;
                    if(nh < 0 || H <= nh || nw < 0 || W <= nw || S[nh][nw] == '#') continue;
                    if(chmin(d[nh][nw], k + 1)){
                        if(nxt.find({nh, nw}) == std::end(nxt)){
                            que.emplace(nh, nw);
                        }
                        nxt.emplace(nh, nw);
                    }
                }
            }
        }
    }
   
    std::cout << (d[Dh][Dw] != INF ? d[Dh][Dw] : -1) << std::endl;
    return 0;
}


Measured memory_bytes: 10056
using System;

namespace AltCoder
{
    public sealed class F_LCS
    {
        public static void Main()
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            string lcs = LCS(s, t);
            Console.WriteLine(lcs);
        }

        private static string LCS(string s, string t)
        {
            char[] a = s.ToCharArray();
            char[] b = t.ToCharArray();

            int[,] c = new int[a.Length + 1, b.Length + 1];
            int length = LCSLength(a, b, c);

            string result = backTrack(c, a, b, a.Length, b.Length);
            return result;
        }

        private static int LCSLength(char[] a, char[] b, int[,] c)
        {
            for (int i = 0; i <= a.Length; i++)
            {
                for (int j = 0; j <= b.Length; j++)
                {
                    if (i == 0 || j == 0)
                    {
                        c[i, j] = 0;
                    }

                    else if (a[i - 1] == b[j - 1])
                    {
                        c[i, j] = 1 + c[i - 1, j - 1];
                    }

                    else
                    {
                        c[i, j] = Math.Max(c[i - 1, j], c[i, j - 1]);
                    }
                }
            }

            return c[a.Length, b.Length];
        }

        private static string backTrack(int[,] c, char[] a, char[] b, int i, int j)
        {
            if (i == 0 || j == 0)
            {
                return string.Empty;
            }

            if (a[i - 1] == b[j - 1])
            {
                return backTrack(c, a, b, i - 1, j - 1) + a[i - 1];
            }

            else if (c[i, j - 1] > c[i - 1, j])
            {
                return backTrack(c, a, b, i, j - 1);
            }

            else
            {
                return backTrack(c, a, b, i - 1, j);
            }
        }
    }
}


Measured memory_bytes: 50136
n = int(input())
from collections import namedtuple
Task = namedtuple('Task',('time','limit'))
tasks=[]
import operator
for _ in range(n):
    tasks.append(Task(*map(int, input().split())))
tasks.sort(key=operator.attrgetter('limit'))

total=0
for task in tasks:
    total+=task.time
    if total > task.limit:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 33944
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll R) {
  if (R < 1200){
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}

int main() {
  ll R;
  cin >> R;
  solve(R);
  return 0;
}


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

int main(){
  string n;
  cin >> n;
  
  if(n[0] == n[1] && n[1] == n[2]){
    cout << "Yes" << endl;
  }
  else if(n[1] == n[2] && n[2] == n[3]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
numbers = list(map(int,input().split()))

def trace(numbers):
  a = str(numbers[0])
  for i in range(1,len(numbers)):
    a += " "
    a += str(numbers[i])
  print(a)

trace(numbers)
for current_i in range(1,N):
  for compare_i in range(current_i-1,-1,-1):

    if(numbers[compare_i] > numbers[current_i]):
      hoge = numbers[compare_i]
      numbers[compare_i] = numbers[current_i]
      numbers[current_i] = hoge

      current_i = compare_i
  trace(numbers)





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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

signed main()
{
    ll N;
    cin >> N;
    vector<string> S(N);
    ll AC = 0,WA = 0,TLE = 0,RE = 0;
    REP(i,N){
        cin >> S.at(i);
        if(S.at(i)=="AC"){
            AC++;
        }else if(S.at(i)=="WA"){
            WA++;
        }else if(S.at(i)=="TLE"){
            TLE++;
        }else if(S.at(i)=="RE"){
            RE++;
        }
        /*
        switch(S.at(i))
        {
            case "AC" :
                AC++;
                break;
            case "WA" :
                WA++;
                break;
            case "TLE" :
                TLE++;
                break;
            case "RE" :
                RE++;
                break;
            default:
                break;
        }
        */
    }
    cout << "AC x "+to_string(AC)+"\nWA x "+to_string(WA)+"\nTLE x "+to_string(TLE)+"\nRE x "+to_string(RE);
}


Measured memory_bytes: 6424
#include<iostream>
#include<cmath>
#define PI 3.141592653589793
using namespace std;
int main(){
	char z;
	int a;
	double b;
	int i,j,k;
	double x=0,y=0;
	double d=0;
	while(cin>>a>>z>>b){
		if(a==0)break;
		x+=(double)a*cos(d/180.0*PI);
		y+=(double)a*sin(d/180.0*PI);
		d+=b;
	}
	cout<<(int)y<<endl;
	cout<<(int)x<<endl;
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <math.h>
#include <algorithm>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;
 
int main(){
  int a;
  cin >> a;

  cout << a*(1+a*(1+a)) << endl;
 
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<double> a(n);
    rep(i, n) cin >> a[i];
    double ue=1;
    double sita = 0;
    rep(i, n) ue *= a[i];
    rep(i, n) sita += ue / a[i];
    printf("%lf\n",ue / sita);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 123456789012

int main(){
    ll i,j;
    ll n;
    cin>>n;
    ll m=n-n/2;
    cout<<fixed<<setprecision(15)<<double(m)/n<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdlib.h>

using namespace std;

int top, S[1000];

void push(int x) {
	/*topを加算してからその位置へ挿入*/
	S[++top] = x;
}

int pop() {
	top--;
	/*topが指していた要素を返す*/
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];
	while (cin>>s) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		
		}	else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b-a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a*b);
		}

		else {
			push(atoi(s));
		}
	}
	cout << pop() << endl;
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    int cnt1=0,cnt2=0;
    for(int i=0;i<3;i++){
        if(s[i]=='A') cnt1++;
        else cnt2++;
    }
    if(cnt1==2||cnt2==2) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <unordered_map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n;
    cin >> n;

    unordered_map<string,int> shiritori_log;
    char last_letter;
    string tmp;
    REP(i,n){
        cin >> tmp;
        if(i>0&&last_letter!=tmp[0]){
            cout << "No" << endl;
            return 0;
        }
        shiritori_log[tmp]++;
        if(shiritori_log[tmp]>1){
            cout << "No" << endl;
            return 0;
        }
        last_letter = tmp[tmp.size() - 1];

    }

    cout << "Yes" << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int inf = (1<<28);
const ll infl = (1LL<<60);
const int mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (t == 0) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint &operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
vector<mint> fac;

void init(int n) {
  fac.assign(n+1,1);
  for (int i = 0; i < n; i++) {
    fac[i+1] = fac[i] * mint(i+1);
  }
}

mint ncr(int n, int r) {
  mint N(n);
  return fac[n] / fac[n-r] / fac[r];
}

mint nhr(int n, int r) {
  return ncr(n+r-1, r);
}

int main() {
  int n, k; cin >> n >> k;
  init(n);
  mint ans(1);
  for (int i = 1; i <= min(n-1, k); i++) {
    ans += ncr(n,i) * nhr(n-i,i);
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <set>
#include <set>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
#include <cmath>
#include <sstream>
#include <cstdlib>
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0x3f3f3f3f;
	for (int p = 1; p <= 100; p++) {
		int tmp = 0;
		for (int i = 0; i < n; i++) {
			tmp += (p - a[i]) * (p - a[i]);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define int long long

const int N = 1e8 + 10;

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int k;
  cin >> k;
  int x = 7 % k;
  for (int i = 0; i < N; ++i) {
    if (x) 
    {
      x *= 10;
      x += 7;
      x %= k;
      continue;
    }
    cout << i + 1;
    return 0;
  }
  cout << -1;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

ll p[51], w[51];

ll rec(ll n, ll x)
{
	if (n == 0) return (x>0)?1:0;
	x--;
	if (x <= w[n-1]){
		return rec(n-1, x);
	}else{
		return p[n-1]+1+rec(n-1, x-w[n-1]-1);
	}
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, x; cin>>n>>x;
	p[0] = 1, w[0] = 1;
	rep(i, n){
		p[i+1] = 2*p[i]+1;
		w[i+1] = 2*w[i]+3;
	}
	ll ans=0;
	cout << rec(n, x) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include <functional>
#include <limits>


using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

template<typename T>
class segment_tree{
	int n;
	T fval;
	function<T(T,T)> operation;
	vector<T> dat;
	
	T _query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l){
			return fval;
		}
		
		if(a <= l && r <= b){
			return dat[k];
		}else {
			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2 );
			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
			return operation(vl, vr);
		}
	}
	
public:
	
	segment_tree(){
		
	}
	
	segment_tree(int n_, T val, function<T(T,T)> fun){
		init(n_, val, fun);
	}
	
	~segment_tree(){
		
	}
	
	void init(int n_, T val, function<T(T,T)> fun){
		fval = val;
		
		operation = fun;
		
		n = 1;
		
		while(n < n_) n *= 2;
		
		dat.resize(2 * n - 1);
	
		for(int i = 0; i < 2 * n - 1; i++) dat[i] = fval;
	}

	void update(int k, T a){
		k += n - 1;
		dat[k] = a;
		while(k > 0){
			k = (k - 1) / 2;
			dat[k] = operation(dat[k*2 + 1],dat[k*2 + 2]);
		}
	}
	
	T query(int a, int b){
		return _query(a, b, 0, 0, n);
	}
	
};


signed main(){
	// cin.tie(nullptr);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N, Q;
	string S;
	vector<segment_tree<signed>> seg(26);
	
	cin>>N;
	cin>>S;
	cin>>Q;
	
	for(int i = 0; i < 26; i++){
		
		seg[i].init(N+101,0, [](int first, int second){ return (first+second);});
	}
	
	for(int i = 0; i < N; i++){
		
		seg[S[i] - 'a'].update(i, 1);
	}
	// cout<<seg[3].query(0, 6+1)<<" "<<3<<endl;
	
	for(int i = 0; i < Q; i++){
		int a, b;
		// cout<<"i = "<<i<<endl;
		
		cin>>a>>b;
		
		 b--;
		
		if(a == 1) { //cout<<"[][]"<<"b = "<<b<<endl;
			char c;
			
			cin>>c;
			
			seg[S[b] - 'a'].update(b, 0);
			seg[c - 'a'].update(b, 1);
			
			
			S[b] = c;
			
		} else {
			int r;
			cin>>r;
			r--;
			int con = 0;
			// cout<<S<<endl;
			// cout<<"r = "<<r<<endl;
			for(int j = 0; j < 26; j++){
				// cout<<seg[j].query(b, r+1)<<" "<<j<<endl;
				if(seg[j].query(b, r+1) >= 1) con++;
			}
			
			cout<<con<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 107524
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
x=0
onds=[]
while x<=n-1:
 onds.append(abs(t-0.006*h[x]-a))
 x+=1
m=min(onds)
x=0
while x<=n-1:
 if onds[x]==m:
  print(x+1)
  x+=1
 else:
  x+=1
  
 

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

int main() {
	int n;
	cin >> n;
	string s = to_string(n);
	int l = s.size();
	int sn = 0;
	rep(i, l) {
		sn += s[i] - '0';
	}
	if (n % sn == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

string s;
int p;

ll A[200][300];
int idx;

ll bnf();

ll get_num(){

  if(s[p]=='('){
    
    p++;

    ll res=bnf();
    
    p++;

    return res;
  }
  
  if('a'<=s[p]&&s[p]<='z') return A[idx][s[p++]];
  
  ll num=0;
  
  while('0'<=s[p]&&s[p]<='9') num=num*10+s[p]-'0', p++;

  return num;
  
}

ll bnf3(){

  ll res=get_num();
  
  while(p<s.size()){

    if(s[p]=='^'){

      p++;

      ll r=get_num();

      ll tmp=1;

      for(int i=0;i<r;i++) tmp*=res;

      res=tmp;
      
    }else break;
    
  }
  
  return res;
}

ll bnf2(){

  ll res=bnf3();

  while(p<s.size()){

    if(s[p]=='*'){

      p++;

      ll r=bnf3();
      
      res*=r;
      
    }else break;
    
  }
  
  return res;
}

ll bnf(){

  ll res=bnf2();
  
  while(p<s.size()){
    
    if(s[p]=='+'){

      p++;
      
      ll r=bnf2();
      
      res+=r;
      
    }
    else if(s[p]=='-'){

      p++;

      ll r=bnf2();

      res-=r;
      
    }else break;
    
  }
  
  return res;
}

void change(){
  
  for(int i=0;i<s.size();i++)
    if((s[i]==')'||('a'<=s[i]&&s[i]<='z')||('0'<=s[i]&&s[i]<='9')))
      if((s[i+1]=='('||('a'<=s[i+1]&&s[i+1]<='z')||('0'<=s[i+1]&&s[i+1]<='9')))
	if(!('0'<=s[i]&&s[i]<='9'&&'0'<=s[i+1]&&s[i+1]<='9'))
	  s=s.substr(0,i+1)+'*'+s.substr(i+1);

  
  for(int i=0;i<s.size();i++)
    
    if(s[i]==' ')
      
      while(s[i]==' '&&i+1<s.size()&&s[i+1]==' ') s.erase(s.begin()+i);
  

  if(s[0]==' ') s.erase(s.begin());
  
  if(s[s.size()-1]==' ') s.erase(s.begin()+s.size()-1);

  for(int i=0;i<s.size();i++)
    if(s[i]==' ')
      if((s[i-1]==')'||('a'<=s[i-1]&&s[i-1]<='z')||('0'<=s[i-1]&&s[i-1]<='9')))
	if((s[i+1]=='('||('a'<=s[i+1]&&s[i+1]<='z')||('0'<=s[i+1]&&s[i+1]<='9'))) s[i]='*';

  for(int i=0;i<s.size();i++)
    
    if(s[i]==' ') s.erase(s.begin()+i), i--;
  
  
}

int main(){
  
  for(int T=0;T<200;T++)
    
    for(int i=0;i<300;i++) A[T][i]=rand();
  
  while(1){

    string tmp=s;
    
    getline(cin,s);
    
    if(s==".") break;
    
    change();
    
    ll base[200];

    for(int T=0;T<200;T++){
      idx=T;
      p=0;
      base[T]=bnf();
    }
    
    while(1){
      
      getline(cin,s);
      
      if(s=="."){
	cout<<"."<<endl;
	break;
      }
      
      change();
      
      bool ans=true;
      
      for(int T=0;T<200;T++){
          
	idx=T;  
	p=0;
      
	ll r=bnf();
	
	if(base[T]!=r) ans=false;
	
      }
      
      if(ans) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
      
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 3632
from collections import deque

N, X, Y = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N-1):
    adj[i].append(i+1)
    adj[i+1].append(i)

adj[X-1].append(Y-1)
adj[Y-1].append(X-1)

dist = [[-1]*N for _ in range(N)]

for i in range(N):
    queue = deque([i])
    dist[i][i] = 0

    while queue:
        now = queue.popleft()
        for u in adj[now]:
            if dist[i][u] < 0:
                queue.append(u)
                dist[i][u] = dist[i][now] + 1

ans = [0] * (N-1)
for i in range(N):
    for j in range(i+1,N):
        ans[dist[i][j]-1] += 1

[print(a) for a in ans]

Measured memory_bytes: 101420
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int main(){
    int n,m;
    while(cin>>n>>m){
        if(n==0&&m==0)break;
        vector<int> v(n);
        rep(i,0,n)cin>>v[i];
        int ans=-1;
        rep(i,0,n){
            rep(j,i+1,n){
                if(ans<v[i]+v[j] && v[i]+v[j]<=m)ans=v[i]+v[j];
            }
        }
        if(ans==-1)cout<<"NONE"<<endl;
        else cout<<ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3060
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
int a[MAXN];
ll b[MAXN];
int n;
ll ans = INF;

ll sum(int l, int r)
{
    ll ret = b[r];
    if (l > 0)
        ret -= b[l - 1];
    return ret;
}

ll ma(ll e,ll f,ll g, ll h)
{
    return max(max(e,f),max(g,h));
}

ll _min(ll e,ll f,ll g, ll h)
{
    return min(min(e,f),min(g,h));
}

pair<ll,ll> f(int x, int y)
{
    pair<ll,ll> ret = {INF,INF};
    ll di = INF;
    ll lo = x, hi = y - 1;
    while (lo <= hi)
    {
        ll m1 = lo + (hi - lo) / 3;
        ll m2 = hi - (hi - lo) / 3;
        ll s1 = abs(sum(x, m1) - sum(m1 + 1, y));
        ll s2 = abs(sum(x, m2) - sum(m2 + 1, y));
        if (s1 < s2)
            hi = m2 - 1;
        else if (s2 < s1)
            lo = m1 + 1;
        else
            lo = m1 + 1, hi = m2 - 1;
        if (s1 < di)
            ret = {sum(x, m1), sum(m1 + 1, y)}, di = s1;
        if (s2 < di)
            ret = {sum(x, m2), sum(m2 + 1, y)}, di = s2;
    }
    if (ret.fi > ret.se)
        swap(ret.fi, ret.se);
    return ret;
}

int main()
{
    ni(n);
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        ni(a[i]);
        sum += (ll) a[i];
        if (i)
            b[i] = b[i - 1] + a[i];
        else
            b[i] = a[i];
    }
    for (int i = 1; i < n - 2; i++)
    {
        pair<ll,ll> l = f(0, i);
        pair<ll,ll> r = f(i + 1, n - 1);
        ans = min(ans, ma(l.fi,l.se,r.fi,r.se) - _min(l.fi,l.se,r.fi,r.se));
        ans = min(ans, ma(l.fi,l.se,r.fi,r.se) - _min(l.fi,l.se,r.fi,r.se));
    }
    prl(ans);
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		int total = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			total += A[i];
		}
		sc.close();
		Arrays.sort(A);
		for(int i = N - 1; i > N - M - 1; i--) {
			if(total <= 4 * M * A[i] && i == N - M) {
				System.out.println("Yes");
				break;
			}
			if(total > 4 * M * A[i]){
				System.out.println("No");
				break;
			}
		}
	}
}


Measured memory_bytes: 22740
N=int(input())
S=[input() for i in range(N)]
G=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j]=="1":
            G[i].append(j)
q=[0]
dist=[-1 for i in range(N)]
dist[0]=0
while(q):
    r=q.pop()
    for p in G[r]:
        if dist[p]==-1:
            dist[p]=1-dist[r]
            q.append(p)
for i in range(N):
    for j in G[i]:
        if dist[i]==dist[j]:
            print(-1)
            exit()
#possible
#print(G)
d=[[10**9 for i in range(N)] for i in range(N)]
for i in range(N):
    for j in G[i]:
        d[i][j]=1
    d[i][i]=0

for k in range(N):
    for i in range(N):
        for j in range(N):
            if d[i][j]>d[i][k]+d[k][j]:
                d[i][j]=d[i][k]+d[k][j]
ans=2
for i in range(N):
    for j in range(N):
        ans=max(ans,d[i][j]+1)
print(ans)


Measured memory_bytes: 44172
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int b = a/100;
  int c = a%100/10;
  int d = a%10;
  int count = 0;
  if (b == 1) count++;
  if (c == 1) count++;
  if (d == 1) count++;
  cout << count << endl;
}
  

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

using namespace std;

bool joisino[10];
bool f[100][10];
int p[100][11];
int n;
long long mx = -10000000000;

void search(int x) {
  if(x == 10) {
    bool notopen = true;
    for(int i = 0; i < 10; i++) {
      if(joisino[i]) {
	notopen = false;
      }
    }
    if(notopen) {
      return;
    }
    long long profit = 0;
    for(int i = 0; i < n; i++) {
      int count = 0;
      for(int j = 0; j < 10; j++) {
	if(joisino[j] && f[i][j]) {
	  count++;
	}
      }
      profit += p[i][count];
    }
    mx = max(mx, profit);
    return;
  }

  joisino[x] = true;
  search(x + 1);
  joisino[x] = false;
  search(x + 1);
}

int main(void) {
  cin >> n;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 10; j++) {
	cin >> f[i][j];
    }
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  for(int i = 0; i < 10; i++) {
    joisino[i] = false;
  }

  search(0);
  
  cout << mx << endl;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0;i<n;i++)
    {
        cin >> a[i];
    }
    int dp[n];
    for (int i = 0;i<n;i++)
    {
        dp[i] = 2147483647;
    }

    dp[0]=0;

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

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

}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
#define mp make_pair

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=;



int main(){
	int N;
	cin>>N;
	int a[50];
	rep1(i,N)cin>>a[i];
	
	int pmx=0;
	int pind=1;
	int nmn=0;
	int nind=1;
	rep1(i,N){
		if(a[i]>=pmx){
			pmx=a[i];
			pind=i;
		}
		if(a[i]<=nmn){
			nmn=a[i];
			nind=i;
		}
	}
	vi x, y;
	if(pmx>=-nmn){
		rep1(i,N)if(a[i]<0){
			a[i]+=pmx;
			x.push_back(pind);
			y.push_back(i);
		}
		rep1(i,N-1)if(a[i]>a[i+1]){
			a[i+1]+=a[i];
			x.push_back(i);
			y.push_back(i+1);
		}
	}
	else{
		rep1(i,N)if(a[i]>0){
			a[i]+=nmn;
			x.push_back(nind);
			y.push_back(i);
		}
		for(int i=N-1; i>0; i--)if(a[i]>a[i+1]){
			a[i]+=a[i+1];
			x.push_back(i+1);
			y.push_back(i);
		}
	}
	int ct=sz(x);
	cout<<ct<<endl;
	rep(i,ct)cout<<x[i]<<" "<<y[i]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
#define mp make_pair
using namespace std;
int n,x,y,a[200005];
int main(){
	string s;
	cin>>s;
	int ans=1;
	bool bad=0;
	for(int i=1;i<s.size();++i){
		if(s[i]==s[i-1] and !bad)++i,bad=1;
		else bad=0;
		if(i==s.size())break;
		++ans;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int H, W;
char s[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };


bool judge(int i, int j){
    rep(k, 0, 4){
        int Y = i + dy[k];
        int X = j + dx[k];
        if(!(0 <= Y && Y < H && 0 <= X && X < W)) continue;
        if(s[Y][X] == '#') return false;
   }
   return true;
}


bool solve(){
    rep(i, 0, H){
        rep(j, 0, W){
            if(s[i][j] == '.') continue;
            if(judge(i, j)) return false;
        }
    }
    return true;
}


signed main(){
    cin >> W >> H;
    rep(i, 0, H)
        rep(j, 0, W) cin >> s[i][j];

    if(solve()) Yes;
    else No;

    return 0;
}

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

using namespace std;

int main()
{
    double a, b, d, r, f;
    cin >> a >> b;

    d = a / b;

    r = fmod(a, b);

    f = a / b;

    cout << int(d) << " " << r << " " << fixed << setprecision(6) << f << endl;
}


Measured memory_bytes: 3328
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int[]A=new int[N];
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
        }
        int a=0;
        out:for(;;){
        for(int i=0;i<N;i++){
            if(A[i]%2==1){
                break out;
            }
            A[i]=A[i]/2;
            if(i==N-1){
                a++;
            }
        }}
        System.out.println(a);


}
        
        
    }


Measured memory_bytes: 21972
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MAX = 24 * 60 * 60 + 100;
int f(int h, int m, int s) {
  return h * 3600 + m * 60 + s;
}
int main()
{
  int n;
  int imos[MAX];
  while(cin>>n,n) {
    int ans = 0;
    CLR(imos);
    FOR(i,0,n) {
      int h1, m1, s1;
      int h2, m2, s2;
      scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
      imos[f(h1,m1,s1)]++;
      imos[f(h2,m2,s2)]--;
    }
    FOR(i,0,MAX-1) {
      imos[i+1] += imos[i];
      ans = max(ans, imos[i+1]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3552
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt()
  val Base = 1000000007

  def expMod(base:Long, exponent:Long, mod:Long):Long = {
    require(base >= 0,     "Base must not be negative. Base="+base)
    require(exponent >= 0, "Exponent must not be negative. Exponent="+exponent)
    require(mod > 1, "Modulo must be grater than 1. Modulo="+mod)
    def iter(b:Long, e:Long, p:Long):Long = {
      (e, e & 1) match {
        case (0, _) => p
        case (_, 0) => iter((b*b) % mod, e >> 1, p % mod)
        case (_, _) => iter((b*b) % mod, e >> 1, (b*p) % mod)
      }
    }

    iter(base, exponent, 1)
  }

  println(expMod(K,N,Base))

}


Measured memory_bytes: 45160
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int h,a;cin>>h>>a;
    int ans=h/a;
    if(h%a!=0)ans++;
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 256
n,c=map(int,input().split())
x=[0]
v=[0]
su=[0]*(n+1)
for i in range(n):
    xx,vv=map(int,input().split())
    x.append(xx)
    v.append(vv)
    su[i+1]=su[i]+v[i+1]
lmax=[0]*(n+2)
rmax=[0]*(n+2)
for i in range(n):
    lmax[i+1]=max(lmax[i],su[i+1]-x[i+1])
    rmax[n-i]=max(rmax[n-i+1],(su[n]-su[n-i-1])-(c-x[n-i]))
ans=0
for i in range(n):
    ans=max(ans,su[i+1]-2*x[i+1]+rmax[i+2])
    ans=max(ans,(su[n]-su[n-i-1])-2*(c-x[n-i])+lmax[n-i-1])
ans = max(ans, max(lmax[n],rmax[1]))
print(ans)

Measured memory_bytes: 30152
#include <bits/stdc++.h>
using namespace std;
 
 
int main()
{
 
    int64_t a,b,n;
    cin>>a>>b>>n;

    int64_t wk=min(b-1,n);
    cout<<floor(a*wk/b)-a*floor(wk/b)<<endl;


    return 0;
}   

Measured memory_bytes: 3792
n = int(input())
w = [input() for _ in range(n)]
e = []
for i in range(n):
    if i == 0:
        e.append(w[i])
    else:
        cw = w[i]
        lw = w[i-1]
        if cw[0] != lw[-1] or cw in e:
            print("No")
            exit()
        else:
            e.append(cw)
print("Yes")


Measured memory_bytes: 3060
#pragma GCC optimize "trapv"
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1000000007;
#define inf 1000000000
#define pb push_back
#define fs first
#define sc second
#define forn(i,k,n) for(int i = k; i < n; ++i)
#define nfor(i,n,k) for(int i = n; i >= k; --i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define vvpii vector<vector<pait<int,int>>>
#define all(arr) arr.begin(), arr.end()
#define endl '\n'
#define dbgarr(V,n) forn(i,0,n) cout << V[i] << " "; cout << endl;
#define dbgarrrev(V,n) nfor(i,n,0) cout << V[i] << " "; cout << endl;
#define dbgmaze(V) for(auto x: V) {for(auto y : x) cout << y <<  " ";cout << endl;}
#define dbg2d(V,n,m) forn(i,0,n) {forn(j,0,m) cout << V[i][j] <<  " ";cout << endl;}
void solve(){
	int n, k; cin >> n >> k;
	vector<int> arr(n); forn(i,0,n) cin >> arr[i];
	int low = 1, high = *max_element(all(arr)) + 100;
	ll sum = 0;
	sum = accumulate(all(arr),sum);
	int ans = inf;//k++;
	while(low <= high){
		int mid = (low + high) / 2;
		//cout << mid << " " << endl;
		int steps = 0;
		forn(i,0,n){
			if(arr[i] > mid){
				steps += arr[i] / mid;
			}
		}
		if(steps > k){
			low = mid + 1;
		}
		else{
			ans = mid;
			high = mid - 1;
		}
	}
	cout << ans << endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	solve();
    return 0;
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 100001;
ll m,n,x[N],y[N],ans=0,xs=0,ys=0,xad[N],yad[N];


int main(){
	cin>>n>>m;
	FOR(i,0,n)cin>>x[i+1];
	FOR(i,0,m)cin>>y[i+1];
	xad[n]=x[n];
	yad[m]=y[m];
	for(ll i=n-1;i>=1;i--){
		xad[i]=x[i]+xad[i+1];
	}
	for(ll i=m-1;i>=1;i--){
		yad[i]=y[i]+yad[i+1];
	}

	FOR(i,1,n+1){
		xs+=xad[i]-x[i]*(n-i+1);
		xs%=INF;
	}
	FOR(i,1,m+1){
		ys+=yad[i]-y[i]*(m-i+1);
		ys%=INF;
	}
	cout<<(xs*ys)%INF<<endl;
	return 0;
}

Measured memory_bytes: 3328