akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define MAXN 105
using namespace std;
ll h,w,dp[MAXN][MAXN];
char mt[MAXN][MAXN];
int main(){
    cin>>h>>w;
    for (int i=1; i<=h; i++)
        for (int j=1; j<=w; j++)
            cin>>mt[i][j];
        
    if (mt[1][1]=='#') dp[1][1]=1;
    else dp[1][1]=0;
    for (int i=2; i<=w; i++) dp[1][i]=dp[1][i-1]+1*(ll)(mt[1][i]=='#' && mt[1][i-1]=='.');
    for (int i=2; i<=h; i++) dp[i][1]=dp[i-1][1]+1*(ll)(mt[i][1]=='#' && mt[i-1][1]=='.');
    for (int i=2; i<=h; i++)
        for (int j=2; j<=w; j++)
            dp[i][j]=min(dp[i-1][j]+1*(ll)(mt[i][j]=='#' && mt[i-1][j]=='.'),dp[i][j-1]+1*(ll)(mt[i][j]=='#' && mt[i][j-1]=='.'));
    
    // for (int i=1; i<=h; i++){
    //     for (int j=1; j<=w; j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }

    cout<<dp[h][w]<<endl;
    return 0;
}

Measured memory_bytes: 384
import sys
n, k = map(int, input().split())
s = list(input())
left = 0
right = 0
if s[0] == "L":
    left = 1
if s[n-1] == "R":
    right = 1
count = 0
if n == 1:
    print(0)
    sys.exit()
for i in range(n-1):
    if s[i] == "R" and s[i+1] == "L":
        count += 1
if k < count:
    count -= k
    ans = n - count*2 - left - right
    print(ans)
elif k == count:
    if left == right == 1:
        print(n-2)
    else:
        print(n-1)
else:
    print(n-1)

Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};
Node *root, *NIL;

void insert(int k) {
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z=(Node*)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x != NIL) {
    y=x;
    if(z->key < x->key) {
      x=x->left;
    }else {
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL) {
    root=z;
  }else {
    if(z->key < y->key) {
      y->left=z;
    }else {
      y->right=z;
    }
  }
}
void inorder(Node *u) {
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u==NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n,i,x;
  string com;
  cin >> n;
  for(i=0;i<n;i++) {
    cin >> com;
    if(com=="insert") {
      cin >> x;
      insert(x);
    } else if(com=="print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 26644
#include <iostream>
#include <string>
using namespace std;
int CountOrder(int N,int M,int table[10],int T,int S,int& order){
    if(M == 0){
        if(T == S){
            return order;
        }
        else{
            order++;
            return 0;
        }
    }
    for(int i=1;i<=N;i++){
        if(table[i] == 0){
            table[i] = 1;
            if(CountOrder(N, M - 1, table, T, S * 10 + i, order)){
                return order;
            }
            table[i] = 0;
        }
    }
    return 0;
}
int main(void){
    int N;
    int table[10] = {0};
    int P=0,Q=0;
    
    cin >> N;
    
    for(int i=1;i<=N;i++){
        int x;
        cin >> x;
        P = P * 10 + x;
    }
    for(int i=1;i<=N;i++){
        int x;
        cin >> x;
        Q = Q * 10 + x;
    }
    int order = 1;
    int Pcount,Qcount;
    Pcount = CountOrder(N,N,table,P,0,order=1);
    for(int i=1;i<=N;i++)table[i] = 0;
    Qcount = CountOrder(N,N,table,Q,0,order=1);
    int ans = abs(Pcount - Qcount);
    cout << ans;
}


Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
 
int calcfrog2(vector<int> &arr, int k){
	vector<int> dp(arr.size(), 0);
	int N = arr.size() - 1;
	dp[N] = 0;
	for(int i=N-1;i>=0;i--){
		//f(i,i+k) + f(i+k,N)
		int min_val = INT_MAX;
		for(int j=1;j<=k;j++){
			if(i+j>N)break;
			int valk = abs(arr[i] - arr[i+j]) + dp[i+j];
			min_val = min(min_val, valk);
		}
		dp[i] = min_val;
	}
	return dp[0];
}
 
int main() {
	// your code goes here
	int N = 0;
	cin>>N;
	int k = 0;
	cin>>k;
	vector<int> arr;
	while(N--){
		int val = 0;
		cin>>val;
		arr.push_back(val);
	}
	cout<<calcfrog2(arr, k);
	return 0;
}


Measured memory_bytes: 3648
A, B, C, X, Y = map(int, input().split())

if A + B > 2 * C:
    ans = 2 * C * min(X, Y)
else:
    ans = A * min(X, Y) + B * min(X, Y)

Z = abs(X - Y)
D = A if X >= Y else B
if D > 2 * C:
    ans += 2 * C * Z
else:
    ans += Z * D

print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

struct graph {
    vector<int> v;
    int oya;
    ll cnt;
};

int main(){
    int n, q; cin >> n >> q;
    vector<graph> vs(n);
    rep(i,n-1){
        int a, b; cin >> a >> b;
        vs[a-1].v.emplace_back(b-1);
        vs[b-1].v.emplace_back(a-1);
        vs[i].cnt = 0;
    }
    vs[n-1].cnt = 0;
    rep(i,q){
        int c, d; cin >> c >> d;
        vs[c-1].cnt += d;
    }
    vs[0].oya = 0;
    stack<int> st;
    rep(i,vs[0].v.size()) {
        st.push(vs[0].v[i]);
        vs[vs[0].v[i]].oya = 0;
        vs[vs[0].v[i]].cnt += vs[0].cnt;
    }
    while (!st.empty()){
        int s = st.top(); st.pop();
        rep(i,vs[s].v.size()){
            if (vs[s].v[i] != vs[s].oya){
                st.push(vs[s].v[i]);
                vs[vs[s].v[i]].oya = s;
                vs[vs[s].v[i]].cnt += vs[s].cnt;
            }
        }
    }
    /*
    rep(i,n){
        cout << i << ": oya = " << vs[i].oya << " : " << vs[i].cnt << " : ";
        rep(j,vs[i].v.size()){
            cout << vs[i].v[j] << " ";
        }
        cout << endl;
    }
    */
    rep(i,n-1) cout << vs[i].cnt << " ";
    cout << vs[n-1].cnt << endl;
}

Measured memory_bytes: 17908
import sys
 
primes = [1] * 500000
primes[0] = 0
 
for i in range(3, 1000, 2):
    if primes[i // 2]:
        primes[(i * i) // 2::i] = [0] * len(primes[(i * i) // 2::i])
 
for i in sys.stdin:
    n = int(i)
    if n < 4:
        print(n - 1)
    else:
        print(sum(primes[:(n + 1) // 2]) + 1)



Measured memory_bytes: 15012
X = int(input())
X = (X-9)%7
if X<0: X = X+7
y = ''
if X==0:
	y = 'sat'
elif X==1:
	y = 'sun'
elif X==2:
	y = 'mon'
elif X==3:
	y = 'tue'
elif X==4:
	y = 'wed'
elif X==5:
	y = 'thu'
elif X==6:
	y = 'fri'
print(y)


Measured memory_bytes: 5592
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    int l[N];
    REP(i, N) cin >> l[i];
    sort(l, l + N);
    int ans = 1e9;
    do
    {
        for (int i = 1; i <= N - 2; ++i)
        {
            for (int j = i + 1; j <= N - 1; ++j)
            {
                for (int k = j + 1; k <= N; ++k)
                {
                    int mp = 0;

                    int sum = l[0];
                    for (int m = 1; m < i; ++m)
                    {
                        sum += l[m];
                        mp += 10;
                    }
                    mp += abs(A - sum);

                    sum = l[i];
                    for (int m = i + 1; m < j; ++m)
                    {
                        sum += l[m];
                        mp += 10;
                    }
                    mp += abs(B - sum);
                    
                    sum = l[j];
                    for (int m = j + 1; m < k; ++m)
                    {
                        sum += l[m];
                        mp += 10;
                    }
                    mp += abs(C - sum);

                    ans = min(ans, mp);
                }
            }
        }
    } while(next_permutation(l, l + N));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else if(a==b){
        printf("a == b\n");
    }
    return 0;
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n+1], b[n+1];
    map<int, int> maap;
    for(int i=1; i<=n; i++) {cin >> a[i]; b[i]=a[i];}
    sort(a+1, a+n+1);
	for(int i=1; i<=n; i++){
		if(i<(n/2+1)) maap[a[i]]=a[n/2+1];
		else maap[a[i]]=a[n/2];
	}
	for(int i=1; i<=n; i++){
		cout << maap[b[i]] << endl;
	}
    return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int c = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		c += ( (i + 1) % 2 == 1 && a % 2 == 1);
	}
	cout << c << endl;
}



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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;

class BIT {
    public:
    int n;
    vector<int> bit;
    
    BIT(int n){
        this->n = n;
        bit.resize(n);
        fill(bit.begin(), bit.end(), 0);
    }

    void add(int idx, int x){
        for(int i=idx;i<=this->n;i+=i&-i) bit[i] += x;
    }

    //bit[1]からbit[end]までの和 (閉区間)
    int sum(int end){
        int ret = 0;
        for(int i=end;i>=1;i-=i&-i) ret += bit[i];
        return ret;
    }

    int count_swap(vector<int> v){
        int ret = 0;
        reppp(i, 1, n){
            add(v[i], 1);
            ret += i - sum(v[i]);
        }
        return ret;
    }
};

int main(){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n+1, 0);
    for(int i=1;i<=n;i++){
        cin >> a[i];
        a[i] += (i?a[i-1]:0LL) - k;
    }

    vector<ll> sorted_a(a);
    sort(all(sorted_a));

    ll ans = 0;
    BIT tree = BIT(n+2);
    for(int i=n;i>=0;--i){
        int idx = int(lower_bound(all(sorted_a), a[i]) - sorted_a.begin()) + 1;
        if(i != n) ans += ll(n-i - tree.sum(idx-1));
        tree.add(idx, 1);
    }
    cout << ans << endl;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = line[0], L = line[1];

            var array = new int[N+1];
            var min = int.MaxValue;

            for (var i = 1; i <= N; i++)
            {
                min = Math.Min(Math.Abs(L + i - 1), min);
                array[i - 1] = L + i - 1;
            }

            var total = 0;
            for (var i = 0; i < N; i++)
            {
                if (min == Math.Abs(array[i])) continue;
                total += array[i];
            }
            Console.WriteLine(total);
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,p[1000],i,j,k,c=0,ans=0;
    cin>>n>>a>>b;
    for(i=0;i<n;i++)
        cin>>p[i];
    sort(p,p+n);
    for(i=0;i<n;i++)
    {
        ans=0;
        if(p[i]<=a&&p[i]!=0)
        {
            for(j=i+1;j<n;j++)
            {
                if(p[j]>a&&p[j]<=b&&p[j]!=0)
                {
                    for(k=j+1;k<n;k++)
                    {
                        if(p[k]>b)
                        {
                            c++;
                            p[i]=0;
                            p[j]=0;
                            p[k]=0;
                            ans=1;
                            break;
                        }
                    }
                }
                if(ans==1)
                    break;
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3644
H,W=map(int,input().split())
s=[]
for i in range(H):
   s.append(input())

dis=[[-1,0],[1,0],[0,-1],[0,1]]

for i in range(H):
    for j in range(W):
        if s[i][j]=='#':
            isfound=False
            for k in dis:
                if  0<=i+k[0]<H and 0<=j+k[1]<W:
                    if s[i+k[0]][j+k[1]]=='#' :
                        isfound=True
                else:
                    continue

            if not isfound:
                print("No")
                exit()

print("Yes")


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a < b && b < c)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 17352
#include <bits/stdc++.h>
using namespace std;
/*long long int f(long long int x){
	long long int ans=0;
for(long long int i=1;i<pow(x,0.5);i++){if(x%i==0){ans++;
}
}
ans=2*ans;
if(pow(x,0.5)==(long long int)pow(x,0.5)){ans+=1;
}
return ans;
}*/
int main() {
    cin.tie(NULL); cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    int t; t=1;
while(t--){
	long long int n; cin>>n;
	n--;
long long int ans=0;
	for(long long int i=1;i<=n;i++){ans+=(n/i);}
	cout<<ans;

}
   
	return 0;
}

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

void solve(){
 char c;
 int cnt[26]={};
 while(cin>>c){
  c=tolower(c);
  cnt[c-'a']++;
 }
 FOR(i,26){
  char cc='a'+i;
  cout<<cc<<" : "<<cnt[i]<<endl;
 }
}

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

Measured memory_bytes: 1140
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] data = in.readLine().split(" ");
        long x = Long.parseLong(data[0]);
        long k = Long.parseLong(data[1]);
        long d = Long.parseLong(data[2]);
        x = Math.abs(x);
        if (d < x) {
            long s = Math.min(k, x / d);
            x -= s * d;
            k -= s;
        }
        if (k % 2 == 0) {
            System.out.println(x);
        } else {
            System.out.println(d - x);
        }
    }
}


Measured memory_bytes: 32624
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<double> A(N);
  REP(i,N){
    double tmp;
    cin >> tmp;
    A[i] = 1/tmp;
    
  }
  double ans =0;
  REP(i,N) ans += A[i];
  cout << setprecision(8) << 1/ans << endl; 
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
for(;;) {
	int H=sc.nextInt();
	int W=sc.nextInt();
	if(H==0&&W==0)break;
	else {
		for(int a=0;a<H;a++) {
			for(int s=0;s<W;s++) {
				if(a==0||a==H-1) {
					System.out.print("#");
				}else if(s==0||s==W-1) {
					System.out.print("#");
				}else {
					System.out.print(".");
				}
			}
			System.out.println();
		}
	}System.out.println();
}
sc.close();
  }
}






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

int main() {
	long long a,b,c,d,ans;
	cin>>a>>b>>c>>d;
	long long ab[4];
	
	ab[0]=a*c;
	ab[1]=a*d;
	ab[2]=b*c;
	ab[3]=b*d;
	
	sort(ab,ab+4);
	cout<<ab[3]<<endl;
	// your code goes here
	return 0;
}

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

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

int main()
{
    int N;
    cin >> N;

    long long result = 1;
    long long limit = pow(10, 18);
    vector<long long> a(N);

    rep(i, N)
    {
        cin >> a.at(i);
        if (a.at(i) == 0)
        {
            cout << "0" << endl;
            return 0;
        }
    }

    rep(i, N)
    {
        

        if (a.at(i) <= limit / result)
        //これがresult * a.at(i) <= 10^18の条件
        {
            result *= a.at(i);
        }
        else{
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << result << endl;
    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define forall(it, c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

template <typename T> inline void read(T &x) {
	x = 0; bool f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	for (;  isdigit(c); c = getchar()) x = x * 10 + (c & 15);
	if (!f) x = -x;
}

const int maxn = 1 << 20;
int K, n;
int pw[15];
int ans[maxn];
char s[2 << 17];

struct tree {
	static const int maxn = 1 << 20;
	int go[maxn][3];
	int lz[maxn], id[maxn];
	int tot;
	void push(int x) {
		swap(go[x][1], go[x][2]);
		lz[x] ^= 1;
	}
	void pd(int x) {
		if (lz[x]) {
			push(go[x][0]);
			push(go[x][1]);
			push(go[x][2]);
			lz[x] = 0;
		}
	}
	void build(int &x, int lvl, int num) {
		x = ++ tot;
		if (K == lvl) {
			id[x] = num;
			return ;
		}
		build(go[x][0], lvl + 1, num);
		build(go[x][1], lvl + 1, num + pw[lvl]);
		build(go[x][2], lvl + 1, num + 2 * pw[lvl]);
	}
	void add(int x, int lvl) {
		if (K == lvl) return ;
		pd(x);
		add(go[x][2], lvl + 1);
		swap(go[x][1], go[x][2]);
		swap(go[x][0], go[x][1]);
	}
	void prt(int x, int lvl, int num) {
		if (K == lvl) {
			ans[id[x]] = num;
			return ;
		}
		pd(x);
		prt(go[x][0], lvl + 1, num);
		prt(go[x][1], lvl + 1, num + pw[lvl]);
		prt(go[x][2], lvl + 1, num + 2 * pw[lvl]);
	}
} tr;

int main() {
	read(K);
	rep(i, K + 1) pw[i] = i ? 3 * pw[i - 1] : 1;
	n = pw[K];
	int rt = 0;
	tr.build(rt, 0, 0);
	scanf("%s", s);
	int m = strlen(s);
	rep(i, m) {
		if (s[i] == 'S') tr.push(rt);
		else tr.add(rt, 0);
	}
	tr.prt(rt, 0, 0);
	rep(i, n) printf("%d ", ans[i]);
	puts("");
	return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

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

   if (s.size() == 1) {
      cout << s << endl;
   } else {
      bool ok = true;
      repp (i, 1, s.size()) {
         if (s[i] != '9') {
            ok = false;
         }
      }
      if (count(all(s), '9') == s.size()) {
         cout << s.size() * 9 << endl;
      } else {
         cout << (s.size()-1) * 9 + s[0]-'1'+ok << endl;
      }
   }

   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <vector>
#include <algorithm>
struct str{
	int x0;
	int y0;
}x[200010];
bool cmp1(str a, str b)
{
	return a.x0<b.x0;
}
bool cmp2(str a, str b)
{
	return a.y0>b.y0;
}

std::vector<str> V1,V2;
std::set<int> S1,S2;
long long int y[200010];
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		S1.clear();
		S2.clear();
		V1.clear();
		V2.clear();
		
		int a;
		scanf("%d",&a);
		
		long long int ans = 0;
		for(int i=1;i<=a;i++)
		{
			int b,c,d;
			scanf("%d%d%d",&b,&c,&d);
			if(c>d) V1.push_back({b,c-d}), ans += c;
			else V2.push_back({a-b,d-c}), ans += d;
		}
		
		std::sort(V1.begin(),V1.end(),cmp1);
		int size1 = 0;
		for(int i=0;i<V1.size();i++) if(V1[i].x0>=size1+1) size1++;
		
		for(int i=1;i<=size1;i++) S1.insert(i);
		std::sort(V1.begin(),V1.end(),cmp2);
		for(int i=0;i<V1.size();i++)
		{
			std::set<int> ::iterator it = S1.upper_bound(V1[i].x0);
			if(it==S1.begin())
			{
				ans -= V1[i].y0;
				continue;
			}
			it--;
			S1.erase(it);
		}
		
		std::sort(V2.begin(),V2.end(),cmp1);
		int size2 = 0;
		for(int i=0;i<V2.size();i++) if(V2[i].x0>=size2+1) size2++;
		
		for(int i=1;i<=size2;i++) S2.insert(i);
		std::sort(V2.begin(),V2.end(),cmp2);
		for(int i=0;i<V2.size();i++)
		{
			std::set<int> ::iterator it = S2.upper_bound(V2[i].x0);
			if(it==S2.begin())
			{
				ans -= V2[i].y0;
				continue;
			}
			it--;
			S2.erase(it);
		}
		
		printf("%lld\n",ans);
	}
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    ll ans = 0;

    for(int i=0;i<n;i++){
        ans+=a[i]-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
A, B, C, D = map(int, input().split())
# 対象となる数の個数
num = B - A + 1
# Cで割り切れる数の個数
C_div = B // C - (A - 1) // C
# Dで割り切れる数の個数
D_div = B // D - (A - 1) // D
# CでもDでも割り切れる数の個数
CandD =  (C * D) // math.gcd(C, D)
CandD_div = B // CandD - (A - 1) // CandD
# CもしくはDで割り切れる数の個数
CorD_div = C_div + D_div - CandD_div
res = num - CorD_div
print(res)

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

int main(){
    vector<int> d(4);
    for(int i=0;i<3;i++){
        int a,b; cin>>a>>b;
        a--,b--;
        d[a]++;
        d[b]++;
    }
    int c=count(d.begin(),d.end(),1);
    cout<<(c>2 ? "NO" : "YES")<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	if (n > k)
		cout << k * x + (n - k) * y << endl;
	else
		cout << n * x << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
# import sys
# sys.setrecursionlimit(10**4)
# import time

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


MOD = 998244353

N = d_in()
total = 3 ** N - (2**N - 2) * 3 - 3

a_list = []
for _ in range(N):
    a_list.append(d_in())
sum_a = sum(a_list)

# 1要素目: i番目の整数までを考慮
# 2要素目: [both>0, 緑>0&青==0, 緑==0&青>0, both==0]
# 3要素目: 最大の色(赤とする)の和
dp = np.zeros((N+1, 3, 1 + (sum_a+1)//2), dtype=int)
dp[0, 2, 0] = 1

for i in range(1, N+1):
    # 赤に入れる
    a = a_list[i-1]
    dp[i, :, a:] += dp[i-1, :, :-a]
    dp[i, :, -1] += dp[i-1, :, -a:].sum(axis=1)

    # 緑or青に入れる
    dp[i, 0, :] += (dp[i-1, 0, :] + dp[i-1, 1, :]) * 2
    dp[i, 1, :] += dp[i-1, 1, :]
    dp[i, 1, :] += dp[i-1, 2, :]

    if i % 10 == 0:
        dp[i, :, :] %= MOD

print((total - dp[-1, 0, -1] * 3) % MOD)


Measured memory_bytes: 328488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    ll ans=0;
    string s;cin >> s;
    ll n=s.size();
    rep(i,n){
        ll cnt=0;
        ll x=i;
        while((s[x]=='A'||s[x]=='T'||s[x]=='C'||s[x]=='G')&&x<n)x++;
        ans=max(ans,x-i);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;
 
void main() {
	auto data = readln.split.to!(long[]), N = data[0], M = data[1];
	auto p = readln.split.to!(long[]).map!(x=>x-1);
	
	long[] list = N.iota().array;
	//long[] size = repeat(1L, N).array;
	ulong root(ulong num) {
		auto parent = list[num];
		return parent == num ? num : ( list[num] = root(list[num]) ) ;
	}
	
	void unite(ulong num1, ulong num2) {
		auto root1 = root(num1), root2 = root(num2);
		if (root1 != root2) {
			//auto result = size[root1] * size[root2];
			list[root1] = root2;
			//size[root2] += size[root1];
			
		}
	}
	
	bool same(ulong num1, ulong num2) { return root(num1) == root(num2); }
	
	foreach (i; 0 .. M) {
		data = readln.split.to!(long[]),
		unite(data[0]-1, data[1]-1);
	}
	
	long ans = 0;
	N.iota.each!(i => same(i, p[i])? ans++ : 0);
	writeln(ans);
}

Measured memory_bytes: 5180
#include<iostream>
using namespace std;
int main(){
  while(1){
    int m,n1,n2,a[200],max=0,maxn;
    cin>>m>>n1>>n2;
    if(m+n1+n2==0)break;
    for(int i=0;i<m;i++)cin>>a[i];
    for(int i=n1;i<=n2;i++){
      int b=a[i-1]-a[i];
      if(max<=b)max=b,maxn=i;
    }
    cout<<maxn<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
"use strict";
const main = arg => {

    var lines = arg.split('\n');

    var firstLine = lines.shift().split(' ').map(function(n){return +n;});


    var H1 = firstLine[0] * 60 ;
    var first = H1 + firstLine[1];
    var H2 = firstLine[2] * 60;
    var Second = H2 + firstLine[3];
    var K  = firstLine[4];

    if(first < Second){
        console.log(Second - first - K);
    }else{
        var today = 3600 - first;
        console.log(Second + today - K);
    }

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()
#define foreach(it,c) for(typeof(c.begin()) it=c.begin();it!=c.end();++it)

const int MAXN = 100, MAXW = 50;

int main()
{
    int n, w;
    while(cin >> n >> w && n)
    {
        int v,  h[MAXN] = {};
        REP(n)
        {
            cin >> v; 
            h[ v / w] ++;
        }
        int rs = 0, maxh = 0;
        REP(MAXN)
        {
            //cout << h[i] << " " ;
            if(h[i] > 0) rs = i;
            maxh = max(maxh, h[i]);
        }
        //cout << rs << " " << maxh << endl;
        double ans = 0.0;
        REP(rs  )
        {
            ans += (double)(rs  - i) / (double)(rs ) * h[i] / maxh ;
        }
        ans += 0.01;
        printf("%.6f\n", ans);
    }

    return 0;
}

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

int main() {
	int n;
	bool g[100][100];
	for (int i = 0; i < 100; i++)for (int j = 0; j < 100; j++)g[i][j] = false;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int u, k, v[100];
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v[j];
			g[u - 1][v[j] - 1] = true;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) cout << " ";
			cout << g[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3120
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n; cin >> n;
    int ans = 0;
    for(int a = 1; a <= n - 1; ++ a) {
        ans += (n % a == 0 ? (n / a) - 1 : (n / a));
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

int main(){
	int n;
	int i;
	cin >> n;
	vector<int> a(n+1);
	for(i=1; i <= n; i++){
		int tmp;
		cin >> tmp;
		a[i] = tmp;
	}
	if(n%2){
		for(i=n; i>0; i-=2){
			cout << a[i] << " ";
		}
		for(i=2; i<n; i+=2){
			cout << a[i] << " ";
		}
	} else {
		for(i=n; i>1; i-=2){
			cout << a[i] << " ";
		}
		for(i=1; i<n; i+=2){
			cout << a[i] << " ";
		}
	}
	return 0;
}



Measured memory_bytes: 2944
fn main() {
    proconio::input! {
        n: usize,
        a: [usize; n],
    }
    let mut dp = vec![vec![0;n+1];n+1];
    let mut b: Vec<_> = (0..n).collect();
    b.sort_by_key(|k| a[*k]);
    for (m,k) in b.into_iter().rev().enumerate() {
        let f = |i,j| a[k]*if i>j {i-j} else {j-i};
        for i in 0..m+2 {
            let j = n+i-m-1;
            let x = if i>0 {dp[i-1][j]+f(i-1,k)} else {0};
            let y = if j<n {dp[i][j+1]+f(j,k)} else {0};
            dp[i][j]=std::cmp::max(x,y);
        }
    }
    println!("{}",(0..=n).map(|i| dp[i][i]).max().unwrap());
}

Measured memory_bytes: 33512
import itertools

N = int(input())
M = 10
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

ans = -10 ** 10
for s in itertools.product([0, 1], repeat=M):
    if max(s) == 0:
        continue
    score = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if s[j] and F[i][j]:
                cnt += 1
        score += P[i][cnt]
    ans = max(ans, score)
print(ans)


Measured memory_bytes: 9236
#include<stdio.h>
int main(void)
{
	int n,m,a[1000],b[1000],i,j,sum,cnt,box;
	scanf("%d %d",&n,&m);
	cnt=0;
	for(i=0;i<m;i++){
		scanf("%d %d",&a[i],&b[i]);
		if(a[i]>=n)	cnt++;
	}
	if(cnt>=m-1)	printf("0\n");
	else{
		sum=0;
		for(i=0;i<m-1;i++){
			for(j=i+1;j<m;j++){
				if(a[i]>a[j]){
					box=a[i];
					a[i]=a[j];
					a[j]=box;
				}
			}
		}
		for(i=1;i<m;i++){
			if(a[i]<n)	sum+=n-a[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}



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

int main(){
  int N, C, K;
  cin >> N >> C >> K;

  vector<int> T(N);
  for(int i = 0; i < N; i++){
    cin >> T[i];
  }
  sort(T.begin(), T.end());

  int now_bus_time = -1, now_bus_mem = 0, ans = 0;
  for(int i = 0; i < N; i++){
    if(now_bus_time < T[i] || now_bus_mem >= C){
      // cout << i << endl;
      now_bus_time = T[i] + K;
      now_bus_mem = 1;
      ans++;
    }else{
      now_bus_mem++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s, t;
    cin>>s>>t;
    vector<vector<ll>> v(26);
    for (int i=0; i<s.size(); i++){
        v[s[i]-'a'].push_back(i);
    }
    ll ans = 0, idx = -1, cnt = 0;
    ll i = 0;
    ll flag = 0;
    while(i<t.size()){
        if (v[t[i]-'a'].size() == 0){ans = -1; break;}
        auto it = upper_bound(v[t[i]-'a'].begin(), v[t[i]-'a'].end(), idx);
        if (it == v[t[i]-'a'].end()){
            idx = -1;
            cnt++;
            continue;
        }
        idx = *it;
        i++;
        ans = cnt*s.size() + *it + 1;
        // cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

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

int Section[550][550];

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;

    for (int i = 0; i < M; ++i) {
        int L, R;
        cin >> L >> R;
        Section[L][R]++;
    }

    for (int i = 0; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            Section[i][j] += Section[i][j - 1];
        }
    }
    for (int j = 0; j <= N; ++j) {
        for (int i = 1; i <= N; ++i) {
            Section[i][j] += Section[i - 1][j];
        }
    }
    for (int i = 0; i < Q; ++i) {
        int p, q;
        cin >> p >> q;
        cout << Section[q][q] - Section[p - 1][q] - Section[q][p - 1] + Section[p - 1][p - 1] << endl;
    }
    return 0;
}

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

using namespace std;

constexpr int mod = 1e9+7;
long long comb[2010][2010];

void init() {
    memset(comb, 0, sizeof(comb));
    comb[0][0] = 1;
    for(int i=1;i<=2000;i++) {
        comb[i][0] = 1;
        for(int j=1;j<=2000;j++) {
            comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%mod;
        }
    }
}

int main() {
    init();
    int N,K; cin >> N >> K;
    for(int i=1;i<=K;i++) {
        cout << (comb[N-K+1][i]%mod) * (comb[K-1][i-1]%mod) % mod << endl;
    }
    return 0;
}


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef unsigned long long int lli;
typedef pair<int, string> pi;


int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto &x: v){
        cin >> x;
        x--;
    }
    int cnt = 0;
    for(int i=0; i<n; i++){
        if(v[i] != i) cnt++;
    }
    if(cnt > 2){
        printf("NO\n");
    }
    else{
        printf("YES\n");
    }


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int X;
	cin >> X;
	int A = 1;
	int cnt = 0;
	for(int i = 1;i < 1000010;i++) {
		cnt += A;
		if(cnt >= X) {
			cout << i << endl;
			break;
		}
		A++;
	}
}

Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;
int n,p[1000],a,b,aa,bb,cc;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);

#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
cin >> n >> a >> b;
for(int i=1;i<=n;i++){
       cin >> p[i];
       if(p[i]<=a)aa++;
       if(p[i]>a&&p[i]<=b)bb++;
       if(p[i]>b)cc++;
}
int ans = min(aa,bb);
ans = min(ans,cc);
cout << ans << endl;




return 0;}
///....


Measured memory_bytes: 256
import math

# Inputs
a, b, c = list(map(int, input().split()))

# Calculation
h = b * math.sin(math.radians(c))
S = b * math.sin(math.radians(c)) * a / 2.0
d = math.sqrt((a - b*math.cos(math.radians(c)))**2 + h**2)
L = a + b + d

# Output
print('{:.15f}'.format(S))
print('{:.15f}'.format(L))
print('{:.15f}'.format(h))



Measured memory_bytes: 5712
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
       
  		int[] v=new int[n];
		for(int c=0;c<n;c++){
    		v[c]=sc.nextInt();
    	}
  	Arrays.sort(v);
  	double ans=(double)v[0];
    
 	for(int d=1;d<n;d++){
      ans=(ans+v[d])/2;
    
    }

    	System.out.println(ans);
    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;






int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    int x, y;
    int count = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        if (x == y) {
            count++;
        } else {
            count = 0;
        }
        if (count == 3) {
            flag = true;
            break;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x=sc.nextInt();
		int y=sc.nextInt();
		if(y%2==0&&x*2<=y&&y<=x*4){System.out.println("Yes");}
		else{System.out.println("No");}
}
}

Measured memory_bytes: 35716
W, H, N = map(int, input().split())

L1 = []
L2 = []
L3 = []
L4 = []
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        L1.append(x)
    if a == 2:
        L2.append(x)      
    if a == 3:
        L3.append(y)
    if a == 4:
        L4.append(y)
# print(L1, L2, L3, L4)

if L1 != []:
    x_min = max(L1)
else:
    x_min = 0
    
if L2 != []:
    x_max = min(L2)
else:
    x_max = W
    
if L3 != []:
    y_min = max(L3)
else:
    y_min = 0
    
if L4 != []:
    y_max = min(L4)
else:
    y_max = H
# print(x_min, x_max, y_min, y_max)

x_len = max(0, x_max-x_min)
y_len = max(0, y_max-y_min)
print(x_len * y_len)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
    int N, K; cin >> N >> K;
    vector<int> L(N, 0);
    for (int i = 0; i < N; ++i) cin >> L[i];
    sort(L.begin(), L.end(), greater<int>());
    int sum = 0;
    for (int i = 0; i < K; ++i) sum += L[i];
    printf("%d\n", sum);
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int N;
	vector<int> arr;
	cin>>N;
	arr.resize(N);
	REP(i,N)cin>>arr[i];
	
	int count = 0;

	for(int i = 0; i < N; i++){
		
		if(arr[i] == (i+1)){
			int tmp = arr[i];
			arr[i] = arr[i+1];
			arr[i+1] = tmp;
			count++;
		}
	}
	
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 640
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math
s = input().split()
p = [int(w) for w in s] #これで勝手にNまで拾ってくれます
t = input().split()
q = [int(w) for w in t] #これで勝手にNまで拾ってくれます

ans = p[0] - sum(q)
if(ans < 0):
    ans = -1
print(ans)

Measured memory_bytes: 10876
import collections

#Input
n = int(input())
l_a = list(map(int, input().split()))

#Process
d_c = collections.Counter(l_a)
l_c = list(d_c.values())

#N個から選ぶ方法
o = 0
for i in range(len(l_c)):
    if(l_c[i] != 1):
        o += int((l_c[i] - 1) * l_c[i] / 2)

#Output
for i in range(n):
    print(o - d_c[l_a[i]] + 1)

Measured memory_bytes: 26772
import sys
sys.setrecursionlimit(10**6)


def DFS(num,pre):
    global point
    if color[num]=="white":
        A[num]=C.pop()
        point +=min(A[num],pre)
        color[num]="black"
        for i in tree[num]:
            DFS(i,A[num])


n=int(input())
AB=[list(map(int,input().split())) for _ in range(n-1)]
C=sorted(list(map(int,input().split())))

color=["white" for _ in range(n+1)]
tree=[[] for _ in range(n+1)]
for a,b in AB:
    tree[a].append(b)
    tree[b].append(a)

A=[0 for _ in range(n+1)]
point=0
DFS(1,0)

print(point)
print(*A[1:])

Measured memory_bytes: 85208
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>

using namespace std;
 

int main(){
  
  	int input;
  	int cnt =0;
  	while(cin >> input){
    	cnt++;
      	if(input==0){
        	cout << cnt;
          	break;
        }
    }

  
  	

  return 0;
  
}

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

#define ll long long
#define print(x) cout << x << endl
#define prints(x) cout << x << " "
#define printline cout << endl

bool comp(const pair<ll, ll> a, const pair<ll, ll> b)
{
    return a.second > b.second;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    ll h, w, m;
    cin >> h >> w >> m;
    set<pair<ll, ll>> s;
    vector<ll> H(3e5, 0);
    vector<ll> W(3e5, 0);
    for (ll i = 0; i < m; i++)
    {
        ll r, c;
        cin >> r >> c;
        r--;
        c--;
        H[r]++;
        W[c]++;
        s.insert({r, c});
    }

    ll ans = 0;
    vector<pair<ll, ll>> hp;
    vector<pair<ll, ll>> wp;
    for (ll i = 0; i < 3e5; i++)
    {
        if (H[i])
            hp.push_back({i, H[i]});
        if (W[i])
            wp.push_back({i, W[i]});
    }
    sort(hp.begin(), hp.end(), comp);
    sort(wp.begin(), wp.end(), comp);
    // for (ll i = 0; i < hp.size(); i++)
    // {
    //     prints(hp[i].second);
    // }printline;
    // for (ll i = 0; i < wp.size(); i++)
    // {
    //     prints(wp[i].second);
    // }printline;
    ll mh = hp[0].second;
    ll mw = wp[0].second;
    ans = mh + mw - 1;
    for (ll i = 0; i < (ll)hp.size(); i++)
    {
        if (hp[i].second != mh)
            break;
      	int flag = 0;
        for (ll j = 0; j < (ll)wp.size(); j++)
        {
            if (wp[j].second != mw)
                break;
            ll temp = hp[i].second + wp[j].second;
            if (s.find({hp[i].first, wp[j].first}) != s.end())
                temp--;
          	else{
              ans++;
              flag=1;
              break;
            }
            ans = max(ans, temp);
        }
      if(flag)break;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 39372