akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int MAXN=3e5+5;

int len,anc[30][MAXN],S,T,num,p[MAXN];
ll l,r;
char s[MAXN];

ll calc(ll lt,int n){
	if(lt<=len)return anc[n][lt];
	if(lt<=2*len)return anc[n][len]+anc[n][lt-len];
	ll f1=anc[n][S],f2=anc[n][len],lenf1=S,lenf2=len;
	while(lt>lenf1+lenf2){
		ll tem2=f2,lentem2=lenf2;
		f2+=f1;lenf2+=lenf1;
		f1=tem2;lenf1=lentem2;
	}
	return f2+calc(lt-lenf2,n);
}

int main(){
	scanf("%s",s+1);
	scanf("%lld%lld",&l,&r);
	len=strlen(s+1)/2;
/*	bool ok=0;
	for(int i=2*len;;i--){
		int tmp=i;num=1;
		while(s[num]==s[tmp]){
			num++;tmp++;
			if(tmp==2*len+1){
				ok=1;
				break;	
			}
		}
		if(ok){num--;break;}
	}	*/
	p[1] = 0;
    for (int j = 0, i = 2; i <= len; i ++) {
        for (; j && s[j + 1] != s[i];) j = p[j];
        if (s[j + 1] == s[i]) j ++;
        p[i] = j;
    }
//	T=num;
//	S=len-num;
	S=len-p[len];
	for(int i=1;i<=26;i++){
		for(int j=1;j<=len;j++){
			anc[i][j]=anc[i][j-1];
			if((int)s[j]-96==i)anc[i][j]++;
		}
	}
//	cout<<calc(43200,1);
	for(int i=1;i<=26;i++){
		printf("%lld ",calc(r,i)-calc(l-1,i));
	}
	return 0;
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  int ans=0;
  if(n<=k)
  {
 	ans=1;
  }
  else
  {
    if(n%k==0)
    {
      ans=n/k;
    }
    else
    {
      ans=n/k +1;
    }
  }
  cout<<ans<<endl; 
}

Measured memory_bytes: 256
while 1:
	a,type = raw_input().split()
	if type == "X": break
	ans = ""
	if type == "U":
		for word in a.split("_"):
			ans += word[0].upper() + word[1:]
	elif type == "L":
		for word in a.split("_"):
			ans += word[0].upper() + word[1:]
		ans = ans[0].lower() + ans[1:]
	else:
		if "_" not in a:
			words = []
			sp = 0
			for i in range(1,len(a)):
				if a[i].isupper() :
					words.append(a[sp:i].lower())
					sp = i
			words.append(a[sp:].lower())
			ans = "_".join(words)
		else:
			ans = a
	print ans

Measured memory_bytes: 4236
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int x = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i]<'0' || '9'<s[i]) continue;
		x *= 10;
		x += s[i]-'0';
	}

	cout << (x <= 20190430?"Heisei":"TBD") << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/
ll a, b, c, d;
/******* define variable end *******/
int solve() {
	cin >> a >> b >> c >> d;
	bool flag = true;
	ll count = 0;
	while(flag){
		if(count % 2 == 0){
			c -= b;
		}else{
			a -= d;
		}
		if(a <= 0 || c <= 0){
			flag = false;
		}
		count++;
	}
	if(a <= 0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
long long n,x,a[100010],s;
int main()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]+a[i+1]>=x)
		{
			s+=a[i]+a[i+1]-x;
			a[i+1]=a[i+1]-(a[i]+a[i+1]-x);
		}
	 } 
	cout<<s<<"\n";
	return 0;
 } 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[21],b[21],c[20],s=0;
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	for(int i=1;i<=n-1;i++) scanf("%d",&c[i]);
	for(int i=1;i<=n;i++)
	{
		s+=b[a[i]];
		if(i>1&&a[i]==a[i-1]+1) s+=c[a[i-1]];
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
def main():
    arg = input()
    arg = arg.split()
    a = int(arg[0])
    b = int(arg[1])
    c = int(arg[2])
    bells = [a, b, c]
    bells.sort()
    print(bells[0] + bells[1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
string s;
ll sum[30303][11];
bool used[11][11]; // 00*~99*
set<string> st;
int main(){
    cin>>n>>s;

    // CumSum
    RREP(i, 0, n){
        REP(j, 0, 10){
            sum[i][j]=sum[i+1][j];
        }
        sum[i][s[i]-'0']++;
    }


//    REP(j, 0, 10){
//        REP(i, 0, n){
//            cout<<sum[i][j]<<" ";
//        }
//        cout<<endl;
//    }

    // i=1~n
    REP(i, 0, n-2){
        REP(j, i+1, n-1){
            ll first=s[i]-'0';
            ll second=s[j]-'0';
            if(used[first][second]) continue;

            used[first][second]=true;
            REP(k, 0, 10){
                if(sum[j+1][k]>0){
                    string tmp=s.substr(i, 1)+s.substr(j, 1)+to_string(k);
                    st.insert(tmp);
                }
            }
        }
    }

    cout<<st.size()<<endl;
    return 0;
}

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

#define int long long

const int N=1e9+7;

int32_t main(){

      int n,m;
      cin>>n>>m;

      char a[n][m];
      int dp[n][m];

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

      memset(dp,0,sizeof(dp));

      int f1=1,f2=1;

      for(int i=n-1;i>=0;i--){
         for(int j=m-1;j>=0;j--){
            if(i==n-1||j==m-1){
               if(a[i][j]=='.'){
                  if(i==n-1&&f1)
                     dp[i][j]=1;
                  else if(j==m-1&&f2)
                     dp[i][j]=1;
               }
               else if(a[i][j]=='#'){
                  if(i==n-1)
                     f1=0;
                  else if(j==m-1)
                     f2=0;
               }
            }
            else if(a[i][j]=='.'){
               if(a[i+1][j]=='.'&&a[i][j+1]=='.')
                  dp[i][j]=dp[i+1][j]+dp[i][j+1];
               else if(a[i+1][j]=='.')
                  dp[i][j]=dp[i+1][j];
               else if(a[i][j+1]=='.')
                  dp[i][j]=dp[i][j+1];
            }

            dp[i][j]%=N;

         }
      }

      cout<<dp[0][0]%N;

   
}


Measured memory_bytes: 9088
n=int(input())
s={}
for i in range(n):
    ss=list(input())
    ss.sort()
    ss=tuple(ss)
    try:
        s[ss]+=1
    except:
        s[ss]=1
tot=0
for i in s:
    if s[i]>1:
        tot+=(s[i]*(s[i]-1))//2
print(tot)
    


Measured memory_bytes: 23652
n = int(input())
left = []
mid = []
midminus = []
right = []
L = []
R = []

for i in range(n):
    s = input()
    l = 0
    r = 0
    for x in s:
        if x == '(':
            l += 1
        else:
            if l > 0:
                l -= 1
            else:
                r += 1
    if l > 0 and r == 0:
        left.append((l, r))
    elif l > 0 and r > 0:
        if l > r:
            mid.append((r, l))  # a,b-a
        else:
            midminus.append((r,l))
    elif l == 0 and r > 0:
        right.append((l, r))
    L.append(l)
    R.append(r)

if sum(L) != sum(R):
    print('No')
    exit()

A = 0
B = 0
for x in left:
    A += x[0]
for x in right:
    B += x[1]

mid = sorted(mid, key=lambda x: (x[0],-x[1]))
midminus = sorted(midminus,key= lambda x:x[0]-x[1])
mid += midminus

l = A
r = 0
for a, b in mid:
    if l < a:
        print('No')
        exit()
    l -= a
    l += b

print('Yes')

Measured memory_bytes: 181276
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL cnt[8];
LL tot1 = 0,tot2 = 0;

int main(){
	for(LL i = 1;i <= 7;i ++) cin >> cnt[i];
	tot2 += (cnt[2] << 1) + ((cnt[1] >> 1) << 2) + ((cnt[4] >> 1) << 2) + ((cnt[5] >> 1) << 2);
	if(cnt[1] && cnt[4] && cnt[5]){
		cnt[1] --; cnt[4] --; cnt[5] --;
		tot1 = 6;
		tot1 += (cnt[2] << 1) + ((cnt[1] >> 1) << 2) + ((cnt[4] >> 1) << 2) + ((cnt[5] >> 1) << 2);
	}
	cout << (max(tot1,tot2) >> 1) << endl;
	return 0;
}
//

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
     
int main() {
  int N;
  std::cin >> N;
     
  std::cout << "?";
  for(int i = 0; i < N; i++){
    std::cout << " " << i + 1;
  }
  std::cout << std::endl;

  std::string s1;
  std::cin >> s1;
     
  int l = 0;
  int r = N;
  while(r > l+1) {
    int m = (l + r) / 2;
     
    std::cout << "?";
    for(int i = 0; i < N; i++){
      std::cout << " " << m + i + 1;
    }
    std::cout << std::endl;
     
    std::string s2;
    std::cin >> s2;
    if (s1 == s2) {
      l = m;
    } else {
      r = m;
    }
  }
     
  std::vector<int> isRed(2 * N, -10);
  isRed[l] = (s1 == "Red");
  isRed[l + N] = !isRed[l];
     
  std::string si = "?";
  std::string so = "?";
  for(int i = 0; i < 2*N; i++){
    if (i == l || i == l + N) continue;

    if (l < i && i < l + N) {
      si = si + " " + std::to_string(i + 1);
    } 
    else {
      so = so + " " + std::to_string(i + 1);
    }
  }
     
  for(int i = 0; i < 2*N; i++){
    if(i == l || i == l + N) continue;

    if(l < i && i < l + N) {
      std::cout << so;
    } 
    else {
      std::cout << si;
    }

    std::cout << " " << i + 1 << std::endl;
     
    std::string s1;
    std::cin >> s1;
    if(s1 == "Red"){
      isRed[i] = 1;
    }
    else{
      isRed[i] = 0;
    }
  }
     
  std::cout << "! ";
  for(int i = 0; i < 2*N; i++){
    if(isRed[i]){
      std::cout << "R";
    }
    else{
      std::cout << "B";
    }
  }
  std::cout << std::endl;

  return 0;
}

Measured memory_bytes: 724
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for yen_500 in range(A+1):
    for yen_100 in range(B+1):
        for yen_50 in range(C+1):
            value = 500 * yen_500 + 100 * yen_100 + 50 * yen_50
            if value == X:
                cnt += 1

print(cnt)

Measured memory_bytes: 3060
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for TN in range(0,N-1):
    C[TN],S[TN],F[TN] = (int(T) for T in input().split())
for TN in range(0,N):
    Time = 0
    for TS in range(TN,N-1):
        if Time>=S[TS]:
            Time += C[TS]+(F[TS]-(Time%F[TS]))%F[TS]
        else:
            Time += C[TS]+(S[TS]-Time)
    print(Time)

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

int main() {
	int N;
	cin >> N;
	int sum = 0;
	int dif = 0;
	for (int i = 0; i < N; i++) {
		int d;
		cin >> d;
		sum += d;
		dif += d * d;
	}
	cout << (sum * sum - dif)/2 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		int d[] = new int[k];
		str = br.readLine().split(" ");

		for (int i = 0; i < k; i++) {
			d[i] = Integer.parseInt(str[i]);
		}

		for (int i = n; i <= 100000; i++) {
			String s[] = String.valueOf(i).split("");
			boolean flag = false;

			for (int j = 0; j < s.length; j++) {
				for (int l = 0; l < d.length; l++) {
					if (s[j].equals(String.valueOf(d[l]))) {
						flag = true;
						break;
					}
				}
				if (flag) {
					break;
				}
			}
			if (flag) {
				continue;
			} else {
				System.out.println(i);
				return;
			}
		}
	}
}


Measured memory_bytes: 60396
#include<iostream>
#include<sstream>
#include<vector>
#include<climits>

using namespace std;

struct E
{
	int from, to;
	long cost;
};

int main(){
	ostringstream out;

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

	vector<long> d(n);
	vector<E> e;

	fill(d.begin(),d.end(),LONG_MAX);
	d[0]=0;

	for(int i=0;i<n;i++){
		cin >> u >> k;
		for(int j=0;j<k;j++){
			E es={u,0,0};
			cin >> es.to >> es.cost; 
			e.push_back(es);
		}
	}

	while(true){
		bool update=false;
		for(int i=0;i<e.size();i++){
			if(d[e[i].from]!=LONG_MAX&&d[e[i].to]>d[e[i].from]+e[i].cost){
				d[e[i].to]=d[e[i].from]+e[i].cost;
				update=true;
			}
		}
		if(!update)break;
	}

	for(int i=0;i<n;i++)
		out << i << " " << d[i] << endl;

	cout << out.str();
	return 0;
}

Measured memory_bytes: 1368
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <tuple>
#include <functional>
#include <limits>
#include <utility>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>

// use printf, scanf instead of cout, cin to avoid time limit exceeded.

using namespace std;

// Node class
template <typename T>
struct Node
{
	Node(const T& value) : mValue(value), mNext(nullptr), mPrev(nullptr) {}

	T mValue;

	Node<T>* mNext;
	Node<T>* mPrev;
};

// Doubly Linked List class
template <typename T>
class List
{
private:

	Node<T>* mFront;
	Node<T>* mBack;

public:

	List() : mFront(nullptr), mBack(nullptr) {}
	~List() { while (mFront) popFront(); }

	void pushFront(const T& val)
	{
		auto node(new Node<T>(val));

		if (mFront)
		{
			node->mNext = mFront;
			mFront->mPrev = node;

			mFront = node;
		}
		else
		{
			mFront = node;
			mBack = node;
		}
	}

	void pushBack(const T& val)
	{
		auto node(new Node<T>(val));

		if (mBack)
		{
			node->mPrev = mBack;
			mBack->mNext = node;

			mBack = node;
		}
		else
		{
			mFront = node;
			mBack = node;
		}
	}

	void popFront()
	{
		if (mFront)
		{
			auto next(mFront->mNext);
			delete mFront;

			if (next)
			{
				next->mPrev = nullptr;
				mFront = next;
			}
			else
			{
				mFront = mBack = nullptr;
			}
		}
	}

	void popBack()
	{
		if (mBack)
		{
			auto prev(mBack->mPrev);
			delete mBack;

			if (prev)
			{
				prev->mNext = nullptr;
				mBack = prev;
			}
			else
			{
				mFront = mBack = nullptr;
			}
		}
	}

	void erase(const T& val)
	{
		auto node(mFront);

		while (node)
		{
			if (node->mValue == val)
			{
				if (node->mPrev) node->mPrev->mNext = node->mNext;
				else mFront = node->mNext;

				if (node->mNext) node->mNext->mPrev = node->mPrev;
				else mBack = node->mPrev;

				delete node;

				break;
			}

			node = node->mNext;
		}
	}

	void print()
	{
		auto node(mFront);

		size_t index(0);
		while (node)
		{
			printf(index++ ? " %d" : "%d", node->mValue);

			node = node->mNext;
		}

		printf("\n");
	}
};

int main()
{
	List<int> list;

	int n;
	scanf("%d", &n);

	for (size_t i(0); i < n; ++i)
	{
		char command[16];
		scanf("%s", command);

		if (!strcmp(command, "insert"))
		{
			int x;
			scanf("%d", &x);

			list.pushFront(x);
		}
		else if (!strcmp(command, "delete"))
		{
			int x;
			scanf("%d", &x);

			list.erase(x);
		}
		else if (!strcmp(command, "deleteFirst"))
		{
			list.popFront();
		}
		else if (!strcmp(command, "deleteLast"))
		{
			list.popBack();
		}
	}

	list.print();

	return 0;
}

Measured memory_bytes: 34384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			int p[] = new int[n];
			
			for (int i = 0; i < n; i++) {
				p[i] = sc.nextInt();
			}
			
			int count = 0;
			for (int i = 0; i < n - 2; i++) {
				if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
					count ++;
				} else if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
					count ++;
				}
			}
			
			System.out.println(count);
			
		}
	}

}

Measured memory_bytes: 22996
li = list(input())
sums = 0
leng = int(len(li))

for i in range(leng):
    now = i
    if (now + 1) >= leng:
        break
    if(li[now] == li[now + 1]):
        if(li[now + 1] == '0'):
            li[now + 1] = '1'
        else:
            li[now + 1] = '0'
        sums += 1
print(sums)


Measured memory_bytes: 3956
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict
import bisect

N = int(input())
A = [None] * N
for i in range(N):
    A[i] = int(input())


D = {}
for a in A:
    D[a] = D.get(a,0) + 1

ret = 0
for k,v in D.items():
    if v%2 == 1:
        ret += 1

print(ret)

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

const int MAX = 110000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> nums(N);
    for (int i = 0; i < N; i++)
    {
        ll A;
        cin >> A;
        nums.at(i) = A;
    }
    COMinit();
    sort(nums.begin(), nums.end());
    if(nums.at(0) < 0){
        ll firstNum = nums.at(0);
        for(int i = 0; i < N; i++){
            nums.at(i) -= firstNum;//全部0以上にする
        }
    }
    ll answer = 0;
    for (int i = K - 1; i < N; i++)
    {
        answer = (answer + COM(i, K - 1) * nums.at(i)) % MOD;
    }
    for (int i = 0; i < N - K + 1; i++)
    {
        answer = answer - ((COM(N - i - 1, K - 1) * nums.at(i)) % MOD);
        if(answer < 0){
            answer += MOD;
        }
    }
    cout << answer << endl;
    return 0;
}


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

using namespace std;

#define ALL(x) x.begin(), x.end()

typedef long long int lld;
typedef pair<int, int> pii;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;

	int n = 0;
	cin >> n;

	priority_queue<double, vector<double>, greater<double>> pq;

	for (int i = 0; i < n; i++){
		double a = 0;
		cin >> a;
		pq.push(a);
	}

	while (pq.size() > 1){
		double a = pq.top();
		pq.pop();
		double b = pq.top();
		pq.pop();

		pq.push((a + b) / 2);
	}

	cout << pq.top() << endl;


	return 0;
}

Measured memory_bytes: 256
import copy
import math
import string
import heapq
import bisect
import sys
sys.setrecursionlimit(10**7)

N = int(input())
A = list(map(int,input().split()))
mc = 0
for i in range(N):
    if A[i] < 0:
        mc += 1
    A[i] = abs(A[i])
A.sort()
ans = 0
for i in range(N):
    if i == 0 and mc % 2 == 1:
        ans -= A[i]
    else:
        ans += A[i]
print(ans)

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

int n;
void dfs(string s, char mx) {
  if (s.size() == n){
    cout << s << endl;
    return;
  }
  for (char c = 'a'; c <= mx + 1; c++){
    string t = s;
    t += c;
    dfs(t, max(mx, c));
  }
}

int main() {
  cin >> n;
  dfs("", 'a' - 1);
  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<vector>
#include<math.h>
long long int mod = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);
using namespace std;
int main() {
	
	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n - 1) / x) * t + t << endl;

	return 0;

}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

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

#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

/*****************************************************START******************************************************************/


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1 ;
	 //cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)
	while (T--)
	{
		int n; cin >> n; 
		string s ; 
		cin >> s; 
		int ans = 0 , x = 0; 
		for(int i=0;i<n;i++){
			if(s[i] == 'I'){
				x++;
			}else{
				x--;
			}
			ans = max(x , ans);
		}
		cout << ans << endl;
		
				
	}
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 2019
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
ll dp[2025]={};
int main()
{
	ios;
	string s;
	ll len,i,ans=0,d,j,res;
	cin>>s;
	len=s.length();
	//dp[s[0]-48]=1;
	for(i=0;i<len;i++)
	{
		ll cnt[2025]={};
		d=s[i]-48;
		cnt[d]=1;
		for(j=0;j<=2018;j++)
		{
			res=(j*10+d)%mod;
			if(res==0)
				ans+=dp[j];
			cnt[res]+=dp[j];
		}
		for(j=0;j<=2018;j++)
			dp[j]=cnt[j];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3808
# -*- coding: utf-8 -*-
import copy
s = list(input())

if ''.join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

if len(s) == 26:
    for i in reversed(range(0, 26)):
        #for j in range(1, ord('z') - ord(s[i])):
        for j in range(ord(s[i]) + 1, ord('z') + 1):
            if not chr(j) in s[:i]:
                s[i] = chr(j)
                print(''.join(s[:i + 1]))
                exit()

for i in range(26):
    if not chr(ord('a') + i) in s:
        s.append(chr(ord('a') + i))
        break
ans2 = ''.join(s)
print(ans2)


Measured memory_bytes: 3444
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<bitset>
using namespace std;
#define ll long long
const ll INF = 1LL << 60;

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; }

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

//input
ll N,K;
string S;

int main() {
	cin >> N >> K >>S;
	bool flag = true;
	vector<ll> n(S.size()+2*K+1,0);
	vector<ll> k(S.size()+2*K+1,0);
	if (K > N) {
		cout << N << endl;
		return 0;
	}

	ll j=0;
	for (int ll i= 0; i<S.size();i++) {
		if (flag) {
			if (S[i] == '0') {
				j++;
				n[j]++;
              	flag=false;
			}
			else {
				n[j]++;
			}
		}
		else {
			if (S[i] == '1') {
				j++;
				n[j]++;
              	flag=true;
			}
			else {
				n[j]++;
			}
		}
	}
	if (j==0|j<=2*K) {
		cout << N << endl;
		return 0;
	}
  //for(int i=0;i<=j;i++) cout<<n[i]<<endl;

	vector<ll> sum(j+2*K+2,0);
	sum[0] = 0;
	for (int i = 0; i <= j+1; i++) {
		sum[i + 1] = sum[i] + n[i];
	}

	vector<ll> ans;

	for (int i = 0; i <= j; i+=2) {
		ans.push_back(sum[i + 2 * K + 1] - sum[i]);
	}
  	
    //for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
	sort(ans.begin(), ans.end(), greater<ll>());
	cout << ans[0];
	return 0;
}

Measured memory_bytes: 5120
def main():
    from collections import defaultdict,deque
    from math import ceil
    from sys import setrecursionlimit
    setrecursionlimit(10**6)
    f = lambda :map(int,input().split())
    n,u,v = f() # u:高橋
    edge = defaultdict(list)
    for i in range(n-1):
        a,b = f()
        edge[a].append(b)
        edge[b].append(a)
    
    distance = [[-1]*2 for _ in range(n+1)]
    distance[u][0] = 0
    distance[v][1] = 0
    def dfs(node,start):
        targets = deque([node])
        while targets:
            parent = targets.popleft()
            distance_parent = distance[parent][start]
            for child in edge[parent]:
                if distance[child][start] == -1:
                    distance[child][start] = distance_parent + 1
                    targets.append(child)
    dfs(u,0)
    dfs(v,1)
    ans = 0
    for u_d, v_d in distance:
        if u_d < v_d:
            ans = max(ans,v_d)
    print(ans-1)


        


main()
        



                
        
        
        
        
        



    


Measured memory_bytes: 107260
from operator import itemgetter
import sys
def main():
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a_b = [list(map(int, input().split())) for i in range(m)]
    a_b.sort(key=itemgetter(1))
    end = a_b[0][1]-2
    ans = 1 
    for i in range(m):
        if a_b[i][0]-1 > end:
            end = a_b[i][1]-2
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()


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

int main(){
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  int ans = 0;
  
  ans = N > K ? K*X+Y*(N-K) : N*X;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> T;

struct UnionFind{
	int size;
	vector<int> parent;

	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n;
llint a[100005], b[100005];
T p[100005];
P pa[100005];
UnionFind uf(100005);

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

  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= n; i++) cin >> b[i];
  for(int i = 1; i <= n; i++) p[i] = T(P(b[i], a[i]), i);
  sort(p+1, p+n+1);
  for(int i = 1; i <= n; i++){
    a[i] = p[i].first.second;
    b[i] = p[i].first.first;
  }
  for(int i = 1; i <= n; i++) pa[i] = P(a[i], i);
  sort(pa+1, pa+n+1);

  for(int i = 1; i <= n; i++){
    if(pa[i].first > b[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i = 1; i < n; i++){
    if(pa[i+1].first <= b[i] && pa[i].first <= b[i+1]){
      cout << "Yes" << endl;
      return 0;
    }
  }

  for(int i = 1; i <= n; i++) uf.unite(i, pa[i].second);
  set<llint> S;
  for(int i = 1; i <= n; i++) S.insert(uf.root(i));
  if(S.size() == 1) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;



int main() {
  int n;
  cin>>n;
  ll a[n];
  map<ll,ll> memo;
  for(int i=0;i<n;i++) {
    cin>>a[i];
    memo[a[i]]++;
  }
  ll ans=0;
  for(auto itr=memo.begin();itr!=memo.end();itr++){
    ans+=(itr->second)*(itr->second-1)/2;
  }
  for(int i=0;i<n;i++){
    ll temp=ans;
    temp-=memo[a[i]]*(memo[a[i]]-1)/2;
    temp+=(memo[a[i]]-1)*(memo[a[i]]-2)/2;
    cout<<temp<<endl;
  }
}


Measured memory_bytes: 12288
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int ans=0,i;
    char s[5];

    for(i=0;i<4;i++){
        scanf("%c",&s[i]);
        if( s[i] == '+' ){
            ans++;
        }else{
            ans--;
        }
    }
    
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    int ans=0,cnt=0, s_size;
    s_size = s.size();
    rep(i,s_size){
        rep(j,s_size-i){
            if(s[i+j] == 'A' || s[i+j] == 'C' || s[i+j] == 'G' || s[i+j] == 'T') {cnt++;}
            else break;
        }
        if(ans < cnt) ans = cnt;
        cnt = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3520
/* COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define debug(x) cout << #x << " = " << x << "\n"

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;


void solve()
{
    //code here.
    ll n;
    cin >> n;
    ll count = 0;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 1; i < n; i++)
    {
        if (a[i] < a[i - 1])
        {
            count += (a[i - 1] - a[i]);
            a[i] = a[i - 1];
        }

    }
    cout << count;

    


    

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T = 1;
    //cin >> T; // If only one test case then you can comment this line out.

    while (T--)
    {
        solve();

    }
    return 0;
}

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

void solve(){
    // int n;
    // cin>>n;
    // int a[n];
    // for(int i=0;i<n;i++){
    //     cin>>a[i];
    // }

}
long long mul(long long a, long long b, long long m){
    long long res=0;
    while(b){
        if(b&1)
            res=(res+a)%m;
        a=(2*a)%m;
        b=b/2;

    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--){
    //     solve();
    // }
    int n;
    cin>>n;
    long long m=1e9+7;
    long long a[n];
    long long prefixsum[n];
    cin>>a[0];
    prefixsum[0]=a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        prefixsum[i]=prefixsum[i-1]+a[i];
    }
    long long ans=0;
    for(int i=0;i<n-1;i++){
        ans+=mul(a[i],prefixsum[n-1]-prefixsum[i],m);
        ans=ans%m;
    }
    cout<<ans;

}

Measured memory_bytes: 6776
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while( true ) {

	    final int n = stdin.nextInt();
	    if ( n == 0 ){
		break;
	    }

	    int[] color = new int[ n ];
	    for ( int i = 0; i < n; i++ ) {
		color[ i ] = stdin.nextInt();
	    }
	    int minSize = n;
	    for ( int i = 0; i < n; i++ ) {
		int preColor = color[ i ];
		if ( preColor != 1 ) {
		    color[ i ] = 1;
		    minSize = Math.min( minSize, n - simulate( color, i ) );
		}
		if ( preColor != 2 ) {
		    color[ i ] = 2;
		    minSize = Math.min( minSize, n - simulate( color, i ) );
		}
		if ( preColor != 3 ) {
		    color[ i ] = 3;
		    minSize = Math.min( minSize, n - simulate( color, i ) );
		}
		color[ i ] = preColor;
	    }
	    System.out.println( minSize );
	}	
    }

    static int simulate( final int[] color, final int index ) {
	
	int left = index;
	int right = index;
	int number = 0;
	//System.err.printf( "%d, %s\n", index, Arrays.toString( color ) );

	while ( 0 <= left && right < color.length && color[ left ] == color[ right ] ) {
	    final int pColor = color[ left ];
	    int localCount = 0;
	    while ( 0 <= left && color[ left ] == pColor ) {
		if ( left != right ) {
		    localCount++;
		}
		left--;
	    }
	    while( right < color.length && color[ right ] == pColor ) {
		right++;
		localCount++;
	    }
	    if ( localCount >= 4 ) {
		//System.err.printf( "remove: (left, right, localCount) = (%d, %d, %d)\n", left, right, localCount );
		number += localCount;
	    }
	}
	return number;
    }    
}

Measured memory_bytes: 39312
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int n, k, nxt;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; i++){
        cin >> nxt;
        if (nxt >= k) ans++;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,r,rr[10][3];
string s,t[10];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)rr[i][0]=rr[i][1]=rr[i][2]=0;
for(i=0;i<n;i++){
cin>>t[i];
for(j=0;j<n-1;j++){cin>>r;rr[i][r]++;}
}
for(i=0;i<n-1;i++){
for(j=n-1;j>i;j--){
if(rr[j-1][0]<rr[j][0]||rr[j-1][0]==rr[j][0]&&rr[j-1][1]>rr[j][1]){
s=t[j-1];t[j-1]=t[j];t[j]=s;
r=rr[j-1][0];rr[j-1][0]=rr[j][0];rr[j][0]=r;
r=rr[j-1][1];rr[j-1][1]=rr[j][1];rr[j][1]=r;
r=rr[j-1][2];rr[j-1][2]=rr[j][2];rr[j][2]=r;
}
}
}
for(i=0;i<n;i++)cout<<t[i]<<endl;
}
return 0;
}

Measured memory_bytes: 1200
import java.util.*;


public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      long sum = 0;
      for (int i = 1; i <= n  ; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
          sum += i;
        } 
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 27068
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int m, k;
	cin >> m >> k;
	int b = 1 << m;
	vector<int> ans;
	if (k == 0) {
		for (int i = 0; i < b; ++i) {
			ans.push_back(i);
			ans.push_back(i);
		}
	} else if (m > 1 && k < b) {
		ans.clear();
		for (int i = 0; i < b; ++i) {
			if (i != k) {
				ans.push_back(i);
			}
		}
		ans.push_back(k);
		for (int i = b - 1; i >= 0; --i) {
			if (i != k) {
				ans.push_back(i);
			}
		}
		ans.push_back(k);
	} else {
		ans = { -1 };
	}
	for (int a : ans) {
		cout << " " << a;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2932
input = STDIN.gets
N = input.to_i


cakes_mums = (0..(N / 4)).to_a
donuts_nums = (0..(N / 7)).to_a

product = cakes_mums.product(donuts_nums)

product.any? do |(cakes, donuts)|
  if cakes * 4 + donuts * 7 == N
    puts 'Yes'
    exit 0
  end
end

puts 'No'



Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
void Main(){
  int h,w,n;
  cin>>h>>w>>n;
  if(h<w) swap(h,w);
  cout<<dup(n,h)<<endl;

} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(ALL(p));
  cout << accumulate(p.begin(), p.begin() + k, 0) << endl;
  ret;
}


Measured memory_bytes: 3640
a, b, c= gets.chomp.split(" ").map(&:to_i)

result = []
i = 1

while i <= c do
  remainder = c % i
  if remainder == 0
    result << i
  end 
  i += 1
end

count = 0

(a..b).each do |e|
  result.each do |i|
    if e == i
      count += 1
    end
  end
end

puts count


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

int main() {

  int N;
  cin>>N;
  
  for(int i=0;i<N;i++){
    int A ;
    int l,r ;
    cin>>l>>r;
    
    A =A + r - l + 1;
    if(i+1 ==N){
      cout<<A<<endl;
    }
  }
    
}


Measured memory_bytes: 3624
/****************### With The name of ALLAH, most Gracious, most Compassionate ###****************/

/**============================================================================**\
|   Author      : Md Jubayer Hossen Jame
|   Study       : CSE, BRUR
|   Today       : 03 September, 2k20
|   Source      : AtCoder Online Judge
|   Problem link: https://atcoder.jp/contests/abc042/tasks/abc042_a
|   Algorithm   :
|
\**============================================================================**/

#include "bits/stdc++.h"
using namespace std;

#define FI                    freopen("input.txt", "r", stdin)
#define FO                    freopen("output.txt", "w", stdout)
#define FasterIO              ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

typedef long long             ll;
typedef unsigned long long    ull;
typedef unsigned int          ui;

#define mem(x,y)              memset(x,y,sizeof(x));
#define pii                   pair<int,int>
#define mk                    make_pair
#define ff                    first
#define ss                    second
#define pb                    push_back
#define ppb                   pop_back
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define for0(i, n)            for (int i = 0; i < (int)(n); ++i)
#define endl                  '\n'

const double PI = acos(-1.0);

#define gcd(a,b)              __gcd(a,b)
#define lcm(a,b)              (a*(b/gcd(a,b)))

///Direction Array
// 4 Direction - DOWN, UP, RIGHT, LEFT
int dx4[]= {+1, -1, +0, +0};
int dy4[]= {+0, +0, +1, -1};
#define isValid(a, b, R, C)   (0 <= a && a < R) && (0 <= b && b < C)
int dx8[]= {+0, +0, +1, -1, -1, +1, -1, +1};
int dy8[]= {-1, +1, +0, +0, +1, +1, -1, -1};

///Knight Moves
int dr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int dc[] = {-2, -2, -1, 1, 2, 2, 1, -1};
/**************************************************************************************************/

void test_case()
{
    int a, b, c;
    cin >> a >> b >> c;

    int ar[10] = {};
    ar[a]++, ar[b]++, ar[c]++;

    if(ar[5] == 2 and ar[7] == 1)cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    //FI;
    //FO;
#endif // ONLINE_JUDGE
    //FasterIO

    int T = 1;
    //cin >> T;
    for(int tc = 1; tc <= T; ++tc)
    {
        //cout << "Case #" << tc << ":" << endl;
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3596
def main():
    N = int(input())
    task = []
    for _ in range(N):
        a, b = map(int, input().split())
        task.append([a, b])
    task = sorted(task, key = lambda x: x[1])
    cur = 0
    for a, b in task:
        if cur + a > b:
            return "No"
        cur += a
    return "Yes"


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 86360
#ABC125-C GCD on Blackboard
"""
問題
リストの要素のうち一つだけ変更して、リスト全体のgcdを最大化せよ。
解法
セグ木を用いて、ある1要素を無視してその右側と左側のgcdを取る。
その時の最大値が答え。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

#input
n = int(readline())
lst1 = list(map(int,readline().split()))

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
#####segfunc######
def segfunc(x,y):
    return  gcd(x,y)

def init(init_val): #渡されたリストでsegを初期化
    #set_val
    for i in range(len(init_val)):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x): #segの要素kをxに変更(セグ木全体の更新)
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q): #区間[p,q)での、segfuncに準じた値を返す
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
"""
最小値のセグ木 → 10**9　(最小値の更新に影響しないため)
　　和のセグ木 → 0　(上の単位元の説明を参照)
　　積のセグ木 → 1　(上の単位元の説明を参照)
　　gcdのセグ木 → 0　(gcdを更新しない値は0)
"""
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num #単位元の配列(計算結果に影響を及ぼさない配列)を作成

init(lst1)

ans = 0
for i in range(n):
    if i == 0:
        ans = max(ans,query(1,n))
    elif i == n-1:
        ans = max(ans,query(0,i))
    else:
        ans = max(ans,gcd(query(0,i),query(i+1,n)))

print(ans)

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll A, B;
  cin >> A >> B;
  if (A % 2 == B % 2) {
    cout << (A + B) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l;
	string s[101];
	cin>>n>>l;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<n;j++)
		{
			if(s[i]==s[j])
			{
				continue;
			}
			for(int k=0;k<l;k++)
			{
				if(s[i][k]-'0'>s[j][k]-'0')
				{
					swap(s[i],s[j]);
					break;
				}
				else if(s[i][k]-'0'==s[j][k]-'0')
				{
					continue;
				}
				else
				{
					break;
				}
			}
		}
	}
	for(int i=n;i>0;i--)
	{
		cout<<s[i];
	}
	return 0;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 100000

int main(){

    ll n;
    cin >> n;

    ll a1,i;

    vector<ll> a;

    for(i=0;i<n;i++){
        cin >> a1;
        a.push_back(a1);
    }

    ll dp[n];

    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);

    for(i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }

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

}


Measured memory_bytes: 1908