akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;

    vector<map<ll,ll>> l(n);
    vector<map<ll,ll>> r(n);
    l[1][s[0] - '0'] = 1;
    FOR(i,2,n-1){
        l[i] = l[i-1];
        l[i][s[i-1] - '0'] = 1;
    }
    r[n-2][s[n-1] - '0'] = 1;
    FORr(i,1,n-3){
        r[i] = r[i+1];
        r[i][s[i+1] - '0'] = 1;
    }
    /*
    FOR(i,1,n-1){
        cout<<"{";
        FORm(j,l[i]){
            cout<<j->first<<",";
        }
        cout<<"}"<<endl;
    }
    FOR(i,1,n-1){
        cout<<"{";
        FORm(j,r[i]){
            cout<<j->first<<",";
        }
        cout<<"}"<<endl;
    }
    */
    
    map<ll, ll> ans;
    FOR(i,1,n-1){
        FORm(j,l[i]){
            FORm(k,r[i]){
                ll t;
                t = 100*j->first + (s[i] - '0')*10 + k->first;
                ans[t] = 1;
            }
        }
    }

    cout<<ans.size()<<endl;
}

Measured memory_bytes: 40704
N = int(input())
A = list(map(int,input().split()))
amari = 0
ans = 0
while True:
    for i in A:
        amari += i%2
    if amari != 0:
        break
    elif amari == 0:
        for j in range(len(A)):
            A[j] = A[j]/2
        ans += 1
print(ans)   

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n), b(n), c(n - 1);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];
  ll last = -1;
  ll ans = 0;
  rep(i, n) {
    ans += b[a[i] - 1];
    if(last + 1 == a[i]) ans += c[last - 1];
    last = a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 998244353;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}
const double PI=3.14159265358979323846;
int dp[100][100];
int tmp[100][100];
signed main(){
    int n;
    cin >> n;
    int w[n];
    rep(i, n) {
        cin >> w[i];
    }
    int a = 0;
    int b = 0;
    int ans = MX;
    rep(i,n) {
        a = 0;
        b = 0;
        rep(j, n) {
            if(j<=i) a+=w[j];
            else b+=w[j];
        }
        ans = min(abs(a-b), ans);
    }



    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 4992
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n,m;
    cin>>n>>m;
    int tsize=pow(2,n);
    int takara[m+1][tsize];


    rep(i,tsize){
        rep(j,m+1) {
            takara[j][i] = MOD;
        }
    }

    rep(i,m+1) {
        takara[i][0] = 0;
    }

    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        int s=0;
        rep(j,b){
            int k;
            cin>>k;
            s+=1<<(k-1);
        }
        //cout<<s<<endl;

        for(int j=0;j<tsize;j++){
          takara[i+1][j]=min(takara[i+1][j],takara[i][j]);

            if(takara[i][j]!=MOD){
                //int h=j+s;
                int h=0;
                for(int g=0;g<n;g++){
                    if((j>>g)&1==1||(s>>g)&1==1){
                        h+=1<<g;
                    }
                }

                if(h<tsize) {
                    //cout<<h;
                    takara[i+1][h] = min({takara[i][h], takara[i][j] + a,takara[i+1][h]});
                }

            }
        }
    }
    //cout<<tsize<<endl;

    if(takara[m][tsize-1]==MOD){
        cout<<-1<<endl;
        return 0;
    }

    cout<<takara[m][tsize-1]<<endl;


    return 0;
}


Measured memory_bytes: 16256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const long long maxn=1000000007;
const int ans=100010;
long long  a[100010];
long long dabiao(int n)
{
    a[1]=1;
    for(int i=2;i<=ans;i++)
        a[i]=(a[i-1]*i)%maxn;
    return a[n];
}
int main()
{
    int N;
   while(scanf("%d",&N)!=EOF)
   {
       long long num=0;
       num=dabiao(N);
       printf("%lld\n",num);
   }
   return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int total = 0;
    int ans = 0;

    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
    }

    for (int i = 0; i < M; i++)
    {
        total += A[i];
    }

    if (N < total)
    {
        ans = -1;
    }
    else
    {
        ans = N - total;
    }

    cout << ans << endl;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

const int mod = 1000000007;
const int MAXP = 31;
const int MAX = 300001;

ll fc[MAX];
ll fci[MAX];

ll modpow(ll a, ll b) {
    ll bp[MAXP];
    bp[0] = a;
    for (int i=1; i<MAXP; ++i) {
        bp[i] = bp[i-1] * bp[i-1] % mod;
    }
    ll ret = 1;
    for (int i=0; i<MAXP; ++i) {
        if (b & (1LL << i)) {
            ret *= bp[i];
            ret %= mod;
        }
    }
    return ret;
}

void init_fact() {
    fc[0] = fc[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fc[i] = (fc[i-1] * i) % mod;
    }
    fci[1] = 1;
    for (int i=2; i<MAX; ++i) {
        fci[i] = (fci[i-1] * modpow(i, mod-2)) % mod;
    }
}

ll C(ll n, ll k) {
    if (k == 0 || n == k) return 1;
    return ((fc[n] * fci[k] % mod) * fci[n-k]) % mod;
}

ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b + mod) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }

int main() {
    init_fact();
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    ll res = 0;

    // A[i]が最大値として選ばれる
    for (int i=K-1; i<N; ++i) {
        res = add(res, mul(A[i], C(i, K-1)));
    }

    // A[i]が最小値として選ばれる
    reverse(A.begin(), A.end());
    for (int i=K-1; i<N; ++i) {
        res = sub(res, mul(A[i], C(i, K-1)));
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    char a; cin >> a;

    if(a >= 'A' && a  < 'a') cout << "A" << endl;
    else cout << "a" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S; cin >> S;
	string X = S; 
	reverse(X.begin(), X.end()); 
	int N = S.size();  
	string T = S.substr(0, (N-1)/2); 
	string U = T; 
	reverse(U.begin(), U.end()); 
	if(S == X && T == U) cout << "Yes" << endl; 
	else cout << "No" << endl; 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, N, K);
    vector<int> h(N);
    read(h);

    i64 ans = LINF;
    rep(b, 0, 1 << N) {
        vector<int> x;
        rep(i, 0, N) if ((b >> i) & 1) x.push_back(i);

        dump(x);

        i64 sum = 0;
        auto cpy = h;
        rep(p, 1, x.size()) {
            const int i = x[p - 1];
            const int j = x[p];
            sum += max<i64>(0, (cpy[i] + 1) - cpy[j]);
            chmax(cpy[j], cpy[i] + 1);
        }

        int cnt = 0;
        rep(i, 0, N) {
            bool ok = true;
            rep(j, 0, i) ok &= cpy[i] > cpy[j];
            if (ok) ++cnt;
        }
        if (cnt >= K) chmin(ans, sum);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <utility>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> *adj;
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();

        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) { continue; }

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);
    adj = new vector<pair<int, int>>[n];
    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 2760
#include <iostream>
#include <map>

using namespace std;

int main() {
    int n;

    cin >> n;

    std::map<int, int> managers;

    for(int i=1;i<=n;i++) {
        managers[i] = 0;
    }

    int tmp;
    for(int i=0;i<n-1;i++) {
       cin >> tmp;
       managers[tmp] += 1;
    }

    for(int i=1;i<=n;i++) {
        cout << managers[i] << endl;
    }
}


Measured memory_bytes: 13012
r,c=gets.split(" ").map(&:to_i)
h = Array.new(r+1).map{Array.new(c+1,0)} 

for i in 1..r

a= gets.split.map(&:to_i)
    for j in 1..c
    h[i-1][j-1] = a[j-1]
    h[i-1][c] += a[j-1]
    h[r][j-1] += a[j-1]
    h[r][c] += a[j-1]
    end
end
for i in 0..r
    for j in 0..c
      print " " unless j == 0
      print h[i][j]
    end
    print "\n"
  end



Measured memory_bytes: 7056
from itertools import accumulate

MAX = 2 * 10 ** 5 + 5

N, M, *A = map(int, open(0).read().split())

B = [0] * MAX
for a in A:
    B[a] += 1

C = list(accumulate(reversed(B)))[::-1]

ng, ok = 1, MAX
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    if sum(C[max(0, m - a)] for a in A) >= M:
        ng = m
    else:
        ok = m

D = list(accumulate(reversed(list(i * b for i, b in enumerate(B)))))[::-1]
print(sum(D[max(0, ng - a)] - (ng - a) * C[max(0, ng - a)] for a in A) + ng * M)

Measured memory_bytes: 23880
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
#define int long long int

void solve() {
  int N, M;
  cin >> N >> M;

  vector<tuple<int, int, int>> v;
  for (int i = 0; i < M; i++) {
    int y, p;
    cin >> p >> y;
    v.emplace_back(y, p, i);
  }

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

  vector<tuple<int, int, int>> ans;
  map<int, int> m;
  for (auto &a : v) {
    int p = get<1>(a);
    int id = ++m[p];
    ans.emplace_back(get<2>(a), p, id);
  }

  sort(ans.begin(), ans.end());
  for (auto &a : ans) {
    printf("%06lld%06lld\n", get<1>(a), get<2>(a));
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 12656
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n, m = map(int, input().split())
    A = [input() for _ in range(n)]
    B = [input() for _ in range(m)]
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            correspond = True
            for p in range(m):
                for q in range(m):
                    if A[i + p][j + q] != B[p][q]:
                        correspond = False
                        break
            if correspond:
                print("Yes")
                return
    print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 71652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N),b(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(a.begin(),a.end());
  int count=0;
  for(int i=0;i<N;i++)if(a.at(i)!=b.at(i))count++;
  if(count<3)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long A[100010], B[100010], C[100010];		
long long p[100010] = { 0 };
int main()
{
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%lld", &B[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%lld", &C[i]);
	}
	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);
	int j = 0, l = 0;
	long long sum = 0;
	for (int i = 0; i < N; i++) {
		while (B[i] >= C[j]) {
			if (j == N) break;
			j++;
		}
		p[i] = N - j;
		sum += p[i];
	}
	long long an = 0;
	for (int i = 0; i < N; i++) {
		while (A[i] >= B[l]) {
			if (l == N) break;
			sum -= p[l];
			l++;
		}
		an += sum;
	}
	printf("%lld", an);
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>

using namespace std;

typedef	pair<int,int>	pii;

int main(){
	for(int n;scanf("%d",&n),n;){
		int w,h;	scanf("%d%d",&w,&h);
		pii psm[500];
		for(int i=0;i<n;i++)	scanf("%d%d",&psm[i].second,&psm[i].first);

		int s,t;	scanf("%d%d",&s,&t);
		int cmax=0;
		for(int i=0;i<h-t+1;i++)for(int j=0;j<w-s+1;j++){
			int cnt=0;
			for(int k=0;k<n;k++){
				int px=psm[k].second-1,py=psm[k].first-1;
				if(i<=py && py<i+t && j<=px && px<j+s)	cnt++;
			}
			cmax=max(cmax,cnt);
		}

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

	return 0;
}

Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
#define db double long
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < int(s.size()); i++) {
		if (s[i] != t[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3792
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a;
    cin>>a;
    int n[a];
    int x[a];
    for(int i=0;i<a;i++){
        int b=0;
        cin>>n[i];
        while(n[i]%2==0){
            n[i]=n[i]/2;
            b=b+1;
        }
        x[i]=b;
    }
    sort(x,x+a);
    cout<<x[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
m = 10**18

ans = 1

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit()

for i in range(0, n):
    ans *= a[i]
    if ans > m:
        print(-1)
        exit()


if ans > m:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21652
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll dp[26][200010];

int main(){
    string S,T;cin >> S >> T;
    S = S + S;
    ll N = S.size(),M = T.size();
    rep(i,26){
        dp[i][N] = INF;
    }
    rep(i,26){
        rrep(j,N){
            if(S[j] == 'a' + i){
                dp[i][j] = 1;
            }else{
                dp[i][j] = dp[i][j+1] + 1;
            }
        }
    }
    /*rep(i,26){
        cout << '(' << i << ')' << ' ';
        rep(j,N){
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }*/
    ll ans = 0,cnt = 0;
    while(1){
        rep(i,26){
            if(T[cnt] == 'a'+i){
                if(dp[i][(ans) % (N/2)] >= INF){
                    cout << -1 << endl;
                    return 0;
                }
                ans += dp[i][(ans) % (N/2)];
                cnt++;
                break;
            }
        }
        if(cnt == M){
            break;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 41344
package main

import(
    "bufio"
    "fmt"
    "os"
    "strings"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main(){
    nextLine()
    a := strings.Split(nextLine(), " ")
    var min_index = 10000
    var max_index = -1

    for _, val := range a {
        a_num, _ := strconv.Atoi(val)
        if a_num < min_index {
            min_index = a_num
        }
        if max_index < a_num {
            max_index = a_num
        }
    }

    result := max_index - min_index

    fmt.Println(result)
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

bool ok(string& s) {
	int len = s.size();
	REP(i, len / 2 + 1) {
		if (s[i] != s[len - 1 - i]) {
			return false;
		}
	}
	return true;
}

int main() {
	cout << fixed << setprecision(10);
	string s;

	cin >> s;

	int n = s.size();
	int len = (n - 1) / 2;

	if (ok(s)) {
		string l = s.substr(0, len);
		string r = s.substr(n - len, len);
		string s2 = s.substr((n + 3) / 2 - 1);
		//cout << l << ":" << r << ":" << s2 << endl;

		if (ok(l) && ok(r) && ok(s2)) {
			cout << "Yes";

		}
		else {
			cout << "No";

		}
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
   
using namespace std;
   
int main(){
    int n,m;
    int a[1000];
    int b[1000];
    int c[1000];
    int e,o;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        c[i]=0;
    }
    for(int i=0;i<n;i++){
        int j=0;
        while(true){
            if(b[i]>=a[j]){
                c[j]+=1;
                break;
            }
            j++;
        }
    }
    e=c[0];
    o=0;
    for(int i=0;i<n;i++){
        if(e<c[i]){
            o=i;
            e=c[i];
        }
    }
    cout<<o+1<<endl;
    return 0;
} 

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

using namespace std;

const int NMAX = 300000;
long long fact[NMAX + 2];
const int MOD = 998244353;
long long ans;
long long n, a, b, k;

long long logpow(long long a, long long b) {
  long long ans = 1, d = a;
  while (b) {
    if (b & 1)
      ans = ans * d % MOD;
    b >>= 1;
    d = d * d % MOD;
  }
  return ans;
}


long long comb (long long n, long long k) {
  return fact[n] * logpow(fact[k], MOD - 2) % MOD * logpow(fact[n - k], MOD - 2) % MOD;
}

int main() {
  cin >> n >> a >> b >> k;
  fact[0] = 1;
  for (long long i = 1; i <= n; i++)
    fact[i] = fact[i - 1] * 1LL * i % MOD;
  for (long long i = 0; i <= n; i++) {
    if ((k - a * i) % b == 0 && k - a * i >= 0) {
      long long A = i, B = (k - a * i) / b;
      if (B <= n)
        ans += 1LL * comb(n, A) * comb(n, B) % MOD;
    }
  }
  cout << ans % MOD;
  return 0;
}


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

int main() {
  int A,B,ans=-1;
  cin>>A>>B;
  for(int i=1010; i>0; i--){
    if( (i*8/100==A) && (i*10/100==B) ){
      ans=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
x,y=map(int,input().split())
ans=0
for i in range(n-1):
    xi,yi=map(int,input().split())
    if xi==x:
        ans+=abs(y-yi)
        y=yi
    elif yi==y:
        ans+=abs(x-xi)
        x=xi
    elif (x-xi)*(y-yi)>0:
        ans+=max(abs(x-xi),abs(y-yi))
        x,y=xi,yi
    else:
        ans+=abs(x-xi)+abs(y-yi)
        x,y=xi,yi
print(ans)


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

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000 // array max range
#define FI first
#define SE second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int K;
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    cin >> K;
    R(i,K) cout << (i==K-1 ? "ACL\n" : "ACL");
    return 0;
}


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

typedef long long ll;
typedef long double ld;

const int M=1e5+5;
const ll mod=998244353;
ll ct[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int mx=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int d;
		cin>>d;
		if(i==1 && d)
		{
			cout<<"0\n";
			return 0;
		}
		if(i>1 && d==0)
		{
			cout<<"0\n";
			return 0;
		}
		ct[d]++;
		mx=max(mx,d);
	}
	ll res=1;
	for(ll i=1;i<=mx;i++)
	{
		if(ct[i]==0)
			res=0;
		for(int j=1;j<=ct[i];j++)
			res=(res*ct[i-1])%mod;
	}
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 1024
N,K=map(int,input().split())
M=[]
for i in range(N):
  M.append(list(map(int,input().split())))
M.sort()
#print(M)

S=[M[0][1]]
for i in range(1,N):
  S.append(S[i-1]+M[i][1])
#print(S)

ans=0
for i,s in enumerate(S):
  if s>=K:
    ans=M[i][0]
    break
    
print(ans)

Measured memory_bytes: 32532
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())
		if(c=='-')
			f=-1;
	for(;isdigit(c);c=getchar())
		x=x*10+c-'0';
	return x*f;
}
long long gcd(long long a,long long b){
	if(b==0) return a;
	return gcd(b,a%b);
} 
int main(){
	int N=read();
	double tmp=(4.0)/N;
	for(int i=1;i<=3500;i++){
		for(int j=1;j<=3500;j++){
			long long l1=gcd(i,j);
    		long long l2=gcd(l1,N);
    		long long l3=i*j/l1*N/l2;
    		long long b=l3;
    		long long a=(4*(l3/N))-(l3/i)-(l3/j);
    		if(!a||a<0) continue;
    		long long f=gcd(a,b);
    		b/=f; a/=f;
    		if(a!=1 && a) continue;
    		printf("%lld %lld %lld\n",i,j,b);
    		return 0;
		}
	} 
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (C >= A && C <= B)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		if (a + b >= 10)
			System.out.println("error");
		else
			System.out.println((a + b));
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}
}


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

typedef long long ll;

int r, g;

int main() {
	cin >> r >> g;
	cout << 2 * g - r  << endl;
	return 0;
}

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

using namespace std;

int main() {
	int n,h;
	cin>>n>>h;
	int maxa=0;
	int a[n];
	vector<int> b(n);
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if(maxa<a[i]) maxa=a[i];
	}
	int dm=0;
	int count=0;
	sort(b.begin(),b.end());
	while(b[n-1-count]>maxa){
		dm+=b[n-1-count];
		count++;
		if(dm>=h) break;
		if(count==n) break;
	}
//	cout<<dm<<endl<<count<<endl;
	if(dm<h){
		count+=(h-dm-1)/maxa+1;
	}
	cout<<count<<endl;

	return 0;
}


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

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

typedef unsigned long long ull;
typedef long long ll;

const int INF = 1001001001;

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

    vector<int> p(n); int maxi = 0;
    rep(i, n) { 
        cin >> p[i];
        maxi = max(maxi, p[i]);
    }

    int sum = 0;
    rep (i, n) {
        sum += (maxi == p[i]) ? p[i]/2 : p[i];
    }
    cout << ((sum == p[0]/2 * n) ? sum * 2 - p[0]/2 : sum) << endl;
}

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

Measured memory_bytes: 128
count = int(input())

ac = 0
wa = 0
tle = 0
re = 0
for i in range(count):
  ans = input()
  if ans == "AC":
    ac = ac + 1
  elif ans == "WA":
    wa = wa + 1
  elif ans == "TLE":
    tle = tle + 1
  else:
    re = 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: 9160
using System;
namespace DynammicProgramming {
  class Vacation {
    public static void Main(String[] args) {
      int N = Int32.Parse(Console.ReadLine());
      int[,] dp = new int[N,3];
      for(int i = 0; i < N; i++) {
        String[] numbers = Console.ReadLine().Split(' ');
        dp[i, 0] = Int32.Parse(numbers[0]);
        dp[i, 1] = Int32.Parse(numbers[1]);
        dp[i, 2] = Int32.Parse(numbers[2]);
      }
      for(int i = 1; i < N; i++) {
        dp[i, 0] += Math.Max(dp[i-1, 1], dp[i-1, 2]);
        dp[i, 1] += Math.Max(dp[i-1, 0], dp[i-1, 2]);
        dp[i, 2] += Math.Max(dp[i-1, 0], dp[i-1, 1]);
      }
      int answer = Math.Max(dp[N-1, 0], Math.Max(dp[N-1, 1], dp[N-1, 2]));
      Console.WriteLine(answer);
    }
  }
}

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

using namespace std;
using ll = long long;

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

  const ll mod = 1e9 + 7;

  int n;
  cin >> n;
  vector<int> cnt(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a]++;
  }

  auto err = [] {
    cout << 0 << endl;
    exit(0);
  };

  if (n % 2 == 0) {
    for (int i = 1; i < n; i += 2) {
      if (cnt[i] != 2)
        err();
    }
  } else {
    if (cnt[0] != 1)
      err();
    for (int i = 2; i < n - 1; i += 2) {
      if (cnt[i] != 2)
        err();
    }
  }

  ll ans = 1;
  for (int i = 0; i < n / 2; i++) {
    ans *= 2;
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3888
#include<iostream>

using namespace std;

int main (){
  int N,A,B,i,answer,keta,tmp;
  cin >> N >> A >> B;
  
  answer = 0;
  
  for (i=1;i<=N;i++){
    keta = i;
    tmp=0;
    while(keta){
      tmp += keta%10;
      keta /= 10;
    }
    if((A <= tmp) && (tmp <= B)){
      answer += i;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll n,k;
    while(cin>>n>>k)
    {
        if(n>=k)
        {
            cout<<min(n%k,abs(n%k-k))<<endl;
        }
        else
        {
            cout<<min(n,abs(n-k))<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
a = int(input())
ar = []
l = 51
t = ''
for i in range(a):
    j = input()
    ar.append(j)
    if len(j) < l:
        l = len(j)
        t = j
T = list(t)
br = []
for r in set(T):
    count = 0
    cr = []
    for l in ar:
        if r not in l:
            break
        else:
            cr.append(l.count(r))
            count += 1
    if count == len(ar):
        for i in range(min(cr)):
            br.append(r)
br.sort()
print("".join(br))

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N ;
  vl a(N);
  rep(i,N){
    cin >> a[i] ;
    a[i]-=(i+1);
  }
  sort(ALL(a));
  ll b = a[N/2];
  ll nx = (N==1 ? a[N/2]: a[N/2+1]);
  ll ans = LINF;
  rep(k,2){
    ll temp = 0LL;
    rep(i,N) temp += abs(a[i]-b);
    chmin(ans,temp);
    b = nx;
  }
  cout << ans << endl;
  return 0; 
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> x(N);
    rep(i, N) cin >> x[i];
    int zero_i = lower_bound(all(x), 0) - x.begin();

    ll ans = 1e14;
    rep(l, N - K + 1) {
        ll tmp_ans = 0;
        int r      = l + K - 1;
        tmp_ans    = min(abs(x[l]) + abs(x[l] - x[r]),
                      abs(x[r]) + abs(x[r] - x[l]));
        ans        = min(ans, tmp_ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn = 30;
char s[maxn];
bool vis[maxn];
int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	if(n < 26)
	{
		for(int i = 1; i <= n; ++i) vis[s[i] - 'a'] = 1;
		for(int i = 0; i < 26; ++i)
			if(!vis[i])
			{
				s[n + 1] = 'a' + i;
				puts(s + 1);
				return 0;
			}
	}
	else
	{
		bool flag = 0;
		for(int i = n - 1; i; --i)
			if(s[i] < s[i + 1])
			{
				flag = 1;
				for(int j = n; j > i; --j)
					if(s[j] > s[i])
					{
						swap(s[j], s[i]);
						s[i + 1] = 0;
						break;
					}
				break;
			}
		if(!flag) puts("-1");
		else puts(s + 1);
		return 0;
	}
	return 0;
}
		
		
				
	
	 

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

using namespace std;
using ll = long long;

int main(){
  ll n, k;
  vector <ll> h;
  ll tmp;
  cin >> n >> k;
  cin.ignore();
  for(ll i = 0; i < n; i++){
    cin >> tmp;
    h.push_back(tmp);
  }
  sort(h.begin(), h.end());
  ll sum = 0;
  for(ll i = 0; i < n - k; i++){
    sum += h[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
int A[200000], N, a, b, c;
int main () {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        if (a < A[i]) c = a, a = A[i], b = 1;
        else if (a == A[i]) b++;
        else if (c < A[i]) c = A[i];
    }
    for (int i = 0; i < N; i++) {
        if (A[i] == a) printf("%d\n", (b > 1) ? a : c);
        else printf("%d\n", a);
    }
}

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

 string S;
  cin>>S;
  
  for(int i =0; i<K; i++){
  if(S.size()>K)
   cout<<S.at(i);
  } 
  if(S.size()>K)
  cout<<"...";
  
  else if(S.size()<=K)
  cout<<S;
  
 
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<ll> num(100200,0);

    rep(i,n){
        int a, b; cin >> a >> b; b++;

        for(int i = a; i < b; i++){
            num[i]++;
        }
    }

    ll ans = 0;
    for(int i = 1; i < 100100; i++){
        int k = i-1;
        if(k <= num[i]) ans = k;
    }

    //imosの方が良かったかも。
    cout << ans << endl;

}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include<string>
using namespace std;
typedef long long ll;
typedef vector < int > vi;
typedef pair<int,int> pi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(i,a,b) for(ll i=a;i<b;i++)
//add below to remove endl in input just before getline()
//cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');
int twos(int a,int c){
	for(int i=2;i<=a;i*=2){
		if(a%i==0)c++;
		}
	return c;}
int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	//freopen("input.txt", "r", stdin);
	int n,c=0;
	cin>>n;int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		c=twos(a[i],c);
		}
	cout<<c;
	

	
return 0;}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    double A, B, H, M, X;
    cin >> A >> B >> H >> M;
    int time = 60*H + M; //全部で何分か

    double hari;
    hari = abs(time*3.14159265359/360 - M*3.14159265359/30);

    X = A*A + B*B - 2*A*B*cos(hari);

    cout << setprecision(15) << sqrt(X) << endl;

}

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

int main() {
  int j,n,m[11],i,f=0;
  cin>>n;
  for(i=0;i<11;i++){
    m[i]=n;
    for(j=0;j<i;j++)
      m[i]=m[i]/10;
    f+=m[i]%10;
    }
  if(n%f==0)
    cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int n, v[20], c[20], i, x=0;

   scanf("%d",&n);
   for(i=0;i<n;i++)
      scanf("%d",&v[i]);
   for(i=0;i<n;i++)
      scanf("%d",&c[i]);

   for(i=0;i<n;i++)
      if(v[i]>c[i])
         x+=v[i]-c[i];

   printf("%d\n",x);
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  ll sum = accumulate(v.begin(), v.end(), 0ll);
  bool ans = true;
  for (int i = 0; i < n; i++) {
    if (v[i] * 2 >= sum)
      ans = false;
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const x = s[0];
  const y = s[1];
  const z = s[2];

  const ans = Math.floor((x - z) / (y + z));

  console.log(ans);
}

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


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  int id=0;
  int mod=1e9+7;
  ll res=1;
  int pre=0;
  if(s[0]==t[0]){res=3;id++;pre=1;}
  else {res=6;id+=2;pre=0;}
  while(1)
  {
    if(id>=n)break;
    if(s[id]==t[id])
    {
      if(pre)res=res*2%mod;
      id++;
      pre=1;
    }
    else
    {
      if(pre)res=res*2%mod;
      else res=res*3%mod;
      id+=2;
      pre=0;
    }
  }
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  while (cin >> N) {
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
      cin >> x[i];
    }
    int pre = 1, size = 1;
    ll res = 1;
    for (int i = 1; i < N; i++) {
      int cur = pre + 2;
      if (cur <= x[i]) {
        pre = cur;
        ++size;
        continue;
      }
      res = res * (size + 1) % MOD;
      cur = x[i];
    }
    for (int i = 1; i <= size; i++) {
      res = res * i % MOD;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
 
 
int main(){
  int n, k, h[100001], ans = 2* 1000000000;

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

  sort(h, h+n, greater<int>());

  for(int i=0; i<n-k+1; ++i){
    ans = min(ans, h[i] - h[i+k-1]);
  }

  cout << ans << endl;
}

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

string replace(string s, string p){
  for(size_t i = 0; i < s.length(); ++i){
    if(s[i] >= 'a' && s[i] < 'e'){
      s[i] = p[s[i]-'a'];
    }
  }
  return s;
}

int Hash(int &i, string &s){
  if(s[i] == '['){
    ++i;
    int ret = Hash(i,s);
    ++i;
    return ret;
  }
  if(s[i] == '+'){
    ++i;
    int a = Hash(i,s), b = Hash(i,s);
    return (a|b);
  }
  if(s[i] == '*'){
    ++i;
    int a = Hash(i,s), b = Hash(i,s);
    return (a&b);
  }
  if(s[i] == '^'){
    ++i;
    int a = Hash(i,s), b = Hash(i,s);
    return (a^b);
  }
  if(s[i] >= '0' && s[i] <= '9'){
    ++i;
    return (s[i-1] - '0');
  }
  return 0;
}

void solve(string s, string p){
  string s_ = replace(s,p);
  //cout << s_ << endl;
  int i = 0, t = Hash(i,s_), count = 0;
  for(int a = 0; a < 10; ++a){
    for(int b = 0; b < 10; ++b){
      for(int c = 0; c < 10; ++c){
        for(int d = 0; d < 10; ++d){
          string p_ = to_string(a) + to_string(b) + to_string(c) + to_string(d);
          i = 0;
          s_ = replace(s,p_);
          if(Hash(i,s_) == t) ++count;
        }
      }
    }
  }
  cout << t << " " << count << endl;
}

int main(){
  string s;
  while(cin >> s, s != "."){
    string p;
    cin >> p;
    solve(s,p);
  }
  return 0;
}



Measured memory_bytes: 3228
#include <stdio.h>
#include <math.h>

int isprime(long L){
  long i=3;
  long Ls = (long)sqrt(L);
  if (!(L%2)) return 0;
  while (i<=Ls) {
    if(!(L%i))return 0;
    i+=2;
  }
  return 1;
}

int main(void) {
  int N,n,t=0;
  long L;
  scanf("%d\n",&N);
  for(n=0;n<N;n++) {
    scanf("%ld\n",&L);
    if (L==2)      t++;
    else if (L> 2) t+=isprime(L);
  }
  printf("%d\n",t);
  return 0;
}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

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

  double ans = 0;

  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) { cout << s << endl; }
  else { cout << "red\n"; }

  return 0;
}


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

using namespace std;

 
string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  set<int> even, odd;
  map<int, int> m;
  int m_size = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]];
  }         
  for (auto& e : m) {
    e.second = m_size++;
  }
  for (int i = 0; i < n; i++) {
    a[i] = m[a[i]];
  }
  vector<int> where(n);
  for (int i = 0; i < n; i++) {
    where[a[i]] = i % 2;
  }
  int ans = 0;
  for (int i = 1; i < n; i += 2) {
    ans += where[i] ^ 1;  
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5760