akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define pi acos(-1)
#define pb push_back
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;

int water[3010],sugar[3010];

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    double A,B,C,D,E,F;
    scanf("%lf%lf%lf%lf%lf%lf",&A,&B,&C,&D,&E,&F);
    for(int i=0; i<=300; i++)
        for(int j=0; j<=300; j++) {
            if(100*i*A+100*j*B>F) continue;
            water[(int)(100*i*A+100*j*B)]=1;
//            printf("%d\n",100*i*A+100*j*B);
        }

    for(int i=0; i<=3000; i++)
        for(int j=0; j<=3000; j++) {
            if(i*C+j*D>F) continue;
            sugar[(int)(i*C+j*D)]=1;
//            printf("%d\n",i*C+j*D);
        }
    double ans=0;
    int sum1=0,sum2=0;
    for(int i=0; i<=3000; i++) {
        if(water[i]) {
            for(int j=0; j<=3000; j++) {
                if(i+j>F) break;
                if(!sugar[j]) continue;
                if(j>((double)((double)i/100.0)*E)) break;
                double sum=((double)(j))/((double)(i+j));
//                printf("%d %d \n",i,j);
                if(sum>=ans) {
                    ans=sum;
                    sum1=i;
                    sum2=j;
                }
            }
        }
    }
    printf("%d %d\n",sum1+sum2,sum2);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

ll X[100005];

int main() {

	ll N, A, B;

	scanf("%lld %lld %lld",&N,&A,&B);

	ll i;

	for (i = 0ll; i < N; i++) {
		scanf(" %lld",&X[i]);
	}

	ll now = 0;

	ll ans = 0ll;

	for (i = 1ll; i < N; i++) {
		if ((X[i] - X[now])*A > B) {
			ans += B;
		}
		else {
			ans += (X[i] - X[now])*A;
		}
		now = i;
	}
	printf("%lld\n",ans);


	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(int argc, char const *argv[]) {
	int a,b,c,d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("%s\n", (c + b - 1) / b <= (a + d - 1) / d ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[2000005];
int child[2000005];
int parent[2000005];
int div1[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            parent[vec[node][i]] = node;
            dfs(vec[node][i]);
            //   child[node] += child[vec[node][i]];
        }
    }
}
void bfs(int node)
{
    queue<int> qu;
    qu.push(node);
    vis[1] = 1;
    while (!qu.empty())
    {
        int top = qu.front();
        //cout << qu.front() << "\n";
        qu.pop();
        vis[top] = 1;
        for (int i = 0; i < vec[top].size(); i++)
        {
            if (!vis[vec[top][i]])
            {
                parent[vec[top][i]] = top;
                qu.push(vec[top][i]);
                vis[vec[top][i]] = 1;
            }
        }
    }
}
void belman(int n, int m, vector<pair<int, pair<int, int>>> vec, int dis[])
{
    for (int i = 0; i <= n + m - 1; i++)
    {
        for (int j = 0; j < vec.size(); j++)
        {
            int u = vec[j].second.first;
            int v = vec[j].second.second;
            int w = vec[j].first;

            if (dis[u] + w < dis[v])
            {
                dis[v] = dis[u] + w;
            }
        }
    }
}
int fun(int a, int b)
{
    if (a > b)
        return 0;
    if (a == b)
        return 1;
    else
    {
        return fun(a + 1, b) + fun(a, b - a);
    }
}
int32_t main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    string str1, str2;
    cin >> str1 >> str2;
    sort(str1.begin(), str1.end(), greater<char>());
    sort(str2.begin(), str2.end(), greater<char>());
    //  cout << str1 << " " << str2 << "\n";
    //cerr << "kcsc"
    //   << "\n";

    for (int i = 0; i < str1.length(); i++)
    {
        for (int j = 0; j < str2.length(); j++)
        {
            if (str2[j] > str1[i])
            {
                cout << "Yes"
                     << "\n";
                return 0;
            }
        }
    }
    if (str2 > str1)
    {
        cout << "Yes"
             << "\n";
    }
    else

        cout << "No"
             << "\n";

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
        ans += a[i] - 1;

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    n, k = map(int, input().split())
    ans = 0

    if k % 2 == 0:
        temp1 = n // (k // 2) - (n // k)
        temp2 = n // k
        ans = temp1 ** 3 + temp2 ** 3
    else:
        temp1 = n // k
        ans = temp1 ** 3
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
a = int(input())
b = list(map(int,input().split()))
c = 0
for i in range(1,a-1):
  if b[i-1]<b[i] and b[i]<b[i+1]:
    c += 1
  elif b[i-1]>b[i] and b[i]>b[i+1]:
    c += 1
print(c)

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

//#define INF 1e9
const ll INF = 1LL << 61;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  if(N % 2){
    ll med = A[N/2];
    REP(i, N){
      ans += abs(A[i]-med);
    }
  }
  else{
    ll med = (A[N/2] + A[N/2-1]) / 2;
    ans = INF;
    REP(j, 2){
      ll cost = 0;
      REP(i, N){
        cost += abs(A[i] - med+j);
      }
      ans = min(ans, cost);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
char ch[1000];
int main()
{
	scanf("%s",ch);
	int n=strlen(ch);
	for (int i=0;i<n-8;i++) printf("%c",ch[i]);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
const int N=2e5+5;
int summ[N];

void solve()
{
    int n,k;cin>>n>>k;
    summ[0]=0;
    for(int i=1;i<=N;i++)
        summ[i]=summ[i-1]+i;
    int ans=0;
    for(int i=k;i<=n+1;i++)
    {
        int min_sum=summ[i-1];
        int max_sum=summ[n]-summ[n-i];
        ans=ans+max_sum-min_sum+1;
        ans%=div;
    }
    cout<<ans<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    //int i=1;
    while(t--)
    {
        //cout<<"Case #"<<i<<": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 5252
#include<bits/stdc++.h>
using namespace std;
#define N 100000
int a[N+1],b[N+1],c[N+1],dp1[N+1],dp2[N+1],dp3[N+1];
int main(){
	int n,i;scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d%d",a+i,b+i,c+i);
	for(i=1;i<=n;i++)
		dp1[i]=a[i]+max(dp2[i-1],dp3[i-1]),
		dp2[i]=b[i]+max(dp1[i-1],dp3[i-1]),
		dp3[i]=c[i]+max(dp1[i-1],dp2[i-1]);
	printf("%d\n",max(max(dp1[n],dp2[n]),dp3[n]));
	return 0;
}
/*1
3
10 40 70
20 50 80
30 60 90
*/
/*2
1
100 10 1
*/
/*3
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
*/

Measured memory_bytes: 2560
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	char s[110];
	cin >> s;
	rep(i, strlen(s) - 8) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int64_t INF = 1LL << 60;

int main() {
	int N,M;
  cin>>N>>M;
  vector<pair<int,int>>P(N);
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    P[i]=make_pair(a,b);
  }
  sort(P.begin(),P.end());
  
  int64_t sum=0;
  int tag=M;
  for(int i=0;i<N;i++){
    int64_t c=P[i].first,d=P[i].second;
    if(d>=tag){sum+=tag*c;break;}
    else{sum+=c*d;tag-=d;}
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3960
N=int(input())
import math

XY=[[int(x) for x in input().rstrip().split()] for i in range(N)]

ans=0
for i in range(N):
  for j in range(N):
    if i<j:
      ans+=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
bb=1
for i in range(1,N+1):
  bb*=i

print(2*ans/N)

Measured memory_bytes: 3064
use proconio::input;
use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


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


Measured memory_bytes: 2104
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin(), x.begin()+n)
// #define int long long
#define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	int A, B, C;
	cin >> A >> B >> C;

	int ans = C - (A-B);
	if (ans < 0) {
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
x, k, d = map(int,input().split())
if x < 0:
    m = 1
else:
    m = 0
x = abs(x)
mod = x%d
ans = x//d
if ans < k:
    if (k - ans)%2 == 0:
        if m == 0:
            print(abs(mod))
        else:
            print(abs(-mod))
    else:
        if m == 0:
            print(abs(mod - d))
        else:
            print(abs(-mod + d))
else:
    if m == 0:
        print(abs(x - k*d))
    else:
        print(abs(-x + k*d))

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

int dp[1000001];
int main()
{
	int n;cin >> n;
	vector<int> hash(n);
	for(int &x:hash)
		cin >> x;
	for(int x:hash)
	{
		if(dp[x]!=0)
		{
			dp[x] = 2;
			continue;
		}
		for(int i = x;i<1e6+1;i+=x)
			dp[i]++;
	}
	int ans = 0;
	for(int x:hash)
	{
		if(dp[x] == 1)
			ans++;
	}
	cout << ans << '\n';
}


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

int max(int a, int b) {
	if (a > b) return a;
	else return b;

}

int main() {

	int X, t;
	scanf("%d%d", &X, &t);
	printf("%d\n", max(0, X - t));
	return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w;
    cin >> h >> w;
    vector<vector<int32>> a(h, vector<int32>(w));
    vector<vector<int32>> b(h, vector<int32>(w));
    REP(i,h)REP(j,w)cin >> a[i][j];
    REP(i,h)REP(j,w)cin >> b[i][j];
    vector<vector<int32>> c(h, vector<int32>(w));
    REP(i,h)REP(j,w){
        c[i][j] = abs(a[i][j] - b[i][j]);
    }
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(13000, false)));
    dp[0][0][c[0][0]] = true;
    REP(i,h)REP(j,w){
        if(i != h-1){    //dp[i+1][j]
            // for(auto x : dp[i+j]){
            //     if(x + c[i+1][j] <= min<int64>(1000, 80 * (min(i + 1, h - i) + min(w + 1, w - j))))
            //         dp[i+1+j].insert(x + c[i+1][j]);
            //     dp[i+1+j].insert(abs(x - c[i+1][j]));
            // }
            REP(k,13000 - c[i+1][j] - 1){
                if(dp[i][j][k]){
                    dp[i+1][j][k + c[i+1][j]] = true;
                    dp[i+1][j][abs(k - c[i+1][j])] = true;
                }
            }
        }
        if(j != w-1){
            // for(auto x : dp[i+j]){
            //     if(x + c[i][j+1] <= min<int64>(1000, 80 * (min(i + 1, h - i) + min(w + 1, w - j))))
            //         dp[i+j+1].insert(x + c[i][j+1]);
            //     dp[i+j+1].insert(abs(x - c[i][j+1]));
            // }
            REP(k,13000 - c[i][j+1] - 1){
                if(dp[i][j][k]){
                    dp[i][j+1][k + c[i][j+1]] = true;
                    dp[i][j+1][abs(k - c[i][j+1])] = true;
                }
            }
        }
    }
    REP(i,13000){
        if(dp[h-1][w-1][i]){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N, K; cin >> N >> K;
    vector<int> A(N, 0);
    rep(i, 0, N) {
        int in;
        cin >> in;
        ++A[in-1];
    }

    sort(A.begin(), A.end(), greater<int>());
    int rewritten = 0;
    rep(i, 0, N) {
        if (i >= K)
            rewritten += A[i];
    }

    cout << rewritten << "\n";
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if (b-a==c-b)
	{
		cout<<"YES\n";
	}
	else
	{
		cout<<"NO\n";
	}
    return 0;
}

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

acab
acb
ab first

abab first

abcab

S^2は無理
abcab
22022
abab
1111

abcdab
330033
自分からみて右側の距離とか
abcdab
330000
そうさするたび26文字のしょり
26*sはいけるけど
最善手の判断にならない
なぞなぞかよ

aba 一致＝奇数でおわる
abab 不一致＝偶数でおわる

偶数で、偶数終わり＝f

*/
int main(){
  string S; cin>>S;
  ll ssz=S.size();
  bool same=false,even=false;
  if(S[0]==S[ssz-1]) same=true;
  if(ssz%2==0) even=true;
  bool ans=same^even;//一致で0=false
  if(ans) cout<<"Second"<<endl;
  else cout<<"First"<<endl;  
}

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

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

Measured memory_bytes: 256
n,y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):#
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n-i-j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
 int N; cin >> N;
 map<int,int> D;
 rep(i,N){
    int d; cin >> d;
    D[d]++;
 }
 int M; cin >> M;
 map<int,int> T;
 rep(i,M){
    int t; cin >> t;
    T[t]++;
 }
 bool ok = true;
 for(auto it = T.begin(); it != T.end(); it++){
    if(it -> second > D[it -> first]) ok = false;
 }
 if(ok) cout << "YES" << endl;
 else cout << "NO" << endl;

}



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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t < x + y || (t & 1) != ((x + y) & 1)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
HP = [list(map(int,input().split())) for _ in range(N)]
HP.sort(key=lambda x: x[0]+x[1])
ceil = max(HP,key=lambda x: x[0])[0]
#dp[i][j] -> i人目まで見る。j人積むときの、座布団の枚数の最小値
dp = [[ceil+1]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    h,p = HP[i-1]
    for j in range(1,N+1):
        if dp[i-1][j-1]<=h:
            dp[i][j] = min(dp[i-1][j],dp[i-1][j-1]+p)
            ans = max(ans,j)
        else:
            dp[i][j] = dp[i-1][j]

print(ans)

Measured memory_bytes: 235164
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>

/*
 *変数
 */
int r;

/*
 *解 
 */
void solve(){
    if(1200>r)printf("ABC");
    else if(2800>r)printf("ARC");
    else printf("AGC");
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>r;
       solve();
       return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a;
    int min_key = 100001;
    rep(i, n){ 
        int tmp; 
        cin >> tmp; 
        a.push_back(tmp); 
        min_key = min(min_key, tmp);
    }

    int ans = 0;
    int next_i = 0;
    bool start = false;
    bool once = false;
    rep(i, n){
        if (a[i] != min_key && start == false){
            ans++;
            start = true;
            once = false;
            next_i = i + (k-2);
        } 
        if (a[i] == min_key && start == true && once == false){
            next_i++;
            once = true;
        }
        if (i == next_i){
            start = false;
        }
    }

    cout << ans << endl;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int H, W; cin >> H >> W;
  string S[H]; rep(i,H) cin >> S[i];
  int dp[H][W] = {}; rep(i,H) fill_n(dp[i],W,INF); dp[0][0] = S[0][0]=='#';
  rep(i,H) rep(j,W) {
    if (i!=0) dp[i][j] = min(dp[i][j],dp[i-1][j]+(S[i][j]!=S[i-1][j]));
    if (j!=0) dp[i][j] = min(dp[i][j],dp[i][j-1]+(S[i][j]!=S[i][j-1]));
  }
  // rep(i,H) debug(dp[i],dp[i]+W);
  int result = (dp[H-1][W-1]+1)/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main (void)
{
   int a,b,c,d,s1,s=0;

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

   if (a>b) s1=b;
   else s1=a;

   if(c>d) s=s1+d;
   else s=s1+c;

   printf("%d\n",s);

   return 0;
}
   


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

#define iter(n) for(int iter_var = 0; iter_var < n; iter_var += 1)
#define rep(i, s, n) for(int i = s; i < n; i += 1)
#define lli long long int
#define INF 1e9

using namespace std;

lli knapsack_iw(int n, int w, vector<pair<int, int>> &v){

  vector<vector<lli>> dp(n + 1, vector<lli>(w + 1, 0));

  rep(i, 1, n + 1) rep(j, 1, w + 1){
    if(v[i - 1].second > j){
      dp[i][j] = dp[i - 1][j];
    } else {
      dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v[i - 1].second] + v[i - 1].first);
    }
  }

  return dp[n][w];
}

lli knapsack_iv(int n, int w, vector<pair<int, int>> &v){

  int maxv = 0; rep(i, 0, n) maxv += v[i].first;
  vector<vector<lli>> dp(n + 1, vector<lli>(maxv + 1, INF));

  int ans = 0;
  lli tmpw = INF;
  rep(i, 0, n) dp[i][0] = 0;

  rep(i, 0, n) {
    rep(j, 0, maxv + 1) if(dp[i][j] < INF){
      dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
      dp[i + 1][j + v[i].first] = dp[i][j] + v[i].second;
      if(j + v[i].first > ans && dp[i + 1][j + v[i].first] <= w) ans = j + v[i].first;
    }
  }
  
  return ans;
}

int main(){

  int n, w; cin >> n >> w;
  vector<pair<int, int>> v;

  iter(n){
    pair<int, int> tmp;
    cin >> tmp.first >> tmp.second;
    v.push_back(tmp);
  }

  //cout << knapsack_iw(n, w, v) << endl;
  cout << knapsack_iv(n, w, v) << endl;

  return 0;
}



Measured memory_bytes: 82696
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M,R;
    cin >> N >> M >> R;
    vector<int> r(R);
    rep(i,0,R)cin >> r[i];
    ll dist[N][N];
    rep(i,0,N)rep(j,0,N)dist[i][j] = INF;
    rep(i,0,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        dist[a][b] = dist[b][a] = c;
    }
    rep(i,0,N){
        rep(j,0,N){
            rep(k,0,N){
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    ll ans = INF;
    sort(r.begin(), r.end());
    do{
        ll num = 0;
        rep(i,0,R-1){
            num += dist[r[i]-1][r[i+1]-1];
        }
        ans = min(ans, num);
    }while(next_permutation(r.begin(), r.end()));

    cout << ans << endl;
}

Measured memory_bytes: 512
import numpy as np

N,M=map(int,input().split())
H=list(map(int,input().split()))
pathes={}
for n in range(N):
  pathes[n+1]=[]
for i in range(M):
  A,B=map(int,input().split())
  pathes[A].append(B)
  pathes[B].append(A)
isGood=np.ones(N)

for k in range(N):
  path=pathes[k+1]
  for p in path :
    if H[k] <= H[p-1]:
      isGood[k]=-1
print(np.count_nonzero(isGood ==1))

Measured memory_bytes: 56092
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl c;
vl d;  // d[v] : 頂点vに書き込む数
ll id = 0;

void dfs(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    d[v] = c[id];
    id++;
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    ll n;
    cin >> n;    

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    c.resize(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(rall(c));

    ll M = 0;
    exrep(i, 1, n-1) {
        M += c[i];
    }

    d.resize(n);
    const ll root = 0;
    dfs(root);

    out(M);
    rep(v, n) {
        cout << d[v] << " ";
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<vector>
using namespace std;

int main(){

    int n;
    scanf("%d", &n);
    vector<int> v1,v2;
    v1.resize(n+1);
    v2.resize(n+1);
    int C[10001] = {0};
    for(int i =0; i<n; i++){
        int a;
        scanf("%d", &a);
        v1[i+1] = a;
        C[v1[i+1]]++;
    }
    
    for(int i=1; i<=10001; i++) C[i] = C[i] + C[i-1];

    for(int j=1; j<=n; j++){
        v2[C[v1[j]]] = v1[j];
        C[v1[j]]--;
    }

    for(int i=1; i<=n; i++){
        if(i>1) printf(" ");
        printf("%d", v2[i]);
    }
    printf("\n");

    return 0;

}


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

using namespace std;

const int N = 1e5 + 9;

int n, h[N], dp[N];

int solve(int i){
    if(i == n - 1)  return 0;
    if(i == n)   return 1e9;

    int &ret = dp[i];
    if(~ret)    return ret;

    return ret = min(abs(h[i] - h[i + 1]) + solve(i + 1), abs(h[i] - h[i + 2]) + solve(i + 2));
}

int main(){

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

    memset(dp, -1, sizeof dp);

    cout << solve(0);
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{

        string s;
        cin >> s;
        int a;
        cin >> a;
        int b = 0;
        for(int i = 0;i < a;i ++) 
        {
            if(s[i] != '1') 
            {cout << s[i];return 0;}
        }
        cout << "1";
        return 0;
}


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

if K == 0:
    ans = N ** 2
    print(ans)
    exit()
    
ans = 0
for i in range(K+1, N+1):
    d = N // i
    m = N % i
    ans += (i - K) * d + max(m-K+1, 0)

print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    int k, n;
    cin >> k >> n;
    vector <int> a(n), b(n - 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++) {
        b[i] = a[i + 1] - a[i];
    }
    int c   = k - a[n - 1] + a[0];
    int ans = c;
    for (auto e : b) {
        if (c < e) c = e;
        ans += e;
    }
    cout << ans - c << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define for_int(i,a,b) for(int i=(a);i<=(b);++i)
#define rep_int(i,a,b) for(int i=(a);i>=(b);--i)
#define for_ll(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep_ll(i,a,b) for(ll i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define db double
#define HPMAX 1005
#define KMP_MAX 1005
#define prime_MAX 1e6+5
#define quick_pow_mod 1e9+7
#define PII pair<int,int>
const int factor_N = 1e7 + 5;
const int tree_arr_N = 1e6 + 5;
using namespace std;
//快读
int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
const int N = 1e5 + 5;
int n, a[N];
int main() {
	n = read();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			for (int k = 1; k <= n; ++k) {
				int t = i * i + j * j + k * k + i * j + i * k + j * k;
				if (t <= n) a[t]++;
				else break;
			}
	for_int(i, 1, n) cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
#define pb push_back
#define mp make_pair
#define MODP(A,B) A=(A+B)%mod
typedef pair<ll,ll> P;
typedef pair<double,double> Pd;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
    ll K,N; cin>>K>>N;
    vec d(N);
    rep(i,N) cin>>d.at(i);
    d.pb(d.at(0)+K);
    ll BIG=0;
    rep(i,N) BIG=max(BIG,d.at(i+1)-d.at(i));
    cout<<K-BIG<<endl;

}

Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int main(){
ll n,a,b;
cin >> n >> a >> b;
if(a == 0){
  cout << a << endl;
}
 else{
    if(n%(a+b)==0){
      cout<<n/(a+b)*a<<endl;
    }
    else{
      if(n%(a+b)>=a){
        cout<<n/(a+b)*a+a<<endl;
      }
      else{
        cout<<n/(a+b)*a+n%(a+b)<<endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb emplace_back
#define pob pop_back
#define ff first
#define ss second
typedef long long int ll;
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define vcc vector<char>
#define vss vector<string>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define test ll t; cin>>t; while(t--)
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,l,k;
    cin>>n>>k;
    vll h(n);
    for(i=0;i<n;i++)
    cin>>h[i];
    vll dp(n);
    for(i=0;i<n;i++)
    dp[i]=1e9;
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    for(j=i-1,l=0;j-l>=0&&l<k;l++)
    dp[i]=min(dp[i],dp[j-l]+abs(h[i]-h[j-l]));
    cout<<dp[n-1];
}

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

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

    let answer = solve(&buf);

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

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

    let k: usize = iterator.next().unwrap().parse().unwrap();
    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    if s.len() <= k {
        return s.iter().map(|it| it.to_string()).collect::<Vec<String>>().join("")
    }

    let mut result = String::new();
    for i in 0..k {
        result.push(s[i]);
    }
    result.push_str("...");
    return result;
}


Measured memory_bytes: 2188
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;


int main(void) {

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

	
	//a < b < c にできるかどうか

	int a, b, c, k; cin >> a >> b >> c >> k;

	while (k--) {

		if (a >= b) {
			b *= 2;
		}
		else c *= 2;
	}


	if (a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;








	return 0;
}


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



int main()
{
    //freopen("input.txt", "r", stdin);


    ll x;
    cin >> x;
    ll sum = 0;
    ll i = 0;
    while (sum < x)
    {
        i++;
        sum += i;
    }

    cout << i << endl;


    return 0;
}



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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    ll N;
    cin >>N;
    
    //-----------------------------------
    ll ans=N*(N-1)/2;

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double nodo = 0;
  int sitsuryo = -1;
  int anssato = -1;
  for (auto i = 0; i <= 30; ++i) {
    for (auto j = 0; j <= 30; ++j) {
      int mizu = A * 100 * i + B * 100 * j;
      if (mizu > F) continue;
      int sato = F - mizu;
      sato = min(sato, mizu / 100 * E);
      for (auto k = 0; k * C <= sato; ++k) {
        int nokori = sato - k * C;
        int realsato = k * C + (nokori/D) * D;
        double nownodo = ((double)realsato) / (realsato + mizu);
        if (nodo <= nownodo) {
          nodo = nownodo;
          sitsuryo = realsato + mizu;
          anssato = realsato;
        }
      }
    }
  }
  cout << sitsuryo << " " << anssato << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  int64_t d, t, s;
  cin >> d >> t >> s;

  cout << (d <= t * s ? "Yes" : "No") << endl;
  return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  string s; cin >> s;
  cout << s.substr(0, 3) << '\n';

  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int a;
            string s;
        cin >> a;
            cin >> s;
                if(a < 3200){
                    cout << "red" << endl;
                }else if(a >= 3200){
                    cout << s << endl;
                }
    return 0;
    }

Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (q h s d n)
  (+ (if (oddp n) (min (* 4 q) (* h 2) s) 0)
     (* (ash n -1) (min (* 8 q) (* h 4) (* s 2) d))))

(princ (main (read) (read) (read) (read) (read)))


Measured memory_bytes: 23988
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

ll keta(ll tmp)
{
  ll i = 1;
  while (tmp / 10 >= 1) {
    i++;
    tmp /= 10;
  }
  return i;
}

ll f(ll a, ll b)
{
  return max(keta(a), keta(b));
}

int main()
{
  ll n;
  cin >> n;
  ll res = LLINF;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      ll a = i;
      ll b = n / i;
      ll c = f(a, b);
      res = min(res, c);
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef vector<int> Vi;
const int INF = (1<<25);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

double data[11][11];
double dp[1 << 12][12];

int main() {
  for(int i=3; i<=10; i++) {
    for(int j=3; j<=10; j++) {
      data[i][j] = sqrt((double)((j+i)*(j+i)-(j-i)*(j-i)));
    }
  }

  int len;
  while( cin >> len ) {
    string s;
    getline(cin, s);

    Vi cur;
    stringstream ss( s );
    while( !ss.eof() ) {
      int r;
      ss >> r;
      cur.pb( r );
    }

    int n = cur.size();

    for(int i=0; i<(1<<12); i++) {
      fill(dp[i], dp[i]+12, INF);
    }

    for(int i=0; i<cur.size(); i++) {
      dp[1<<i][i] = cur[i];
    }

    for(int i=0; i<(1<<n); i++) {
      for(int j=0; j<n; j++) {
	if( dp[i][j] != INF ) {
	  for(int k=0; k<n; k++) {
	    if( k == j ) continue;
	    if( !(i & (1 << k)) ) {
	      if( (i|(1<<k))  == ((1<<n)-1) )  {
		dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j]+data[cur[k]][cur[j]]+cur[k]);
	      }
	      else {
		dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j]+data[cur[k]][cur[j]]);
	      }
	    }
	  }
	}
      }
    }

    bool flag = false;
    for(int i=0; i<n; i++) {
      if( dp[(1<<n)-1][i] <= len ) flag = true;
    }

    if( flag ) cout << "OK" << endl;
    else cout << "NA" << endl;
  }
}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
int main()
{
	ll n,a,sum=0,cnt=0;
	cin>>n>>a;
	ll p=min(a,n-a),q=max(a,n-a);
	sum+=q;
	bool flag=false;
	while(q%p!=0)
	{
		cnt++;
		if(cnt<=1)sum+=2*p*(q/p);
		else sum+=2*p*(q/p)-p;
		ll a=q%p,b=p;
		p=min(a,b),q=max(a,b);
		sum+=q;
		flag=true;
	}
	sum+=2*p*(q/p);
	if(flag)sum-=p;
	cout<<sum<<endl;
}

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

int main()
{
    string s1,s2;
    int k,n,i,j;

    cin>>k;
    cin>>s1;

    n=s1.size();

    if(n<=k)
        cout<<s1<<endl;

    else
    {
        for(i=0;i<k;i++)
        {
            s2+=s1[i];
        }

        cout<<s2<<"..."<<endl;
    }
}


Measured memory_bytes: 3620
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (a, b, x) = get!(usize, usize, usize);

    let ans = b / x - a / x + if a % x == 0 { 1 } else { 0 };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
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; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main ()
{
    string N;cin>>N;
    ll S = 0;
    REP(i,N.size()){
        S+= N[i] - '0';
    }
    int n = stoi(N);
    if(n%S==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    //cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 256
road = int(input())
while road > 0:
    answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
    city = 0
    for _ in range(road):
        c1, c2, w = (int(n) for n in input().split(" "))
        answer[c1][c2] = w
        answer[c2][c1] = w
        city = max(city, c1, c2)
    city += 1
    for i in range(city):
        for j in range(city):
            for k in range(city):
                answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
    sum_ans = [-1 , float("inf")]
    for i in range(city):
        if sum(answer[i][:city]) < sum_ans[1]:
            sum_ans = [i, sum(answer[i][:city])]
    print(*sum_ans)
    road = int(input())

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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

void upd(ll &a, ll b) {
    a = (a + b) % mod;
}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    cout << min(a * b, c);
}


Measured memory_bytes: 764