akhauriyash/Code-Regression huggingface dataset:
import sys
def main():
    for line in sys.stdin:
        a,b = map(int, line.split())
        if a > b:
            a,b = b,a
        p = a * b #product

        while True:
            hoge = a
            a = b % a
            b = hoge
            if a == 0:
                gcd = b
                break

        lcm = p // gcd
        print(gcd, lcm)




if __name__ == "__main__":
    main()

Measured memory_bytes: 7588
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(int i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e5+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int a, b; cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int h,w,i,j;
    for(;;){
        scanf("%d %d\n",&h,&w);
        if(h==0&&w==0)break;
        for(i=0;i<h;i++){
            if(i==0||i==h-1){
                for(j=0;j<w;j++){
                    printf("#");
                }
            }else{
            for(j=0;j<w;j++){
                if(j==0||j==w-1){
                    printf("#");
                }else{
                printf(".");
            }
            }
            // printf("\n");
        }
        printf("\n");
    }
    printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2100
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::*;

fn main() {
    input! {
        n: isize,
    }
    if n >= 30 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2172
while True:

    n,x = map(int,input().split())
    if n == 0 and x ==0:
        break
    
    ans = 0
    
    for a in range(1,n+1):
        for b in range(1,n+1):
            if b <= a:
                continue
            c = x-(a + b)
            
            if c <= n and c > b and c != 0:
                ans += 1
        
    print(ans)
        


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b; cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    reverse(s.begin(), s.end());
    if (stoi(s) == i) ans++;
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
    a:usize,
    b:usize,
    v:[usize;a]
    }
    let sum:usize=v.iter().sum();
    let min:usize=*v.iter().min().unwrap();
    println!("{}",a+(b-sum)/min);
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


// bool cmp(pair<int,int>p,pair<int,int>q) {
//     return p.first>q.first;//descending by first
//     return p.first<q.first;//ascending by first
//     return p.second>q.second;//descending by second
//     return p.second<q.second;//ascending by second
// }

bool cmp(int p,int q) {
    return p>q;//descending
    // return p<q;//ascending
}

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }
    return 0;
}
int clue() {

    lli x;double c;
    cin>>x>>c;
    lli p=c*100+.5;
    lli q=x*p;
    q/=100;
    cout<<q<<endl;
    return 0;
}

Measured memory_bytes: 3736
n = gets.to_i
s = gets
ans = r = g = b = 0
0.upto(n-1) do |i|
  if s[i] == "R"
    r += 1
  elsif s[i] == "G"
    g += 1
  else
    b += 1
  end
  (i+1).upto(n-1) do |j|
    k = j + j - i
    break if k >= n
    if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
      ans += 1
    end
  end
end
puts (r * g * b - ans)

Measured memory_bytes: 14360
# -*- coding: utf-8 -*-
import math
def main():
    N,D = map(int,input().split())
    X=[list(map(int,input().split())) for i in range(N)]
    count = 0
    for i in range(N):
        for k in range(N-1-i):
            K = 0
            KK = 0
            for j in range(D):
                K += ((X[i][j])-(X[N-1-k][j]))**2
            KK = K**0.5
            if isinstance(KK,int) or KK.is_integer():
                count += 1
    print(count)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9+5;

int main(){
    int n;
    cin>>n;
    vector<int> dp(3,0);
    for(int i=0; i<n; i++){
        vector<int> h(3);
        for(int j=0; j<3; j++) cin>>h[j];
        vector<int> dpn(3,0);
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; k++){
                if(j!=k)
                    dpn[j]=max(dpn[j], dp[k]+h[j]);
            }
        }
        dp=dpn;
    }

    cout<<max(max(dp[0],dp[1]),dp[2]);
    
}

Measured memory_bytes: 3540
sx, sy, gx, gy = [ int(v) for v in input().split() ]
dx, dy = gx - sx, gy - sy


ans_1 = "R" * dx + "U" * dy
ans_2 = "L" + "D" * (dy-1) + "L" * (dx-1) + "D"
ans_3 = "D" + "R" * (dx+1) + "U" * (dy+1) + "L"
ans_4 = "U" + "LL" + "D" * (dy-1) + "L" * (dx-1) + "DD" + "R"

print(ans_1+ans_2+ans_3+ans_4)

Measured memory_bytes: 38256
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

int a, b, c;

int ans;

void solve() {                   
	scanf("%d %d %d", &a, &b, &c);

    if (a == b && a == c && a % 2 == 0) {
    	printf("-1\n");
    	return;
    }

    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    	int na = b + c, nb = a + c, nc = a + b;
    	a = na / 2, b = nb / 2, c = nc / 2;
    	++ans;
    }

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

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp
    i += 1
end

N = line[0].to_i
S = line[1]

num_r = 0
for i in 1..N do
  if S[i-1] == "R" then
    num_r += 1
  else
    num_r -= 1
  end
end
  
if num_r > 0 then
  print "Yes"
else
  print "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    long long int x,a;
    cin>>n>>x;
    std::deque<long long int> deq;
    deq.emplace_back(x);
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end());
    std::deque<long long int> diff;
    for (int j=0;j+1<deq.size();j++) {
        diff.emplace_back(deq[j+1]-deq[j]);
    }
    for (int k=0;k+1<diff.size();k++) {
        long long int a=diff[k];
        long long int b=diff[k+1];
        while (a%b!=0) {
            long long int tmp=b;
            b=a%b;
            a=tmp;
        }
        diff[k+1]=b;
    }
    cout<<diff.back()<<endl;
    /*
    for (int hoge=0;hoge<diff.size();hoge++) {
        cout<<diff[hoge]<<" ";
    }
    cout<<endl;*/
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
  ll dif = abs(a-b);
  ll tmp = (v-w)*t;
  if(tmp >= dif)print("YES");
  else print("NO");
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <stack>
#include <cstring>
#include <algorithm>
#include <vector> 
#include <map>
#include <string>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, l; cin >> n >> l;
	int sum = 0;
	for (int i = l; i < l + n; i++) {
		sum += i;
	}
	int cnt = -1;
	int ans = 0;
	for (int i = l; i < l + n; i++) {
		int t = sum - i;
		if (cnt == -1 || abs(sum - t) < cnt) {
			cnt = abs(sum - t);
			ans = t;
		}
	}
	cout << ans << '\n';


}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]ITP1_5_D 構造化プログラミング

            string line = Console.ReadLine().TrimEnd();
            int n = int.Parse(line);

            var list = new List<int>();

            for(int i = 1; i <= n; i++)
            {
                if(i % 3 == 0)
                {
                    list.Add(i);
                }
                else if(i.ToString().Contains("3"))
                {
                    list.Add(i);
                }
            }

            //先頭に空白を出力
            Console.WriteLine(" {0}", String.Join(" ", list));
        }
    }
}



Measured memory_bytes: 8300
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int n, ac = 0, wa = 0, tle = 0, re = 0;
  string s[100010];
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i)
  {
    if (s[i] == "AC") ++ac;
    if (s[i] == "WA") ++wa;
    if (s[i] == "TLE") ++tle;
    if (s[i] == "RE") ++re;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 6716
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (a == b && b == c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    A, B, C, D, E, F = map(int, input().split())

    W = [100*A*x + 100*B*y for x in range(0, 31) for y in range(0, 31) if 0 < (100*A*x + 100*B*y) <= F]
    S = [C*x + D*y for x in range(0, 3001) for y in range(0, 3001) if 0 < (C*x + D*y) <= F]

    dense, sugar, mass = 0, 0, 100*A
    for w in W:
        for s in S:
            if ((w+s) <= F and s <= (w*E/100) and dense*(s+w) < s):
                dense = s/(s+w)
                sugar = s
                mass = s+w
    print(mass, sugar)

    
if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

int a, b, c, d;

double f(double x) {
    return a * x * x * x + b * x * x + c * x + d;
}

int judge(double x) {
    if(x > 1e-9) return 1;
    if(x < -(1e-9)) return -1;
    return 0;
}

int main() {
    int n;
    cin >> n;
    P* a = new P[n];
    rep(i, n) {
        int ai;
        cin >> ai;
        a[i] = P(ai, i);
    }
    sort(a, a + n);

    rep(i, n) {
        if(i != 0) cout << " ";
        cout << a[i].second + 1;
    }
    cout << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        mp[a]+=1;
        if(mp[a] > 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12948
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0022
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "";
            int maxNumber = 0;
            while ((str=Console.ReadLine())!="0")
            {
                int n = int.Parse(str);
                List<int> numberList = new List<int>();
                for (int i = 0; i < n; ++i)
                {
                    numberList.Add(int.Parse(Console.ReadLine()));
                }
                maxNumber = numberList[0];
                for (int j = 0; j < n; ++j)
                {
                    int addNumber = 0;
                    for (int i = j; i < n; ++i)
                    {
                        addNumber += numberList[i];
                        if (maxNumber < addNumber)
                        {
                            maxNumber = addNumber;
                        }
                    }
                }
                Console.WriteLine(maxNumber);
            }
        }
    }
}



Measured memory_bytes: 13916
#include<stdio.h>

int main(){
	long long int N;
	scanf("%lld",&N);
    
    int i;
    long long int A=0;
	for(i=0;i<=N;i++)
		if(i%3==0){
		}else if(i%5==0){
		}else{
			A+=i;
		}
		printf("%lld",A);

		return 0;
}

Measured memory_bytes: 1728
#それぞれの時間に注目して最大のものを考える
#いもす法？
#チャンネル同じ場合を考慮し忘れていた
#チャンネル分けてチェックすればええやん
n,c=map(int,input().split())
imos=[[0 for i in range(c)] for j in range(10**5+1)]#1~10**5+1
for i in range(n):
    s,t,_c=map(int,input().split())
    imos[s-1][_c-1]+=1
    imos[t][_c-1]-=1
for i in range(1,10**5+1):
    for j in range(c):
        imos[i][j]+=imos[i-1][j]
imosans=[0]*(10**5+1)
for i in range(10**5+1):
    for j in range(c):
        imosans[i]+=(imos[i][j]>=1)
print(max(imosans))

Measured memory_bytes: 87900
from sys import stdin
import numpy as np

def main():
    def itrsum(arr):
        n=len(arr)
        tri=np.array([[i>=j for i in range(n)] for j in range(n+1)])
        return np.dot(tri,arr).astype('int64')
    n,w=map(int,stdin.readline().strip().split())
    t=[list(map(int,stdin.readline().strip().split())) for _ in range(n)]
    w1=t[0][0]
    # arr=[sorted([x for x in t if x[0]==w1+i],reverse=True,key=lambda e:e[1]) for i in range(4)]
    arr=[[x for x in t if x[0]==w1+i] for i in range(4)]
    arr=[l for l in arr]
    lenarr=list(map(len,arr))
    arr0=[itrsum(np.array(sorted([x[0] for x in l]),dtype='int64')) for l in arr]
    arr1=[itrsum(np.array(sorted([x[1] for x in l]),dtype='int64')) for l in arr]
    # arr=[x.sort(reverse=True,key=lambda e:e[1]) for x in arr]
    arr=np.array(arr)
    arrw=0
    arrv=0
    for i in range(4):
        arrw=np.ravel(arr0[i].reshape(lenarr[i]+1,1)+np.array([arrw]))
        arrv=np.ravel(arr1[i].reshape(lenarr[i]+1,1)+np.array([arrv]))
    #print(arr0)
    #print(arr1)
    #print('\n')
    #print(arrw)
    #print(arrv)
    #print(arrv[arrw<=w])
    ansarr=arrv[arrw<=w]
    print(np.max(ansarr))
    # wts=list(map(lambda l:l[0]-w1-1, t))
    # val=list(map(lambda l:l[1], t))

if __name__=='__main__':
    main()   


Measured memory_bytes: 35772
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

ll llmin(ll a,ll b){
    if(a>=b) return b;
    return a;
}
ll llmax(ll a,ll b){
    if(a<=b) return b;
    return a;
}

ll tmpcount(ll li,ll ri){
    ll cntans=0;

    if(li==ri){
        if(li<=N) cntans++;
    }

    if(li*10+ri<=N) cntans++;

    for( ll base = 100 ; base <=base10_6 ; base=base*10 ){
        if(N >= base*li){
            for( ll bi = 0 ; bi <base/10 ; bi++ ){
                ll val = li * base + bi * 10 + ri;
                if(val<=N) cntans++;
                else break;
            }
        }
    }
    return cntans;

}



int main(){

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

    cin >> N;
    ll cntans = 0;

    for( ll ni = 1 ; ni <=9 ; ni++ ){
        ll tmpcnt = tmpcount(ni,ni);
        cntans += tmpcnt * tmpcnt;
    }
    for( ll li = 1 ; li <=8 ; li++ ){
        for( ll ri = li+1 ; ri <=9 ; ri++ ){
            ll tmpcntl = tmpcount(li,ri);
            ll tmpcntr = tmpcount(ri,li);
            cntans += (tmpcntl * tmpcntr * 2);
        }
    }

    cout << cntans << endl;

}

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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int n;
    string s;
    cin >> n >> s;

    int cnt = 0;
    for(int i = 0; i < n - 2; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <array>

class Baseball {

	std::array<bool, 3> base;//base[0]:first, base[1]:second, base[2]:third
	int point,outcount,inning;

public:
	/*construtor*/
	Baseball(int ing) {
		for (int i = 0; i < (int)base.size(); ++i){
			base[i] = false;
		}
		point = 0;
		outcount = 0;
		inning = ing;
	}

	int inning_result(std::string res);

private:
	void clear();
	void hit();
	void homerun();
	void out();
};

/*Clear method*/
void Baseball::clear() {

	for (int i = 0; i < (int)base.size(); ++i){
		base[i] = false;
	}

	point = 0;
	outcount = 0;

}

/*The case of hit*/
void Baseball::hit() {

	if (base[2] == true) {
		++point;
		base[2] = false;
	}

	if (base[1] == true){
		base[2] = true;
		base[1] = false;
	}

	if (base[0] == true) {
		base[1] = true;
		base[0] = false;
	}

	base[0] = true;

}

/*The case of homerun*/
void Baseball::homerun() {

	++point;//butter runner point

	for (int i = 0; i < (int)base.size(); ++i){
		if (base[i] == true){
			++point;
		}
		base[i] = false;
	}

}

/*The case of out*/
void Baseball::out() {

	++outcount;

	if (outcount == 3){
		std::cout << point << std::endl;
		clear();
		--inning;
	}

}

/*Judgement of inning*/
int Baseball::inning_result(std::string res) {

	if (res == "HIT") {
		hit();
	}
	else if (res == "HOMERUN") {
		homerun();
	}
	else if (res == "OUT") {
		out();
	}
	else {
		std::perror(NULL);
	}

	return inning;
}

int main() {

	int n;//the number of ining
	std::string result;

	std::cin >> n;

	Baseball game(n);

	while (n > 0) {
		std::cin >> result;
		n = game.inning_result(result);
	}

	return 0;
}

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

set<string> ss;
string a[200048],s;
int tot=0,k;

int main ()
{
    cin>>s>>k;
    int i,j,n=int(s.size());
    for (i=0;i<=n-1;i++)
        for (j=1;j<=5;j++)
        {
            if (i+j-1>=n) continue;
            ss.insert(s.substr(i,j));
        }
    for (i=1;i<=k-1;i++) ss.erase(ss.begin());
    cout<<(*(ss.begin()))<<endl;
    return 0;
}

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

int GCD(int a, int b){
  return b?GCD(b,a%b):a;
}

int main(){
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  vector<int> b(n,0);
  int cnt=0;
  for(int i=n;i;i--){
      int t=a[i-1];
      for(int j=2;i*j<=n;j++){
        t^=b[j*i-1];
      }
      b[i-1]=t;
    cnt+=b[i-1];
  }
  cout << cnt << endl;
  for(int i=0;i<n;i++){
    if(b[i]) cout << i+1 << " ";
  }
}

Measured memory_bytes: 2432
n=int(input())
x=[0]*n
y=[0]*n
for i in range(n):
  x[i],y[i]=map(int,input().split())
  if(abs(x[i])+abs(y[i]))%2!=(abs(x[0])+abs(y[0]))%2:
    print(-1)
    exit()
D=[]
for i in reversed(range(33)):D.append(1<<i)
D+=[1,1]
if(abs(x[0])+abs(y[0]))%2==0:D.append(1)
print(len(D))
print(*D)
for i in range(n):
  X,Y=x[i],y[i]
  s=''
  for d in D:
    if abs(X)>abs(Y):
      if X>0:
        X-=d
        s+='R'
      else:
        X+=d
        s+='L'
    else:
      if Y>0:
        Y-=d
        s+='U'
      else:
        Y+=d
        s+='D'
  
  print(s)

Measured memory_bytes: 9240
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

struct drink{
	ll a, b;
	bool operator<(const drink &another){
		return a<another.a;
	}
};

int main(){
	ll n, m;
	cin >> n >> m;
	drink d[n];
	for(ll i=0; i<n; i++) cin >> d[i].a >> d[i].b;
	sort(d, d+n);
	ll ans=0, cnt=0;
	for(ll i=0; i<n; i++){
		if(cnt>=m) break;
		ll buy=min(m-cnt, d[i].b);
		cnt+=buy;
		ans+=d[i].a*buy;
	}
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){


string o;
cin>>o;

string E;
cin>>E;

int N=min(o.size(),E.size());

rep(i,N){
    cout<<o[i]<<E[i];
}
if(o.size()>E.size()){
    cout<<o[N]<<endl;
}

 return 0;
}

Measured memory_bytes: 256
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main() {
  val INF = 1000000001
  val n = readLine()!!.toInt()
  val activities = Array(n){
    val (a,b,c) = readLine()!!.split(' ').map { it.toInt() }
    Triple(a,b,c)
  }

  val dp = Array<IntArray>(n){ intArrayOf(0,0,0)}
  dp[0][0] = activities[0].first
  dp[0][1] = activities[0].second
  dp[0][2] = activities[0].third

  for (i in 1 until n){
    dp[i][0] = max(dp[i][0], max(dp[i-1][1], dp[i-1][2]) + activities[i].first)
    dp[i][1] = max(dp[i][1], max(dp[i-1][0], dp[i-1][2]) + activities[i].second)
    dp[i][2] = max(dp[i][2], max(dp[i-1][1], dp[i-1][0]) + activities[i].third)
  }

  println(max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])))
}

Measured memory_bytes: 70812
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

bool comp(pii a,pii b){
    return a.S>b.S;
}
signed main(){
    FastIO;
    int n;
    cin>>n;
    vector<pii>pos,neg;
    rep(i,1,n){
        string s;
        cin>>s;
        int maxi=0,cnt=0;
        for(char c:s){
            if(c=='(') cnt++;
            else cnt--;
            if(cnt<0) maxi=max(maxi,abs(cnt));
        }
        if(cnt>0) pos.pb({maxi,cnt+maxi});
        else neg.pb({maxi,cnt+maxi});
    }
    sort(all(pos));
    sort(all(neg),comp);
    int bal=0;
    for(pii p:pos){
        bal-=p.F;
        if(bal<0) return cout<<"No",0;
        bal+=p.S;
    }
    for(pii p:neg){
        bal-=p.F;
        if(bal<0) return cout<<"No",0;
        bal+=p.S;
    }
    cout<<(bal?"No":"Yes");
    return 0;
}


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

const int mn=5e5+7;
int a[mn][26],n;
char s[mn];

int lowbit(int x) {return x&-x;}

void modify(int dl,int x,int d)
{
	while(x<=n) {
		a[x][d]+=dl;
		x+=lowbit(x);
	}
}

int query(int x,int d)
{
	int ans=0;
	while(x) {
		ans+=a[x][d];
		x-=lowbit(x);
	}
	return ans;
}

int main()
{
	int q,op,l,r,ans;
	scanf("%d%s%d",&n,s+1,&q);
	char c;
	for(int i=1;i<=n;++i) modify(1,i,s[i]-'a');
	for(int i=1;i<=q;++i) {
		scanf("%d",&op);
		if(op==1) {
			scanf("%d",&l);
			c=getchar();while(c<'a'||c>'z') c=getchar();
			if(s[l]==c) continue ;
			modify(-1,l,s[l]-'a');
			s[l]=c;
			modify(1,l,s[l]-'a');
		}
		else {
			ans=0;
			scanf("%d%d",&l,&r);
			for(int j=0;j<26;++j) if(query(r,j)-query(l-1,j)>0) ans++;
			printf("%d\n",ans);
		}
	}
}

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

void enqueue(int);
void dequeue(void);

int Process_time[1000000];
char Process_name[100000][11];
int Process[100000];
int head=0,tail=1;

int main(){
  int i,j,time;
  int total_time = 0;
  int Process_number;


  scanf("%d %d",&Process_number,&time);
  
  for( tail = 0 ; tail < Process_number ; tail++){
    scanf("%s %d",Process_name[tail],&Process_time[tail]);
  }
  
  while(head != tail){
    
    Process_time[head] -= time; 
    
    if(Process_time[head] > 0) {
      total_time += time;
      dequeue( );
      if(head - 1 != -1)
      enqueue(head - 1);
      else enqueue( 99999);
    }
    else{
      total_time = total_time +(Process_time[head] +time);
      printf("%s %d\n",Process_name[head],total_time);
      head++;
      //if(head == 100000 || tail == 100000) {printf("over head!!\n"); head = 0;}
	}  
    
	   }
  return 0;

}

void enqueue(int a){
  Process_time[tail] = Process_time[a];
  strcpy(Process_name[tail],Process_name[a]);
	 tail++;
	 if(tail == 100000)  tail = 0;
	 /*   Process_time[tail] = Process_time[a];
	 strcpy(Process_name[tail],Process_name[a]);
	 }	*/ 
}


void dequeue(void){
  head++; 
  if(head == 100000) head = 0;
}

Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 5;

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

  for (int i = 0; i < n - 1; i++) {
    dis[i] = list[i + 1] - list[i];
  }
  dis[n - 1] = k - list[n - 1] + list[0];
  sort(dis.begin(), dis.end(), greater<int>());
  cout << k -  dis[0] << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>


int main() {
    using namespace std;
    int n, D, d;
    cin >> n >> D;
    d = D * 2 + 1;
    if (n % d == 0){
        cout << n / d;
    } else {
        cout << int(floor(n / d)) + 1;
    }
    return 0;
}

Measured memory_bytes: 3600
def solve(string):
    base = int(string) if len(string) % 2 else 10**(len(string) - 1) - 1
    excepts = sum([9 * 10**(i - 1) for i in range(2, len(string), 2)])
    return str(base - excepts)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 2940
using System;
using System.Text.RegularExpressions;



class Program
{
    static void Main(string[] args)
    {
        int num;
        Double sum = 0;
        int.TryParse(Console.ReadLine(), out num);
        foreach (string x in Regex.Split(Console.ReadLine(), @"\s+"))
        {
            sum += 1/Convert.ToDouble(x);
        };
        Console.WriteLine("{0}",1.0/sum);
    }
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	lint n,k; cin>>n>>k;
	vector<lint> h(n);
	rep(i,n) cin>>h[i];

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

	cout<<accumulate(h.begin(),h.begin()+n-min(k,n),0LL)<<'\n';

	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
#define N 2050
int head[N],to[N<<1],nxt[N<<1],cnt,n,K,ans=1<<30;
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
}
int tot,vis[N];
void df1(int x,int y,int d) {
	int i; tot++;
	if(d==K/2) return ;
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y&&!vis[to[i]]) {
		df1(to[i],x,d+1);
	}
}
int main() {
	scanf("%d%d",&n,&K);
	int i,x,y;
	for(i=1;i<n;i++) {
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	if(!(K&1)) {
		int i;
		for(i=1;i<=n;i++) {
			tot=0;
			df1(i,0,0);
			ans=min(ans,n-tot);		
		}
	}else {
		int i;
		for(i=1;i<=cnt;i+=2) {
			tot=0;
			vis[to[i+1]]=1;
			df1(to[i],0,0);
			vis[to[i+1]]=0;

			vis[to[i]]=1;
			df1(to[i+1],0,0);
			vis[to[i]]=0;
			ans=min(ans,n-tot);
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <iomanip>
#include <sstream>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}



int main(){
    long long n;
    string s,s1,s2,s3; cin >> n;
    stringstream ss;
    ss << bitset<32>(n);
    s = ss.str();
    cout << s << endl;
    for(int i = 0; i < s.size(); i++){
        if (s[i] == '0') s1 += '1';
        else s1 += '0';

        if (i == s.size()-1) s2 += '0';
        else s2 += s[i+1];

        if (i == 0) s3 += "0";
        else s3 += s[i-1];
    }
    cout << s1 << endl << s2 << endl << s3 << endl;
}
  




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

const int MAX_N = 310;
const int MAX_K = 100010;

const int64_t MOD = 1e9+7;

int64_t dp[MAX_N][MAX_K];
int64_t sum[MAX_N][MAX_K];

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  
  dp[0][0] = 1;
  for(int i=0; i<MAX_K; i++){
    sum[0][i] = 1;
  }
  
  for(int i=0; i<N; i++){
    for(int j=0; j<=K; j++){
      int64_t x = sum[i][j];
      if(j - vec[i] > 0){
        x -= sum[i][j - vec[i] - 1];
        while(x < 0){
          x += MOD;
        }
      }
      dp[i+1][j] = x;
      dp[i+1][j] %= MOD;
      sum[i+1][j] = dp[i+1][j];
    }
    for(int j=1; j<=K; j++){
      sum[i+1][j] += sum[i+1][j-1];
      sum[i+1][j] %= MOD;
    }
  }
  
  /*for(int i=0; i<=N; i++){
    for(int j=0; j<=K; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  
  cout << dp[N][K] << endl;
}

Measured memory_bytes: 160000
from heapq import heappush, heappop
n, m = map(int, input().split())
jobs = []
for _ in range(n):
    a, b = map(int, input().split())
    jobs.append((a, b))
jobs.sort(reverse=True)
ans = 0
q = []
for i in range(1, m+1):
    while jobs and jobs[-1][0] <= i:
        heappush(q, -jobs.pop()[1])
    if q:
        ans -= heappop(q)
print(ans)

Measured memory_bytes: 17144
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, D;
	cin >> H >> W >> D;
	vector<int> A(H*W);
	vector<int> sum(H*W, 0);
	vector<pair<int, int> > vp(H*W);
	int res = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i * W + j];
			A[i * W + j]--;
			vp[A[i * W + j]].first = i;
			vp[A[i * W + j]].second = j;
		}
	}
	for (int i = 0; i < D; i++) {
		for (int j = i + D; j < H*W; j += D) {
			sum[j] = sum[j - D] + abs(vp[j].first - vp[j - D].first) + abs(vp[j].second - vp[j - D].second);
		}
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << sum[r] - sum[l] << endl;
	}
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	string S; cin>>S;
	if(N&1){
		puts("No");
		return 0;
	}
	rpz(i,N/2){
		// ote(S[i]);
		// ote(S[N/2+i]);
		// puts("--");
		if(S[i]!=S[N/2+i]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());

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

	int X;
	cin >> X;
	bool array[X+1];
	for(int i = 0;i <= X; i++) array[i] = false;

	for(int i = 2; i <= X; i++) {
		int tmp = i * i;
		while(tmp <= X) {
			array[tmp] = true;
			tmp *= i;
		}
	}
	for(int i = X; i >= 1; i--) {
		if(array[i]) {
			cout << i << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}


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

typedef long long ll;

const int MAX_N = 100;
const int MAX_W = 10000;

int dp[MAX_N+1][MAX_W+1];

int n, W;
int w[MAX_N], v[MAX_N];

int rec(int i, int j){
    // すでに調べたことがある場合
    if(dp[i][j] >= 0){
        return dp[i][j];
    }
    int res;
    // すべての品物を使った場合
    if(i==n){
        res = 0;
    }
    // その品物が入らない場合
    else if(j < w[i]){
        res = rec(i+1,j);
    }
    // その品物が入る場合
    else {
        // その品物を使う場合と使わない場合で大きい方を求める
        res = max(rec(i+1,j), rec(i+1, j-w[i])+v[i]);
    }
    // 結果をテーブルに記憶する
    return dp[i][j] = res;
}

int main() {
    cin >> n >> W;
    for(int i=0; i<n; i++) cin >> v[i] >> w[i];
    memset(dp, -1, sizeof(dp));
    cout << rec(0,W) << endl;
}



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

B = [list(map(int,input().split())) for i in range(N)]
ans = 10**28
for i in range(2**N):
    cost = 0
    alg = [0]*M
    for j in range(N):
        if i & 2**j>0:
            cost += B[j][0]
            for k in range(M):
                alg[k] += B[j][1+k]
    flag = True
    for k in range(M):
        if alg[k]<X:
            flag=False
            break
    if flag:
        ans = min(cost,ans)

if ans <10**28:
    print(ans)
else:
    print(-1)

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

int main(){
  int n, m, a, b, i;
  cin >> n >> m;
  vector<int> city(n);
  
  for(i=0; i<m; i++){
    cin >> a >> b;
    city.at(a-1) += 1;
    city.at(b-1) += 1;
  }
  

  
  for(i=0; i<n; i++) cout << city.at(i) << endl;
}

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int K;
  cin >> K;
  int sum = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        sum += gcd(gcd(i, j), k);
      }
    }
  }
  cout << sum << endl;
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] x = new int[4];
		for(int i = 0; i < N; i++) {
			String S = sc.next();
			if(S.equals("AC"))
				x[0]++;
			else if(S.equals("WA"))
				x[1]++;
			else if(S.equals("TLE"))
				x[2]++;
			else
				x[3]++;
		}
		System.out.println("AC x " + x[0]);
		System.out.println("WA x " + x[1]);
		System.out.println("TLE x " + x[2]);
		System.out.println("RE x " + x[3]);
	}

}

Measured memory_bytes: 59172
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

int myf(int x,int y){
  	if(x%y==0) return x/y;
  	else return x/y+1;
}

signed main(){
    int N,K;
    cin>>N>>K;
    cout<<myf(N-1,K-1)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int n,w;
int v[100][3];
int dp[10001];

int main(){
  cin >> n >> w;
  for(int i = 0; i < n ; i++){
    cin >> v[i][0] >> v[i][1] >> v[i][2];
  }
  for(int i = 0; i <= 10001; i++){
    dp[i] = 0;
  }
  for(int k = 0; k < n; k++){
    for(int i = 0; v[k][2] > 0; i++){
      int key = min(v[k][2], (int)(1<<i));
      v[k][2] -= key;
      for(int j = w; j >= key*v[k][1]; j--){
        dp[j] = max(dp[j], dp[j-key*v[k][1]] + key*v[k][0]);
      }
    }
  }
  int m = 0;
  for(int i = 0; i < 10001; i++){
    m = max(m, dp[i]);
  }
  cout << m << endl;
}



Measured memory_bytes: 3132
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 09 20:40:07 2018

@author: Fujiichang
"""

if __name__ == "__main__":
    a = map(int, raw_input().split())
    square = a[0] * a[1]
    perimeter = 2*a[0] + 2*a[1]

    print square, perimeter



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

	if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100100;
const int MOD = 1000000007;
typedef pair<bool,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int parent[11451];
int tall[11451];

int searchRoot(int V){
    //頂点Vの親==頂点Vということは頂点Vはその木の根である。
    if(parent[V] == V){
        return V;
    }
    else{
        //一回ごとにparent[V]を更新する。辺の縮約
        return parent[V] = searchRoot(parent[V]);
    }
}

bool same(int X,int Y){
    if(searchRoot(X) == searchRoot(Y)) return true;
    else return false;
}

void unite(int X,int Y){
    //X,Yの高さが高い方の木の「高さ0の根」に高さが低い方の根を付ける
    int Xroot = searchRoot(X);
    int Yroot = searchRoot(Y);
    //同じ根を持つ木を併合することはしなくてよい
    if(Xroot == Yroot) return;
    //高さが高いほうの木を根にして併合
    if(tall[X] > tall[Y]){
        parent[Yroot] = Xroot;
    }
    else if(tall[Xroot] == tall[Y]){
        parent[Yroot] = Xroot;
        //高さが同じとき、YがXの根の下に入るのでYの深さはXより1深くなる
        tall[Y]++;
    }
    else parent[Xroot] = Yroot;
}

int main() {
    int N,Q;cin >> N >> Q;
    //各頂点を高さ0,根をその頂点自身としてで初期化
    for(int i = 0;i<N;i++){
        tall[i] = 0;
        parent[i] = i;
    }
    vector<int> ans;

    for(int i = 0;i<Q;i++){
        int a;cin >> a;
        int x,y;cin >> x >> y;
        if(a == 0){
            unite(x,y);
        }
        if(a == 1) {
            bool ok = same(x,y);
            if(ok) ans.push_back(1);
            else ans.push_back(0);
        }
    }

    for(int i = 0;i<ans.size();i++) cout << ans.at(i) << endl;
    
    // PLEASE GIVE ME THE "ACCEPTED" !
}


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

int main(){
    int h, w, k;
    cin >> h >> w >> k;

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

    vector<vector<int>> ans(h, vector<int>(w));
    int cut = 1;
    int first = -1;
    bool flag = false;

    for(int i=0; i<h; i++){
        int count = 0;

        // search
        for(int j=0; j<w; j++){
            if(s[i][j] == '#'){
                count += 1;
                if(flag == false){
                    first = i;
                    flag = true;
                }
            }
        }

        // fill
        if(count == 0 && first != -1) ans[i] = ans[i-1];
        if(count == 1){
            for(int j=0; j<w; j++) ans[i][j] = cut;
            cut += 1;
        }
        if(count >= 2){
            bool flag2 = false;
            for(int j=0; j<w; j++){
                if(s[i][j] == '#'){
                    if(flag2 == true) cut += 1;
                    flag2 = true;
                }
                ans[i][j] = cut;
            }
            cut += 1;
        }   
    }
    for(int i=0; i<first; i++) ans[i] = ans[first];

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << ans[i][j];
            if(j == w-1) break;
            cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 4152
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
#define pr make_pair
#define X first
#define Y second
typedef long long ll;
ll h,w,n;
ll x,y,s=0;
map <pair<ll,ll>,ll> mp;
int dx[]={-1,0,0,1,-1};
int dy[]={-1,1,-1,0,0};
ll ans[12];
int main()
{
	scanf("%lld%lld%lld",&h,&w,&n);
	ans[0]=1ll*(h-2)*(w-2);
	while(n--)
	{
		scanf("%lld%lld",&x,&y);
		for(ll i=max(x-2,1ll);i<=min(h-2,x);i++)
			for(ll j=max(y-2,1ll);j<=min(w-2,y);j++)
				mp[pr(i,j)]++;
	}
	for(map<pair<ll,ll>,ll>::iterator it=mp.begin(),ed=mp.end();it!=ed;it++)
		ans[it->second]++,s++;
	ans[0]-=s;
	for(int i=0;i<=9;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int n;cin>>n;
    vector<int> S;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin>>t;
        S.push_back(t);
    }
    int ans=0;
    int q;cin>>q;
    for (int i = 0; i < q; i++)
    {
        int T;cin>>T;
        for (int i = 0; i < S.size(); i++)
        {
            if(S[i]==T){
                ans++;
                break;
            }
        }
        
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3208
N, W = map(int, input().split())
items = [list(map(int, input().split())) for i in range(N)]

dp = [[0 for w in range(W+1)] for i in range(N+1)]
for w in range(W+1):
    dp[0][w] = 0
for i in range(N):
    for w in range(W+1):
        if items[i][1] <= w:
            dp[i+1][w] = max(dp[i+1][w-items[i][1]] + items[i][0], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])



Measured memory_bytes: 42472
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}

bool check(string s){
    if(s[0] != 'A')return false;
    ll c = 0;
    for(ll i = 2; i<s.length()-1; i++){
        if(s[i] == 'C')c++;
    }
    if(c != 1)return false;
    ll upper = 0;
    for(ll i = 0; i<s.length(); i++){
        if(s[i]>= 'A' && s[i]<='Z')upper++;
    }
    if(upper != 2)return false;
    return true;
}
  
int main(){
    string s;
    cin>>s;
    if(check(s)){
        cout<<"AC"<<endl;
    }else{
        cout<<"WA"<<endl;
    }
    return 0;
}
    
    



Measured memory_bytes: 256