akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <cstring>
using namespace std;

void _130() {
    int n, x;
    int l[100];
    cin >> n >> x;
    for (int i = 0; i < n; ++i) { 
        cin >> l[i];
    }

    int d = 0;
    for (int i = 0; i < n; ++i) {
        d = d + l[i];
        // cout << d << endl;
        if (d > x) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << n + 1 << endl;
}

void _131() {
    int n, l;
    cin >> n >> l;

    int sum = (l - 1) * n + (1 + n) * n / 2;
    // cout << sum << endl;

    int taste = 0;
    int min_taste = 100;
    for (int i = 0; i < n; ++i) {
        taste = l + (i + 1) - 1;
        // cout << "taste" << taste << endl;
        if (abs(taste) < abs(min_taste))
            min_taste = taste;
        // cout << min_taste << endl;
    }
    cout << sum - min_taste << endl;
}

void _132() {
    int n;
    cin >> n;
    int p[20];
    for (int i = 0; i < n; ++i) 
        cin >> p[i];

    int count = 0;
    int second_value = 0;
    for (int i = 0; i < n - 2; ++i) {
        if ((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])){
            // cout << "1:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
        else if ((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2])){
            // cout << "2:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
    }
    cout << count << endl;
}

void _133() {
    int n, d;
    cin >> n >> d;
    int x[10][10];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    float distance = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            distance = 0;
            for (int k = 0; k < d; ++k) {
                distance += pow(x[i][k] - x[j][k], 2);
                // cout << x[i][k] << " " << x[j][k] << " " << distance << endl;
            }
            distance = pow(distance, 0.5);
            // cout << distance << endl;

            if (abs(distance - ceil(distance)) <= 1e-6)
                count++;
        }
    }

    cout << count << endl;
}

void _134() {
    int n, d;
    cin >> n >> d;

    cout << (n + 2 * d + 1 -1) / (2 * d + 1) << endl;
}

void _135() {
    int n, p[50];
    cin >> n;
    int conflict_count = 0;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        if (p[i] != (i + 1))
            conflict_count++;
    }

    if (conflict_count != 0 && conflict_count != 2){
        cout << "NO" << endl;
        return;
    }

    cout << "YES" << endl;
}

void _136() {
    int n;
    cin >> n;

    char str[10];
    int count = 0;
    for (int i = 0; i < n; ++i) {
        sprintf(str, "%d", i + 1);
        if (strlen(str) % 2 == 1)
            count++;
    }
    cout << count << endl;
}

int main()
{
    _136();
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;
 
long f[105][10];
long p[105][11];

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n); 

    long i,j;
    for(i=0; i<n; i++) {
        for(j=0; j<10; j++) {
            scanf("%ld", &f[i][j]);
        }
    }
    for(i=0; i<n; i++) {
        for(j=0; j<11; j++) {
            scanf("%ld", &p[i][j]);
        }
    }

    long max=-MOD;
    for(i=0; i<(1<<10); i++) {
        if(i==0) continue;

        long value=0;

        for(j=0; j<n; j++) {
            long count=0;
            long k;
            for(k=0; k<10; k++) {
                if((i&(1<<k)) && f[j][k])
                    count++;
            }
            value+=p[j][count];
        }
        max=MAX(max,value);
    }
    printf("%ld\n", max);
 
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
 int main()
{
int i, l[10], v[2], comp;
float dis;
while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0], &v[1]) != EOF){
dis = 0;
comp = 0;
for (i = 0; i < 10; i++){
dis += l[i];
}
dis = dis * 1.0 * v[0] / (v[0] + v[1]);         
for (i = 0; i < 10; i++){
comp += l[i];
if (dis <= comp){
printf("%d\n", i + 1);
break;
}
}
}
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include<functional>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 30005
#define maxn 100005
typedef pair<int,int> PII;
typedef long long LL;

int n,m,k,ans;
struct Node{int to,next;}node[5005];
int head[2010],hcnt;
inline void add(int x,int y){
    node[hcnt].to=y;node[hcnt].next=head[x];
    head[x]=hcnt++;
}
int ct(int u,int fa,int num){
    if(num==0)return 1;
    int temp=1;
    for(int i=head[u];~i;i=node[i].next){
        int e=node[i].to;
        if(e==fa)continue;
        temp+=ct(e,u,num-1);
    }
    return temp;
}
int main(){
    //freopen("in.txt","r",stdin);
    int i,j,x,y;
    mst(head,-1);
    scanf("%d%d",&n,&k);
    for(i=2;i<=n;++i){
        scanf("%d%d",&x,&y);
        add(x,y);add(y,x);
    }
    LL num=1;
    for(int i=0;i<2000000000;++i)num=num*5%MOD+MOD;
    ans=0;
    if(k&1){
        for(i=1;i<=n;++i){
            for(int l=head[i];~l;l=node[l].next){
                int e=node[l].to;
                if(e<=i)continue;
                int temp=ct(i,e,k/2)+ct(e,i,k/2);
                ans=max(ans,temp);
            }
        }
    }
    else{
        for(i=1;i<=n;++i){
            ans=max(ans,ct(i,-1,k/2));
        }
    }
    printf("%d\n",n-ans);
    return 0;
}


Measured memory_bytes: 384
h, w = gets.split.map(&:to_i)
masu = (1..h).map{gets.chomp}

def count_bom(masu, medhod_x, medhod_y, h, w)
  output_num = 0
    [*-1..1].each do |_x|
      [*-1..1].each do |_y|
        if (medhod_x+_x) >= 0 && (medhod_x+_x) < w && (medhod_y+_y) >= 0 && (medhod_y+_y) < h
          #p "元(#{medhod_x} #{medhod_y})  #{medhod_x+_x} #{medhod_y+_y}"
          output_num += 1 if masu[medhod_y+_y][medhod_x+_x] == '#'
        end
      end
    end 
  output_num.to_s
end

result_masu = ''
  h.times do |y|
    w.times do |x|
      result_masu <<
        if masu[y][x] == '#'
          '#'
        else
          count_bom(masu, x, y, h, w)
        end
    end
    result_masu <<"\n"
  end

  puts result_masu

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, D, A;
    cin >> N >> D >> A;
    vector<pll> v(N);
    vector<ll> X(N + 1);
    vector<ll> H(N + 1);
    ll x, h;
    for (int i = 0; i < N; i++) {
        cin >> x >> h;
        v[i] = pll(x, h);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++) {
        X[i] = v[i].first;
        H[i] = v[i].second;
    }
    vector<pll>().swap(v);

    X[N] = LINF;
    H[N] = 0;
    vector<ll> sum(N + 1);
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        H[i] += sum[i];
        if (H[i] <= 0) {
            sum[i+1] += sum[i];
            continue;
        }
        int cnt = ceil((double) H[i] / A);
        ans += cnt;
        sum[i] += -A * cnt;
        int ind = lower_bound(X.begin(), X.end(), X[i] + 2*D + 1) - X.begin();
        sum[ind] += A * cnt;
        sum[i+1] += sum[i];
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define int long long
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}

namespace {
  const int mo = 1e9 + 7;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return x * y % mo;
  }
  inline int pw(int a, int k, int mo) {
    int ans = 1;
    for(; k; k >>= 1, a = mul(a, a))
      if(k & 1) ans = mul(ans, a);
    return ans;
  }
  inline void U(int &x, int y) {
    x = add(x, y);
  }
}
const int N = 1e5 + 233;
struct Mar {
  int m[4][4];
  Mar() {
    memset(m, 0, sizeof m);
  }
  inline void E(void) {
    memset(m, 0, sizeof m);
    m[1][1] = m[2][2] = m[3][3] = 1;
  }
  inline void ovo(void) {
    for(int i = 1; i <= 3; i ++, puts(""))
      for(int j = 1; j <= 3; j ++)
        cout << m[i][j] << " ";
    puts("");
  }
}A, B, f;
int n, m, x[N];
Mar operator * (Mar a, Mar b) {
  Mar c;
  for(int i = 1; i <= 3; i ++)
    for(int j = 1; j <= 3; j ++) {
      for(int k = 1; k <= 3; k ++) 
        c.m[i][j] = add(c.m[i][j], mul(a.m[i][k], b.m[k][j]));
    }
  return c;
}

inline Mar fastpw(Mar a, int k) {
  Mar ans; ans.E();
  for(; k; k >>= 1, a = a * a)
    if(k & 1) ans = ans * a;
  return ans;
}

inline void doit(void) {
  int pos = 0;
  f.E();
  for(int i = 1; i <= m; i ++) {
    f = fastpw(A, x[i] - pos) * f;
    f = B * f;
    pos = x[i] + 1;
    // f.ovo();
  }
  f = fastpw(A, n - pos) * f;
  cout << f.m[1][3] << "\n";
}

main(void) {
  read(n); read(m);
  for(int i = 1; i <= m; i ++) {
    read(x[i]);
  }
  A.m[1][1] = 2; A.m[1][2] = 1; A.m[1][3] = 1;
  A.m[2][1] = 2; A.m[2][2] = 1; A.m[2][3] = 2;
  A.m[3][1] = 1; A.m[3][2] = 0; A.m[3][3] = 1;
  
  B.m[1][1] = 1; B.m[1][2] = 1; B.m[1][3] = 1;
  B.m[2][1] = 0; B.m[2][2] = 1; B.m[2][3] = 2;
  B.m[3][1] = 0; B.m[3][2] = 0; B.m[3][3] = 1;
  doit();
}


Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<string>

using namespace std;

int main(){
    int n, q;
    queue< pair<string, int> > Q;
    string tmp_name;
    int tmp_time;

    cin >> n >> q;

    for(int i=0; i<n; i++){
        cin >> tmp_name >> tmp_time;
        Q.push(make_pair(tmp_name, tmp_time));
    }
    
    pair<string, int> tmp;
    int ans=0;

    while(!Q.empty()){
        tmp = Q.front();
        Q.pop();
        tmp_time = tmp.second;
        if(tmp_time<=q){
            ans += tmp_time;
            cout << tmp.first << " "<< ans << endl;
        }else{
            ans += q;
            Q.push(make_pair(tmp.first, tmp_time-q));
            
        }
    }
    return 0;
}

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

int main(){
    int n;
    char buf[30];

    fgets(buf, sizeof(buf),stdin);
    n = atoi(buf);
    if (n>= 1 && n <= 10){
        int result = n + (n*n) + (n * n * n);
        printf("%d\n",result);
    }
    else
    {
        printf("正しい値を入力してください:1以上10以下");
    }
   }

Measured memory_bytes: 1668
#include<iostream>
#include<queue>

using namespace std;

queue<int> q1, q2;

int d, cnt, N;
int nextarr[1010];
int p[1010];
int flag[1010];
int a[1010][1010];

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

	for(int i = 1; i <= N; i++){
		q1.push(i);
		p[i] = 1;
		nextarr[i] = a[i][1];
	}

	int amount = N * (N - 1);
	int temp;
	while(cnt != amount){
		d++;
		while(!q1.empty()){
			temp = q1.front();
			q1.pop();
			if(nextarr[nextarr[temp]] == temp && flag[temp] < d){
				q2.push(temp);
				q2.push(nextarr[temp]);
				flag[temp] = d;
				flag[nextarr[temp]] = d;
			}
		}

		if(q2.empty()) break;
		
		cnt += q2.size();
		while(!q2.empty()){
			temp = q2.front();
			q2.pop();
			p[temp]++;
			nextarr[temp] = a[temp][p[temp]];
			q1.push(temp);
		}
	}
	if(cnt == amount) cout << d;
	else cout << -1;
}

Measured memory_bytes: 4224
import math
#n = int(input())
#a = list(map(int, input().split()))
N,D = map(int, input().split())

x = [0]*N
for n in range(N):
        x[n] = list(map(int, input().split()))

k = 0
for i in range(N):
        for j in range(i+1,N,1):
                dd = 0
                for d in range(D):
                        dd += math.pow(x[i][d]-x[j][d], 2)
                if math.sqrt(dd).is_integer():
                        k += 1
print(k)


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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    if( (a+b) > (c+d) )
        cout << "Left" << endl;
    else if( (a+b) < (c+d) )
        cout << "Right" << endl;
    else
        cout << "Balanced " << endl;
   
    return 0;
}


Measured memory_bytes: 256
def check(num,memo={}):
  if num==0:
    return 2
  elif num == 1:
    return 1
  elif num in memo:
    return memo[num]
  else:
    memo[num] = check(num-1,memo) + check(num-2,memo)
    return memo[num]

print(check(int(input())))

Measured memory_bytes: 9172
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
using namespace std;

vector<string> S;
int N;
vector<int> checker;

void solve() {
	cin >> N;
	S.resize(N+1);
	S[0] = string("aaaaaaaaaa");
	for (int n = 1; n <= N; n++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end(), [](char a, char b) {
			return a < b;
		});
		S[n] = s;
	}
	sort(S.begin(), S.end());
	S.push_back(string("zzzzzzzzzA"));
	long long ans = 0;
	long long counter = 0;
	for (int i = 2; i <= N+1; i++) {
		if (S[i] == S[i - 1])counter++;
		else {
			if (counter != 0) {
				ans += (counter + 1) * counter / 2;
				counter = 0;
			}
		}
	}
	cout << ans << endl;
	return;
}

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

int dp[17][70001],ax[17][20],ay[17][20],ara[17],n;
map<int,int>mp;

int on(int x,int ps)
{

    return x | (1<<ps);

}


bool ck(int x,int ps)
{
    return (bool)(x & (1<<ps));
}


int solve(int idx,int mask)
{

    if(idx==n)
    {

       int cnt=0,x,y,i,j;

       for(i=0;i<=n;i++)
       {
           if(ck(mask,i)==true)
           {
               mp[i]=mask;  cnt++;

           }

       }



       for(i=0;i<=n;i++)
       {
           if(ck(mask,i)==true)
           {
               for(j=0;j<ara[i];j++)
               {
                   x=ax[i][j];  y=ay[i][j];

                   if((y==1 && mp[x]!=mask) || (y==0 && mp[x]==mask))
                   {
                       cnt=0; break;
                   }

               }

           }

           if(cnt==0)break;

       }


       return cnt;


    }
    else if(dp[idx][mask]!=-1)return dp[idx][mask];
    else
    {

        int s,p,q,r;  s=on(mask,idx);

        p=solve(idx+1,mask);
        q=solve(idx+1,s);

        r=max(p,q);  dp[idx][mask]=r;  return dp[idx][mask];


    }


}


int main()
{


    int a,b,c,i,j,ans;

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

        scanf("%d",&a); ara[i]=a;

        for(j=0;j<a;j++)
        {
            scanf("%d %d",&b,&c);  ax[i][j]=b-1;  ay[i][j]=c;
        }

    }

    memset(dp,-1,sizeof dp);
    ans=solve(0,0);

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



    return 0;
}





Measured memory_bytes: 8336
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n; 
  	cin >> n;
  	cout << (ll)n*(n-1)/2 << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;



int main() {
   
    set <int> s;
    for (ll i=1;i<=3;i++){
        s.insert(i);
    }
    int a,b;
    cin >> a >> b;
    s.erase(a);
    s.erase(b);
    cout << *s.begin() << endl;



}

Measured memory_bytes: 256
a,b,c,d=map(int,list(input()))
x=a*10+b
y=c*10+d

if 1<=x and x<=12 and 1<=y and y<=12:
  print('AMBIGUOUS')
elif 1<=x and x<=12 and not(1<=y and y<=12):
  print('MMYY')
elif not(1<=x and x<=12) and (1<=y and y<=12):
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<climits>
using namespace std;
static long long a, b;

long long gcd(long long a, long long b)
{
	return b == 0 ? a : gcd(b, a%b);
}

int main()
{
	while (scanf("%lld%lld", &a, &b) != EOF)
	{
		long long c = gcd(a, b);
		long long d = a / c*b / c*c;
		printf("%lld %lld\n", c, d);
	}
	return 0;
}


Measured memory_bytes: 3124
import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())

    ans =0
    for i in range(1,N+1):
        if i>K:
            s =0
        else:
            s =math.ceil(math.log2(K/i))
        ans +=(0.5 **s ) /N

    print(ans)


if __name__ == "__main__":
    main()


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

class P
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[][] CSF = new int[N - 1][].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

        for (int i = 0; i < CSF.Length; i++)
        {
            int nowtime = CSF[i][1] + CSF[i][0];
            for (int j = i + 1; j < CSF.Length; j++)
            {
                if (nowtime < CSF[j][1])
                {
                    nowtime = CSF[j][1];
                }
                else
                {
                    nowtime = ((nowtime / CSF[j][2]) + (nowtime % CSF[j][2] != 0 ? 1 : 0)) * CSF[j][2];
                }
                nowtime += CSF[j][0];
            }
            Console.WriteLine(nowtime);
        }
        Console.WriteLine(0);
    }
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        # 0-indexed
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """
    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """
    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            # 上を探しに行く
            ok = mid
        else:
            # 下を探しに行く
            ng = mid
    return ok

# m~idxの間に出現済がない(この範囲の中で自分が最小値)かどうか
def calc1(m):
    cnt = lend - bit.sum(m-1)
    return cnt == 0

# idx~mの間に出現済がない(この範囲の中で自分が最小値)かどうか
def calc2(m):
    cnt = bit.sum(m) - rstart
    return cnt == 0

N = INT()
A = LIST()
# aの昇順に処理できるようにindexで並べておく
idxs = [0] * (N+1)
for i, a in enumerate(A):
    idxs[a] = i + 1

bit = BIT(N+2)
# 先頭と末尾に番兵を仕込む
bit.add(0, 1)
bit.add(N+1, 1)
ans = [0] * (N+1)
for a in range(1, N+1):
    # a(1~N)が格納されているindex
    idx = idxs[a]
    # 左の終点と右の始点は各回固定なので先に取っておく
    lend = bit.sum(idx)
    rstart = bit.sum(idx-1)
    # 自分より小さいindexで最初に自分より小さい値がある場所
    l = bisearch_min(0, idx+1, calc1)
    # 自分より大きいindexで最初に自分より小さい値がある場所
    r = bisearch_max(idx, N+1, calc2)
    # aを使う回数 * a = 左端として使える範囲 * 右端として使える範囲 * a
    ans[a] = (idx-l+1) * (r-idx+1) * a
    # aを出現済とする
    bit.add(idx, 1)
# 全てのaについての合計
print(sum(ans))


Measured memory_bytes: 80464
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n+1-i):
        k = n-i-j
        if 10000*i + 5000*j + 1000*k == y:
            print(i, j, k)
            exit()

print(-1, -1 ,-1)

Measured memory_bytes: 3060
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let mut m=0;
    let mut p=0;
    for c in read::<String>().chars().collect::<Vec<char>>(){
        p=if c!='A'&&c!='T'&&c!='G'&&c!='C'{0}else{p+1};
        if m<p{m=p}
    }
    println!("{}",m);
}

Measured memory_bytes: 4352
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
  s = input()
  if s == 'AC':
    ac += 1
  elif s == 'WA':
    wa += 1
  elif s == 'TLE':
    tle += 1
  else:
    re += 1
print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

vector< vector<int> > G;
// vector<bool> status;
vector<int> color;

// bool dfs_find(int v, int c){
//     // cout << "current vertex: " << v << endl;
//     if(v == c) return true;
//     if(status[v] == true) return false;
//     status[v] = true;
//     for(int i=0; i<G[v].size(); ++i){
//         if(G[v][i] == c) return true;
//         if(dfs_find(G[v][i], c)) return true;
//     }
//     return false;
// }

bool dfs_visit(int v, int c){
    // cout << "current vertex: " << v << endl;
    // cout << "color: " << c << endl;
    color[v] = c;
    for(int i=0; i<G[v].size(); ++i){
        if(color[G[v][i]] == 0) dfs_visit(G[v][i], c);
    }
    return true;
}

int main(){

    int N, M;
    cin >> N >> M;

    int V=N, E=M;
    vector<int> p(N+1);
    for(int i=1; i<=N; i++){
        cin >> p[i];
    }

    G = vector< vector<int> >(V+1);
    color = vector<int>(V+1, 0);
    int x, y;
    for(int i=0; i<E; i++){
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    //TLE
    // int ans = 0;
    // for(int i=1; i<=N; ++i){
    //     status = vector<bool> (V+1, false);
    //     // cout << "start dfs" << endl;
    //     // cout << dfs_find(i, p[i]) << endl;
    //     // cout << dfs_find(p[i], i) << endl;
    //     ans += (int)dfs_find(i, p[i]); 
    // }
    // cout << ans << endl;

    int c = 1;
    for(int i=1; i<=N; ++i){
        if(color[i] != 0) continue;
        // cout << "start dfs" << endl;
        dfs_visit(i, c);
        c++;
    }

    // for(auto it = color.begin(); it != color.end(); ++it){
    //     cout << *it << endl;
    // }

    int ans = 0;
    for(int i=1; i<=N; i++){
        if(color[i] == color[p[i]]) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};

int main(){

  int x,a;
  cin >> x >> a;
  if(x < a)cout << 0 << endl;
  else cout << 10 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] numbers = br.readLine().split(" ");
            Map<String, Long> counted = Arrays.asList(numbers).stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
            counted.entrySet().stream().filter(e -> e.getValue() == 1).forEach(e -> System.out.println(e.getKey()));

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 26836
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

long long N,H;
long long A;
//vector<long long>A(1e5,0);
vector<long long>B(1e5,0);

int main(){

	cin>>N>>H;
	long long Am=0;
	for(int i=0;i<N;i++){
		cin>>A>>B[i];
		Am=max(Am,A);
	}
	
	sort(B.begin(),B.end(),greater<long long>());
	long long i=0;
	int ans=0;
	while(H>0){
		if(Am>=B[i]){
			if(H%Am==0)ans+=H/Am;
			else ans+=H/Am+1;
			break;
		}
		else {
			H-=B[i];
			ans++;
			i++;
		}
	}

	cout<<ans<<endl;

	return 0;

}
	


	




Measured memory_bytes: 1024
n = int(input())
s = list(map(int, input().split()))

s1 = 0
s2 = 0
mini = 100000000

for i in range(n):
    s2 += s[i]

for j in range(n):
    s2 -= s[j]
    s1 += s[j]

    if mini > abs(s2 - s1) :
        mini = abs(s2 - s1)
    else:
        break

print(mini)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<29)


struct SkewHeap{
	SkewHeap *l,*r;
	int val;
};

SkewHeap* meld(SkewHeap* a, SkewHeap* b) {
    if (a==NULL) return b;
    if (b==NULL) return a;
    if (a->val < b->val) swap(a, b);
    a->r = meld(a->r, b);
	std:: swap(a->l, a->r);
    return a;
}
SkewHeap* insert(SkewHeap* a,int v) {
    SkewHeap* b=new SkewHeap;
	b->l=b->r=NULL;
	b->val=v;
	return meld(a,b);
}
int getmax(SkewHeap* a){
	return a->val;
}
SkewHeap* pop(SkewHeap* a){
	SkewHeap* res = meld(a->l,a->r);
	delete a;
	return res;
}
void del(SkewHeap* a){
	if(a->l)del(a->l);
	if(a->r)del(a->r);
	delete a;
}



int n,q;
vector<int> edge[100000];
int marked[100000];
SkewHeap* bh[100000];
long long ans;


void dfs(int u){
	for(int i=0;i<edge[u].size();i++){
		dfs(edge[u][i]);
		bh[u]=meld(bh[u],bh[edge[u][i]]);
		bh[edge[u][i]]=NULL;
	}
	while(bh[u] && marked[u]<getmax(bh[u])){
		ans+=u+1;
		bh[u]=pop(bh[u]);
	}
}


int main(){
	while(cin>>n>>q&&n){
		for(int i=0;i<n;i++)edge[i].clear();
		for(int i=0;i<n;i++)if(bh[i]){
			del(bh[i]);
			bh[i]=NULL;
		}
		for(int i=0;i<n;i++)marked[i]=INF;
		marked[0]=0;
		for(int i=1;i<n;i++){
			int p;
			cin>>p;
			edge[p-1].push_back(i);
		}
		for(int i=0;i<q;i++){
			char op;
			int v;
			cin>>op>>v;
			v--;
			if(op=='M'){
				marked[v]=min(marked[v],i+1);
			}else{
				bh[v]=insert(bh[v],i+1);
			}
		}
		ans=0;
		dfs(0);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 14564
class Mint
  MOD = 1_000_000_007

  attr_reader :x

  def initialize(x)
    @x = ((x % MOD) + MOD) % MOD
  end

  def to_s
    @x.to_s
  end

  def -@
    Mint.new(-@x)
  end

  def +(a)
    Mint.new(@x).add(a)
  end

  def -(a)
    Mint.new(@x).sub(a)
  end

  def *(a)
    Mint.new(@x).mul(a)
  end

  def /(a)
    Mint.new(@x).div(a)
  end

  def add(a)
    @x += a.x
    @x -= MOD if @x >= MOD
    self
  end

  def sub(a)
    @x += MOD - a.x
    @x -= MOD if @x >= MOD
    self
  end

  def mul(a)
    @x = (@x * a.x) % MOD
    self
  end

  def pow(t)
    return Mint.new(1) if t.zero?
    a = pow(t >> 1)
    a = a.mul(a)
    a = a.mul(self) if (t % 2) == 1
    a
  end

  def inv
    pow(MOD - 2)
  end

  def div(a)
    self.mul(a.inv)
  end

  def factorial
    return Mint.new(1) if @x.zero?
    (1..@x).map{|v| Mint.new(v)}.inject(:mul)
  end

  def permutation(k)
    return Mint.new(1) if k.zero?
    (@x - k + 1..@x).map{|v| Mint.new(v)}.inject(:mul)
  end

  def combination(k)
    permutation(k).div(Mint.new(k).factorial)
  end
end

N, K = gets.chomp.split(" ").map(&:to_i)

ans = Mint.new(0)
min_x = (0..K-1).inject(&:+)
max_x = (N-K+1..N).inject(&:+)
ans += Mint.new(max_x - min_x + 1)

(K+1).upto(N+1) do |k|
  min_x += k-1
  max_x += N-k+1
  ans += Mint.new(max_x - min_x + 1)
end
puts ans


Measured memory_bytes: 14400
#include <stdio.h>

int     main(void)
{
    long n, a, b;
    long ans, l;

    ans = 0;
    scanf("%ld %ld %ld", &n, &a, &b);
    ans += (n / (a + b)) * a;
    l = n % (a + b);
    if (a < l) ans += a;
    else ans += l;
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

int main() {
	std::string S;
	std::cin >> S;

	long long K;
	std::cin >> K;

	int result = -1;

	for(char c : S) {
		int n = c - '0';
		if(n == 1) {
			K -= n;
		}
		if(n >= 2 || K <= 0) {
			result = n;
			break;
		}
	}

	std::cout << result << std::endl;

	return 0;
}

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

int relu(int num){
    if(num < 0)num = 0;
    return num;
}

/*i~j文字目の部分文字列が足される合計回数は 2^relu(i-1)+relu(S_LENGTH-j-2) で求められるから、
その計算を取りうる全てのi,jで行い、それらの合計値を出力する。*/
int main(void){
    string S;
    cin >> S;
    int S_LENGTH = S.size();
    ll ans = 0; 
    rep(i,S_LENGTH){
        for(int j = i;j < S_LENGTH;j++){
            int cut_len = j - i + 1;
            ans += stoll(S.substr(i, cut_len)) * pow(2, relu(i-1)+relu(S_LENGTH-j-2));
        }
    }
    cout << ans << endl;
    return 0;
}

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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 100;
int n;
int l[max_n];
int main(){
    cin >> n;
    rep(i, n) cin >> l[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j + 1; k < n; k++){
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
                int len = l[i]+l[j]+l[k];
                int mymax = max(l[i], max(l[j], l[k]));
                int rest = len - mymax;
                
                if(mymax < rest) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define uint unsigned long long
#define ls x << 1
#define rs x << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int inf = 1e9;
vector<int>g[2010];
int dp[2010][2010], dp2[2010][2010], K, v[2010];
void dfs(int x, int fa)
{
	v[x] = 1;
	int s = (int)g[x].size();
	rep(i, 0, s - 1)
	{
		if(fa == g[x][i])continue;
		dfs(g[x][i], x);
		v[x] += v[g[x][i]];
	}
	rep(i, 0, s)
		rep(j, 0, K)
			dp2[i][j] = -inf;
	dp2[0][0] = 1;
	int sz = 0, now = 0;
	rep(i, 0, s - 1)
	{
		if(fa == g[x][i]) continue;
		rep(j, 0, sz)
		{
			dp2[now + 1][j] = max(dp2[now + 1][j], dp2[now][j]);
			for(int k = 0; j + k + 1 <= K; k ++)
				dp2[now + 1][max(j, k + 1)] = max(dp2[now + 1][max(j, k + 1)], dp2[now][j] + dp[g[x][i]][k]);
		}
		now ++;
		sz += v[g[x][i]];
	}
	rep(i, 0, K) dp[x][i] = dp2[now][i];
}
int main()
{
	int n, k;
	n = read();
	k = read();
	K = k;
	rep(i, 1, n - 1)
	{
		int u, v;
		u = read();
		v = read();
		u --, v --;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	int ret = 0;
	rep(i, 0, n - 1)
		rep(j, 0, k)
			ret = max(ret, dp[i][j]);
	printf("%d\n", n - ret);
	return 0;
}



Measured memory_bytes: 30592
#include <iostream>
const int mod = 1e9 + 7;  
using namespace std;

long long result(long long n){
	if(n==0){
		return 1;
	}
	else{
		return result(n-1)*n%mod;
	}
}

int main() {
	long long n;
	cin>>n;
	cout<<result(n)<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i=1; i<=N; ++i) {
    if (i < 10) ++ans;
    else if (i < 100) continue;
    else if (i < 1000) ++ans;
    else if (i < 10000) continue;
    else if (i < 100000) ++ans;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
import sys
N = int(input())
Ls = sorted(list(map(int, input().split())))

if len(Ls) < 3:
    print("0")
    sys.exit(0)

count = 0
for i in reversed(range(len(Ls))):
    max_l = Ls[i]
    for j in range(1,i+1):
        sec_l = Ls[i-j]

        if sec_l < max_l/2:
            break
        if sec_l == max_l:
            continue

        for k in range(j+1,i+1):
            thi_l = Ls[i-k]

            if sec_l == thi_l:
                continue

            if thi_l + sec_l > max_l:
                count += 1
            else:
                break
print(count)


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

using namespace std;

int main(){
    string s;
    while(cin>>s){
        rep(i,0,s.size()){
            if(s[i]=='@'){
                rep(j,0,s[i+1]-'0') cout<<s[i+2];
                i+=2;
            }else cout<<s[i];
        }
        cout<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int max = 0;
		int ans = 1;
		for (int i = 1; i <= n; i++) {
			int x = i;
			int a = 0;
			while (x % 2 == 0) {
				x /= 2;
				a++;
			}
			if (max < a) {
				max = a;
				ans = i;
			}
		}

		System.out.println(ans);

		sc.close();
	}

}


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

void selectionSort(int A[], int N){
    int minj,count=0;
    for(int i=0;i<N;i++){
        minj=i;
        for(int j=i;j<N;j++){
            if(A[j]<A[minj]){
                minj=j;
            }
        }
        if(i!=minj){
            swap(A[i],A[minj]);
            count++; 
        }

    }
    for(int i=0;i<N;i++){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;
}

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


Measured memory_bytes: 3108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    if (s.length()<t.length())cout<<"UNRESTORABLE";
    else
    {
        bool flag0=true;
        for (int i=s.length()-t.length(); i>=0; --i)
        {
            bool flag=true;
            for (int j=0; j<=t.length()-1; ++j)
                if (!(s[i+j]==t[j]||s[i+j]=='?'))
                {
                    flag=false;
                    break;
                }
            if (flag)
            {
                for (int j=0; j<=i-1; ++j)
                    if (s[j]=='?')
                        cout<<'a';
                    else cout<<s[j];
                cout<<t;
                for (int j=i+t.length(); j<=s.length()-1; ++j)
                    if (s[j]=='?')
                        cout<<'a';
                    else cout<<s[j];
                flag0=false;
                break;
            }
        }
        if (flag0)cout<<"UNRESTORABLE";
    }
}

Measured memory_bytes: 256
def prime_table(m):
    t = [True] * (m + 1)
    i = 2
    while i * i <= m:
        if t[i]:
            j = i + i
            while j <= m:
                t[j] = False
                j += i
        i += 1
    return t
    # t[i] = i が素数ならTrue


Q = int(input())
pt = prime_table(10 ** 5)
sn = [False] * (10 ** 5 + 1)
for i in range(3, 10 ** 5, 2):
    sn[i] = pt[i] and pt[(i + 1) // 2]
c = [0] * (10 ** 5 + 1)
for i in range(3, 10 ** 5, 2):
    c[i] = c[i - 2] + (1 if sn[i] else 0)
    # print(i, c[i])
for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r] - c[l - 2])

Measured memory_bytes: 6900
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
ll a,ans;
priority_queue<ll> q;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for (int i=0;i<n;++i) cin>>a,q.push(a);
	while (m--)
	{
		ll t=q.top();
		q.pop();
		t/=2;
		q.push(t);
	}
	while (!q.empty()) ans+=q.top(),q.pop();
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define endl "\n"
const int N = 1e6, inf = 1e9;
typedef long long ll;
#define deb(x) cout << #x << " = " << x << endl;
#define debg cout << "yes" << endl;

#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL)
#define Test  \
    int t;    \
    cin >> t; \
    while (t--)
#define pb push_back
#define F first
#define S second
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, b, n) for (int i = b; i < n; i++)
#define fon(i, n) for (int i = n - 1; i >= 0; i--)
#define Ln length()
#define pb push_back
#define mp make_pair
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x;
    x=a*c;
    x=max(x,a*d);
    x=max(x,b*c);
    x=max(x,b*d);
    cout<<x<<endl;

}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var A1 = input[0];
            var A2 = input[1];
            var A3 = input[2];
            var max = Math.Max(A1, Math.Max(A2, A3));
            var min = Math.Min(A1, Math.Min(A2, A3));

            Console.WriteLine(max - min);
        }
    }
}

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

int main(){
	int k;
  cin>>k; 
  string palabra;
  cin>>palabra;
  int tamano;
  tamano=palabra.size();
    if (tamano>k){
          for(int i=0;i<k;i++){
          cout<<palabra[i];
          }
          cout<<"...";
      }
      else{
        cout<<palabra<<endl;
    }
      
}

Measured memory_bytes: 3596
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 805;

int n,m,K;
string s[maxn];
bool vis[maxn][maxn];
int d[maxn][maxn];
int ret;
int dir[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};
int cal(int x,int y,int tx,int ty) {
  return (abs(tx-x)+abs(ty-y)+K-1)/K;
}

int main() {
 // freopen("in.cpp","r",stdin);
  cin>>n>>m>>K;
  for(int i=0; i<n; i++)cin>>s[i];
  ret=1000000007;
  int sx,sy;
  for(int i=0; i<n; i++)
    for(int j=0; j<m; j++)
      if(s[i][j]=='S') {
        sx=i,sy=j;
      }
  queue<int>qx,qy;
  qx.push(sx);
  qy.push(sy);
  vis[sx][sy]=1;
  while(!qx.empty()) {
    int x=qx.front();
    qx.pop();
    int y=qy.front();
    qy.pop();
    ret=min(ret,cal(x,y,x,0)+1);
    ret=min(ret,cal(x,y,x,m-1)+1);
    ret=min(ret,cal(x,y,0,y)+1);
    ret=min(ret,cal(x,y,n-1,y)+1);
    for(int i=0; i<4; i++) {
      int nx=x+dir[i][0];
      int ny=y+dir[i][1];
      if(nx<0||nx>=n||ny<0||ny>=m||vis[nx][ny]||s[nx][ny]=='#')continue;
      d[nx][ny]=d[x][y]+1;
      if(d[nx][ny]<=K) {
        vis[nx][ny]=1;
        qx.push(nx);
        qy.push(ny);
      }
    }
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 4224
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

mm   = inputs[0][1]
list = inputs[1..-1]

# body
list.sort_by!{|c, n| c }
if $debugFlag
  p mm
  p list
end

cost = 0
got  = 0
idx  = 0
while mm - got > 0
  delta = [ list[idx][1], mm - got ].min
  cost += list[idx][0]*delta
  got  += delta
  idx += 1
end

puts cost


Measured memory_bytes: 13688
#include<stdio.h>

int main()

{

int N,a[1000],min=0,i,max,d;

scanf("%d",&N);

for(i=0;i<N;i++)

{

scanf("%d",&a[i]);

}

min=a[0];

max=a[0];

for(i=1;i<N;i++)

{

if(min>a[i])

min=a[i];

if(max<a[i])

max=a[i];

}

d=max-min;

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

return 0;

}

Measured memory_bytes: 2160
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();

  println!("{}", (a + b) % 24);
}



Measured memory_bytes: 4352
#include <cstdio>
#include <cassert>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;

typedef long long LL;
#define X first
#define Y second
typedef pair<LL, LL> pii;
const int N = 1e6 + 100;

char s[2000000];
int main() {
	int ans = 0;
	scanf("%s", s + 1);
	int len = strlen(s + 1);
	bool flag = false;
	s[0] = '0';
	for(int i = len; i >= 0; i --) {
		ans += min(s[i] - '0', 10 - s[i] + '0');
		if(s[i] > '5') s[i - 1] ++;
		else if(s[i] == '5' && s[i - 1] >= '5') s[i - 1] ++;			
	}
	printf("%d\n", ans);

}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<29)//INF
#define F first
#define S second
#define VS vector<string>
#define VI vector<int>
#define REPI(i,s,n) for(int i=s;i<n;i++)//sからn未満の間iを回す
#define REPJ(j,s,n) for(int j=s;j<n;j++)//sからn未満の間iを回す
#define RREPI(i,s,n) for(int i=s;i>=n;i--)//sからn以下の間iを回す
#define RREPJ(j,s,n) for(int j=s;j>=n;j--)//sからn以下の間jを回す
#define ALL(a) a.begin(),a.end()//ソートとかに使える sort(ALL(vec))のように
#define SET(a,c) memset(a,c,sizeof(a));//aをc（0or1）で初期化する
#define DEBUGONE(x) cout<<#x<<" : "<<x<<endl;//デバックで一つの変数を表示
#define DEBUGTWO(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;//デバックで二つの変数を表示
#define DEBUGTHREE(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;//デバックで三つの変数を表示
#define OUTONE(x) cout<<x<<endl;//一つの変数を表示
#define OUTTWO(x,y) cout<<x<<" "<<y<<endl;//二つの変数を表示
#define OUTTHREE(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;//三つの変数を表示
typedef long long int64;
typedef pair<string,int> Psi;
typedef pair<int,int> Pii;
main(){
  int n,m;
  int d[1001];
  int c[1001];
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>d[i];
  }
  for(int i=1;i<=m;i++){
    cin>>c[i];
  }
  int dp[1001][1001];
  for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++){
      if(i<j){
	dp[i][j]=INF;
      }
      else if(i==0||j==0){
	dp[i][j]=0;
      }
      else{
	dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+c[i]*d[j]);
      }
    }
  }
  cout<<dp[m][n]<<endl;
}

Measured memory_bytes: 5080
#include <iostream>
#include <cstdio>
#include <cstring>
#define MN 550000

int w = 1, tot;
int ch[MN * 12][3];
int n, len, ans[MN];
bool tag[MN * 12];
char t[MN];

void ins(int x)
{
	int now = w, X = x;
	for(int i = 0; i < n - 1; i++)
	{
		if(!ch[now][x % 3]) ch[now][x % 3] = ++tot;
		now = ch[now][x % 3];
		x /= 3;
	}
	ch[now][x] = X;
}

void pushdown(int x)
{
	if(tag[x])
	{
		std::swap(ch[x][1], ch[x][2]);
		tag[ch[x][0]] ^= 1;
		tag[ch[x][1]] ^= 1;
		tag[ch[x][2]] ^= 1;
		tag[x] = 0;
	}
}

int get(int x)
{
	int now = w;
	for(int i = 0; i < n; i++)
	{
		pushdown(now);
		now = ch[now][x % 3];
		x /= 3;
	}
	return now;
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) w *= 3; tot = w;
	scanf("%s", t + 1); len = strlen(t + 1);
	for(int i = 0; i < w; i++) ins(i);
	for(int i = 1; i <= len; i++)
	{
		if(t[i] == 'S') tag[w] ^= 1;
		else
		{
			int now = w;
			for(int j = 0; j < n; j++)
			{
				pushdown(now);
				int x = ch[now][0], y = ch[now][1], z = ch[now][2];
				ch[now][0] = z; ch[now][1] = x; ch[now][2] = y;
				now = ch[now][0];
			}
		}
	}
	for(int i = 0; i < w; i++) ans[get(i)] = i;
	for(int i = 0; i < w; i++) printf("%d ", ans[i]);
}

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

typedef long long LL;

int n;
LL A, B;

LL solve(){
    if(A > B)   return 0;
    if(A == B)  return 1;
    if(n == 1){
        return 0;
    }
    if(n == 2){
        return 1;
    }
    LL low = A * (n - 1) + B;
    LL top = A + B * (n - 1);
    return top - low + 1;
}

int main(){
    while(~scanf("%d %lld %lld", &n, &A, &B)){
        printf("%lld\n", solve());
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    string s,t; cin >> s >> t;
    vector<int> start(26,-1);
    vector<int> goal(26,-1);
    rep(i,s.size()){
        int a = s[i]-'a';
        int b = t[i]-'a';

        if(start[a] != -1 || goal[b] != -1){
            if(start[a] != b || goal[b] != a){
                cout << "No" << endl;
                return 0;
            }
        }
        start[a] = b;
        goal[b] = a;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776