akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

int abs(int x){
    if(x > 0) return x;
    else return -x;
}


int main(){
    int n;
    cin >> n;
    int p[n], q[n];
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    int perm[n];
    rep(i, n) perm[i] = i + 1;
    int cp = 0;
    do{
        bool flag = true;
        for (int i = 0; i < n; i++){
            if (perm[i] != p[i]){
                flag = false;
                break;
            }
        }
        if (flag){
            break;
        }
        cp++;
    }while(next_permutation(perm, perm + n));

    
    rep(i, n) perm[i] = i + 1;
    int cq = 0;
    do{
        bool flag = true;
        for (int i = 0; i < n; i++){
            if (perm[i] != q[i]){
                flag = false;
                break;
            }
        }
        if (flag){
            break;
        }
        cq++;
    }while(next_permutation(perm, perm + n));
    // cout << cp << " " << cq << endl;
    cout << abs(cq - cp) << endl;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
H = list(map(int, input().split()))

x = []
for i in range(N):
    x.append(0)

for i in range(M):
    A1, A2 = map(int, input().split())
    if H[A1-1] > H[A2-1]:
        x[A2-1] = 1
    elif H[A1-1] < H[A2-1]:
        x[A1-1] = 1
    else:
        x[A1-1] = 1
        x[A2-1] = 1

count = 0
for num in x:
    if num == 0:
        count += 1

print(count)

Measured memory_bytes: 20128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

	int n;
	cin >> n;
	string s;
	cin >> s;

	// 飛ばし飛ばしでもよい

	typedef map<char, ll> M; // map<key の型, valueの型>
	M mp;

	rep(i, n) {
		mp[s[i]]++;
	}

	ll ans = 0;

	sort(allof(s)); // ソートしても変わらないのでは
	char tmpC = 'a';
	M alphaCnt;

	for (char c = 'a'; c <= 'z'; c++) {
		ll tmpAns = mp[c];
		for (char tc = 'a'; tc < tmpC; tc++) {
			tmpAns += (alphaCnt[tc] * mp[tmpC]) % mod;
			tmpAns %= mod;
		}
		alphaCnt[c] = tmpAns;
		tmpC++;
	}

	for (char c = 'a'; c <= 'z'; c++) {
		ans += alphaCnt[c] % mod;
	}

	cout << ans % mod << endl;

	return 0;
}

Measured memory_bytes: 512
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let N,M,C = util.Scan3 int
let As = util.ScanVecH int
let Bs = util.ScanMatrix N int

let isOK arr =
  Array.map2 (*) As arr
  |> Array.sum
  |> fun x -> (x + C) > 0

Bs
|> List.filter isOK
|> List.length
|> printfn "%d"



Measured memory_bytes: 14172
#include<bits/stdc++.h>
#define int long long
#define sz(s) (int)(s).size() 
 
using namespace std;
const int hell = 1e9+7;

void solve(){
	int n , a = 0 ;
	cin >> n ;
	string s ;
	cin >> s;
	vector<int>arr(n);
	for(int i = 0 ; i < n ; i++ ){
		arr[i] = s[i]-'a';	
        }
        arr.resize(unique(arr.begin(),arr.end())-arr.begin());
        a = sz(arr);
        cout << a << endl;
}
 
int32_t main(){                                    
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    	cout.precision(10);
    	cout << fixed;
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt","w",stdout);
#endif
        int q=1;
        //cin>>q;
        while(q--){
            solve();
        }
               
#ifdef LOCAL
    cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
 
	return 0;
}	
 

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

using namespace std;

typedef long long	ll;
const int N = int(1e6);
ll a[N];
ll b[N];

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]);
	}

	ll tot = 0LL;

	for(int i = 0 ; i < n ; i++){
		if(a[i] >= b[i]){
			tot += b[i];
		}else{
			tot += a[i];
			b[i] -= a[i];

			if(a[i + 1] >= b[i]){
				tot += b[i];
				a[i + 1] -= b[i];
			}else{
				tot += a[i + 1];
				a[i + 1] = 0LL;
			}
		}
	}

	printf("%lld\n", tot);

	return 0;
}

Measured memory_bytes: 5120
N = int(input())

blocks = list(map(int, input().split()))

max_cnt = 0
cnt = 0
i = 1
height = blocks[0]

while i <= N-1:
    if height >= blocks[i]:
        cnt += 1
    else :
        cnt = 0
    if cnt >= max_cnt:
        max_cnt = cnt
    height = blocks[i]
    i += 1

print(max_cnt)

Measured memory_bytes: 15020
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Foxy
 */
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int n = Integer.parseInt(s.next());
    int out = 0;
    int runner = 0;
    boolean change = false;
    int score = 0;
    do{
        String event = s.next();
        if(change){
            score = 0;
            out = 0;
            runner = 0;
            change = false;
        }
        if(event.equals("HIT")){
            if(runner == 3){score++;}
            else {runner++;}
        }
        else if(event.equals("HOMERUN")){
            score += (1 + runner);
            runner = 0;
        }
        else if(event.equals("OUT")){
            out++;
            if(out == 3){
                change = true;
                System.out.println(score);
                n--;
            }
        }
    }while(n>0);
  }
}


Measured memory_bytes: 25860
#include <stdio.h>

int main(){
  int N,v,i,j,k,A[100];

  scanf("%d",&N);
  if(N<1 || N>100){
    return -1;
  }

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    if(A[i]<0 || A[i]>1000){
      return -1;
    }
  }

  for(i=0;i<N;i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k == N-1) break;
      printf(" ");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2064
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double long double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 1e5 + 10;
int a[MAXN],bit[2*MAXN];

void update(int idx,int val){
    for(;idx<2*MAXN;idx+=(idx&(-idx))) bit[idx] += val;
}

int query(int idx){
    int ret = 0;
    for(;idx>0;idx-=(idx&(-idx))) ret += bit[idx];
    return ret;
}

int prefix[MAXN];

void solve(){
    int n; cin>>n;
    FOR(i,1,n) cin>>a[i];

    int s = 1,e = 1e9;
    int ans = 1;

    while(s <= e){
        int mid = (s+e)>>1;
        ZERO(bit);
        
        int cnt = 0;
        update(MAXN,1);
        
        FOR(i,1,n){
            if(a[i] >= mid) prefix[i] = prefix[i-1] + 1;
            else prefix[i] = prefix[i-1] - 1;

            cnt += query(prefix[i] + MAXN);
            update(prefix[i]+MAXN,1);
        }

        if(cnt >= (n*(n+1)/2 +1)/2){
            ans = mid,s = mid+1;
        }else e = mid-1;
    }

    cout<<ans<<endl;
}

signed main(){

   FastRead;    
  
    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 999999999999999
#define MOD 1000000007

void func()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k<<"\n";
    }
    else if((k-a)<=b){
        cout<<a<<"\n";
    }
    else if((k-a-b)<=c){
        cout<<a-(k-a-b)<<"\n";
    }
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif

    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int H, N, A;

void solve() {
    cin >> H >> N;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> A;
		sum += A;
	}
    if (sum >= H) cout << "Yes";
    else cout << "No";
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int H,W,K;
    cin >> H >> W >> K;
    vector<string>S(H);
    for(int i = 0; i < H; i++) {
        cin >> S[i];
    }
    vector<vector<int>>ans(H,vector<int>(W));
    int cnt = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(S[i][j] == '#') {
                cnt++;
                ans[i][j] = cnt;
            }
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W-1; j++) {
            if(ans[i][j+1] == 0) {
                ans[i][j+1] = ans[i][j];
            }
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = W-1; j >= 1; j--) {
            if(ans[i][j-1] == 0) {
                ans[i][j-1] = ans[i][j];
            }
        }
    }
    for(int i = 0; i < H-1; i++) {
        for(int j = 0; j < W; j++) {
            if(ans[i+1][j] == 0) {
                ans[i+1][j] = ans[i][j];
            }
        }
    }
    for(int i = H-1; i >= 1; i--) {
        for(int j = 0; j < W; j++) {
            if(ans[i-1][j] == 0) {
                ans[i-1][j] = ans[i][j];
            }
        }
    }
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(j) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 4484
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    String[] S=scan.nextLine().split("");
    for(int i=0;i<S.length;i++){
      if(i%2==0){
        if(S[i].equals("R")||S[i].equals("U")||S[i].equals("D")){
          continue;
        }else{
          System.out.println("No");
          System.exit(0);
        }
      }else{
        if(S[i].equals("L")||S[i].equals("U")||S[i].equals("D")){
          continue;
        }else{
          System.out.println("No");
          System.exit(0);
        }
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAX_N  300005
#define P pair<int,int>

int fac[MAX_N];
int revfac[MAX_N];

int nCk(int n, int k){
    return fac[n] * revfac[k] % MOD * revfac[n - k] % MOD;
}

int pow(int a, int e){
    int ans = 1;
    while(e > 0){
        if(e & 1){
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        e = e >> 1;
    }
    return ans % MOD;
}

void set_fac(){
    fac[0] = 1;
    fac[1] = 1;
    revfac[0] = 1;
    for (int i = 1; i < MAX_N; ++i)
    {
        fac[i] = i * fac[i-1] % MOD;
        revfac[i] = pow(fac[i], MOD - 2) % MOD;
    }
}

signed main(){
	
	int n,a,b,k;cin>>n>>a>>b>>k;
	vector<P> g;
	int ans = 0;
	set_fac();
	rep(i,n+1)
	{
		if((k-i*a) < 0) break;
		if((k-i*a)%b) continue;
		if((k-i*a)/b > n) continue;
		g.push_back(P(i,(k-i*a)/b));
	}
	
	rep(i,g.size())
	{
		//cout << g[i].first << " " << g[i].second << endl;
		ans += (nCk(n,g[i].first) *nCk(n,g[i].second))%MOD;
		ans %= MOD;
		
		
		
	}
	
	cout << ans << endl;
}

//cout << ans << endl;

Measured memory_bytes: 10992
#include <stdio.h>
#include <string.h>

struct element;
typedef struct _element {
	char city;
	struct element *e[2];
}element;

int main(void) {
	char buff[105];
	int i;
	int flag;
	element *p;
	int n;
	element e[6];
	
	e[0].city = 'A';
	e[0].e[0] = (element*)&e[1];
	e[0].e[1] = (element*)&e[2];
	e[1].city = 'X';
	e[1].e[0] = NULL;
	e[1].e[1] = (element*)&e[3];
	e[2].city = 'Y';
	e[2].e[0] = (element*)&e[1];
	e[2].e[1] = NULL;
	e[3].city = 'Z';
	e[3].e[0] = (element*)&e[4];
	e[3].e[1] = (element*)&e[5];
	e[4].city = 'W';
	e[4].e[0] = (element*)&e[5];
	e[4].e[1] = (element*)&e[2];
	e[5].city = 'B';
	e[5].e[0] = (element*)&e[2];
	e[5].e[1] = (element*)&e[1];
	
	while(scanf("%s\n", buff) == 1) {
		p = &e[0];
		n = strlen(buff);
		if(buff[0] == '#') break;
		for(i=0;i<n;i++) {
			flag = 0;
			if(p->e[buff[i]-'0'] == NULL) {
				printf("No\n");
				flag = 1;
				break;
			}
			p = p->e[buff[i]-'0'];
		}
		
		if(!flag) {
			if(p!= NULL && p->city == 'B') {
				printf("Yes\n");
			} else {
				printf("No\n");
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <iostream>

using namespace std;
void trace(int a[],int n){
    for(int i=0;i<n;i++){
        if(i>0)cout << " ";
        cout << a[i];
    }
    cout << endl;
}

void Insort(int a[],int n){
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
            a[j+1]=v;
        }
        trace(a,n);
    }
}

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
     trace(a,n);
     Insort(a,n);
     return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>

int main(void)
{
    int n;
    int i[1000], p[1000], q[1000], r[1000];
    int P, Q, R, C;
    int j, k;
    int flag;
    int c;
    
    while (1){
        scanf("%d", &n);
        if (n == 0){
            break;
        }
        for (j = 0; j < n; j++){
            scanf("%d%d%d%d", &i[j], &p[j], &q[j], &r[j]);
        }
        scanf("%d%d%d%d", &P, &Q, &R, &C);
        
        flag = 0;
        for (j = 0; j < n; j++){
            c = p[j] * 4 + q[j] * 9 + r[j] * 4;
            if (p[j] <= P && q[j] <= Q && r[j] <= R && c <= C){
                printf("%d\n", i[j]);
                flag = 1;
            }
        }
        if (flag == 0){
            printf("NA\n");
        }
    }
    return (0);
}

    

Measured memory_bytes: 628
main = do
  n <- readLn
  s <- getLine
  putStrLn $ solve n s

solve :: Integer -> String -> String
solve n s =
    case r > b of
      True -> "Yes"
      False -> "No"
    where r = length . filter (\c -> c=='R') $ s
          b = length . filter (\c -> c=='B') $ s



Measured memory_bytes: 3800
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map> 
#include <stack>
#include <sstream>
#include <set>
#pragma GCC optimize(2)

//#define int long long
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
//你冷静一点，确认思路再敲！！！ 

using namespace std;
typedef long long ll;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin; //  ssin << string   while ( ssin >> int)

const int N = 3e5 + 5, M = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
int n, x, y;
int a[N];

inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}

int main(){
    cin>>n>>x>>y;
    int a[n+1]={0};
    for(int i=1;i<=n;i++){
        for(int j=1;j<i;j++){
            a[min(i-j,abs(x-j)+abs(y-i)+1)]++;
        }
    }
    for(int i=1;i<=n-1;i++)
        cout<<a[i]<<endl;
}

Measured memory_bytes: 3592
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort()
f.sort(reverse=True)
lst = []
maxi = 0
for i in range(n):
    lst.append([a[i]*f[i], f[i]])
    maxi = max(maxi, a[i]*f[i])

left = -1 # 不可能
right = maxi # 可能
while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    for i in range(n):
        lsti = lst[i]
        if lsti[0] > mid:
            sa = lsti[0] - mid
            cnt += (sa+lsti[1]-1) // lsti[1]
    if cnt <= k:
        right = mid
    else:
        left = mid
print(right)

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

struct Point {
    ld x, y;
    Point(ld x = 0.0, ld y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};
Point rotate(const Point &p, double angle){
  ld rad = angle * M_PI / 180;
  ld x= p.x*cos(rad)-p.y*sin(rad);
  ld y= p.x*sin(rad)+p.y*cos(rad);
  return Point(x, y);
}
ld distance(const Point &p1, const Point &p2){
  return sqrt(pow(p1.x-p2.x, 2)+pow(p1.y-p2.y, 2));
}
int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  cout.precision(17);

  double a, b, h, m;cin>>a>>b>>h>>m;

  double ar = h*30+m/2.0;
  double br = m*6.0;

  Point p1(0, a);
  Point p2(0, b);
  p1 = rotate(p1, -ar);
  p2 = rotate(p2, -br);
  cout<<distance(p1, p2)<<endl;

  return 0;
}


Measured memory_bytes: 4140
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;
const int MOD = 1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    Rep (i, n) cin >> x[i];
    Rep (i, m) cin >> y[i];

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    ll width = 0, height = 0;

    Rep (i, n-1) {
        ll tmp = x[i+1] - x[i];
        tmp = tmp * (i+1) % MOD * (n-i-1) % MOD;
        width += tmp;
        width %= MOD;
    }

    Rep (i, m-1) {
        ll tmp = y[i+1] - y[i];
        tmp = tmp * (i+1) % MOD * (m-i-1) % MOD;
        height += tmp;
        height %= MOD;
    }

    ll ans = width * height % MOD;
    cout << ans << endl;
}

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

int N, A, B, C, D;
string S;

int main() {
	cin >> N >> A >> B >> C >> D;
	cin >> S;

	bool ans = true;
	for (int i = A; i < C; i++) {
		if (S[i] == '#' && S[i + 1] == '#') {
			ans = false;
		}
	}

	for (int i = B; i < D; i++) {
		if (S[i] == '#' && S[i + 1] == '#') {
			ans = false;
		}
	}

	if (ans && C > D) {
		ans = false;
		for (int i = B - 2; i < C - 2; i++) {
			if ( S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.' && i + 1 < D) {
				ans = true;
				break;
			}
		}
	}

	if (ans)	cout << "Yes";
	else        cout << "No";
	cout << endl;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int ans = 0;
		String Nlen = Integer.toString(N );

		for(int i = 0;i < Nlen.length();i++){
			int tmp = N % 10;
			double tmp2 = Math.pow(10, i);
			if(tmp == 1){
				ans = (int) (ans + 9*tmp2);
			}else if(tmp == 9){
				ans = (int) (ans + 1*tmp2);
			}else{
				ans = (int) (ans + 1*tmp2); 
			}
			N = N / 10;
		} 

		//最大の数
		System.out.println(ans);

   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long

double dp[301][301][301];

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    bool dp[k+1];
    memset(dp, false, sizeof(dp));
    for(int i=1; i<=k; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(i-arr[j] < 0)
                continue;
            if(!dp[i-arr[j]])
            {
                dp[i] = true;        
            }            
        }
    }
    if(dp[k])
        cout<<"First";
    else
    {
        cout<<"Second";
    }
    
    return 0;
}

Measured memory_bytes: 384
a=int(input())
b=int(input())

if a==1:
  if b==2:
    print(3)
  else:
    print(2)
elif a==2:
  if b==1:
    print(3)
  else:
    print(1)
elif a==3:
  if b==2:
    print(1)
  else:
    print(2)

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
#endif


    int n, ele, k;
    cin >> n >> k;
    vector<int> H;

    for (int i = 0; i < n; i++)
    {
        cin >> ele;
        H.push_back(ele);
    }

    int dp[n];


    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        dp[i] = INT_MAX;
        for (int j = 1; j <= k; j++)
        {
            if (j < n && i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(H[i - j] - H[i]));
        }
    }
    cout << dp[n - 1] << endl;
    return 0;

}

Measured memory_bytes: 4172
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << 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 input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

 
template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) return b;
    gcd(b, a%b);
}

template<typename U>
U lcm(U a, U b) {
    U ans = a*b/gcd(a, b);
    return ans;
}

int main(int argc, char const *argv[]) {
    ll a,b; cin>>a>>b;
    cout << lcm(a,b) << '\n';
    return 0;
}

Measured memory_bytes: 256
require 'rational'

class AOJ0520
  def initialize(n)
    @n = n
    @poles = []
  end

  def solve
    @n.times{ @poles << gets.split.map(&:to_i) }

    top = ((1..@n).to_a - @poles.map{ |p| [p[2], p[3]] }.flatten)[0]

    weight(top-1)
  end

  def weight(id)
    r = (@poles[id][2] == 0 ? 1 : weight(@poles[id][2]-1))
    l = (@poles[id][3] == 0 ? 1 : weight(@poles[id][3]-1))

    p = @poles[id][0]
    q = @poles[id][1]

    a = (r*p).lcm(l*q) / q
    b = (r*p).lcm(l*q) / p

    a+b
  end
end

while (n = gets.chomp.to_i) != 0
  puts AOJ0520.new(n).solve
end

Measured memory_bytes: 3372
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

class Pair implements Comparable<Pair> {
    public int first;
    public int second;

    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public int compareTo(Pair o) {
        return second - o.second;
    }
}

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        String S = fs.next();
        String T = fs.next();

        int ans = Integer.MAX_VALUE;
        for (int i = 0; i <= S.length()-T.length(); ++i) {
            int cnt = T.length();
            for (int j = 0; j < T.length(); ++j) {
                if (S.charAt(i+j) == T.charAt(j)) {
                    --cnt;
                }
            }
            ans = Math.min(ans, cnt);
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 32704
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include<algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};

int main() {
  string n;
  cin >> n;
  bool RL = false;
  bool LR = false;
  int RLcount = 0;
  int LRcount = 0;
  int start = 0;
  int size = n.size();
  int ans[size] = {0};
  for(int i=start;i<size;i++){
   if(RL == false && n.at(i) == 'L'){
     RL = true;
     RLcount = i;
   }
   else if(RL && n.at(i) == 'R'){
     LR == true;
     LRcount = i;
     if((RLcount-start)%2 == 1){
     ans[RLcount] = (LRcount-start)/2;
     ans[RLcount-1] = LRcount - start - ans[RLcount];
     }
     else if((RLcount-start)%2 == 0){
     ans[RLcount-1] = (LRcount-start)/2;
     ans[RLcount] = LRcount- start - ans[RLcount-1];
     }
     RL = false;
     LR = false;
     start = i;
   }
  }
  if((RLcount-start)%2 == 1){
     ans[RLcount] = (size-start)/2;
     ans[RLcount-1] = size - start - ans[RLcount];
     }
  else if((RLcount-start)%2 == 0){
    ans[RLcount-1] = (size-start)/2;
    ans[RLcount] = size- start - ans[RLcount-1];
  }
    
  for(int i=0;i<size;i++)
	cout << ans[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 1792
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    bs <- B.getLine
    print $ solve n bs

solve :: Int -> B.ByteString -> Int
solve n bs = sum [M.findWithDefault 0 pair rightFreq| pair<-lefts]
  where
    (left, right) = B.splitAt n bs
    lefts = pairs n left
    rights = map swap . pairs n $ B.reverse right
    !rightFreq = foldl' (\m pair -> M.insertWith (+) pair 1 m) M.empty rights

pairs :: Int -> B.ByteString -> [(B.ByteString, B.ByteString)]
pairs n bs = [divide i bs|i<-[0..2^n-1]]
  where
    divide :: Int -> B.ByteString -> (B.ByteString, B.ByteString)
    divide i bs = (xs, ys)
      where
        (xis, yis) = partition (testBit i) [0..n-1]
        !xs = B.pack $ map (B.index bs) xis
        !ys = B.pack $ map (B.index bs) yis



Measured memory_bytes: 148860
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int dp[maxn];
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    dp[2] = abs(arr[2]-arr[0]);
    for(int i=3; i<=n; i++)
    {
        dp[i] = min( abs(arr[i]-arr[i-2])+dp[i-2], abs(arr[i]-arr[i-1])+dp[i-1]);
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int dfs(vector<set<int>>& g, vector<bool>& c, int current) {
    if (c[current])
        return 0;

    c[current] = true;
    int cnt = 1;
    for (auto i : g[current])
        cnt += dfs(g, c, i);

    return cnt;
}

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

    vector<set<int>> g(n);
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].insert(b);
        g[b].insert(a);
    }

    vector<bool> c(n, false);
    int ans = 0;
    for (int i=0; i<n; i++) {
        int cnt = dfs(g, c, i);
        ans = max(ans, cnt);
    }

    cout << ans << endl;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
int n,a[maxn];
bool judge(int a,int b,int c)
{
    return a+b>c&&b+c>a&&c+a>b;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        for(int k=j+1;k<=n;k++)
    {
        if(a[i]==a[j]||a[i]==a[k]||a[k]==a[j]) continue;
        if(judge(a[i],a[j],a[k])) ans++;
    }
    printf("%d\n",ans);
}


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

long long xx[100000];
int x;

int main( int argc, char *argv[] )
{
    int max;
    long long a, b;

    xx[0] = 0;
    for( int i=1; ; i++ ) {
        xx[i] = (long long) i*i*i*i*i;
        max = i;
//        printf( "%d %lld\n", i, xx[i] );
        if( xx[i] < xx[i-1] ) break;
    }

//printf( "max = %d\n", max );

    scanf( "%d", &x );

    for( int i=1; i<max; i++ ) {
        for( int j=0; j<i; j++ ) {
            if( xx[i] - xx[j] == x ) {
                printf( "%d %d\n", i, j );
                exit( 0 );
            }
        }
    }

    for( int i=1; i<max; i++ ) {
        for( int j=0; j<i; j++ ) {
            if( xx[i] + xx[j] == x ) {
                printf( "%d %d\n", i, -j );
                exit( 0 );
            }
        }
    }
}


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

int main()
{
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  int min_sum = 2147483647;
  for (int i = -100; i <= 100; i++)
  {
    int sum = 0;
    for (int j = 0; j < N; j++)
    {
      sum += pow(abs(a[j] - i), 2);
    }
    if (sum < min_sum)
    {
      min_sum = sum;
    }
  }
  cout << min_sum << endl;
  return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int z = sc.nextInt();
		int w = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		sc.close();
		
		int score;
		if(n == 1){ System.out.println(Math.abs(a[n-1] - w));
			return;
		}
		if(Math.abs(a[n-1] - w) > Math.abs(a[n-2] - a[n-1])){
			System.out.println(Math.abs(a[n-1] - w));
		}else{
			System.out.println(Math.abs(a[n-2] - a[n-1]));
		}
	}
}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

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

ll v=n%k;
ll u=k-v;
cout<<min(v,u)<<endl;
return 0;




}




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

int32_t main()
{
    int n,m;
    cin>>n>>m;
    char arr[n][m];int dp[n][m];
    memset(dp, 0, sizeof(dp));
    dp[0][0]=1;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='.')
            {
                //cout<<dp[i][j]<<" ";
                //cout<<"HAHA ";
                if(i>0 && arr[i-1][j]=='.')
                {
                    dp[i][j] += dp[i-1][j];
                    dp[i][j]%=1000000007;
                }
                if(j>0 && arr[i][j-1]=='.')
                {
                    dp[i][j] += dp[i][j-1];
                    dp[i][j]%=1000000007;
                }
            }
        }
    }
    // for(int i=0; i<n; i++)
    // {
    //     for(int j=0; j<m; j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[n-1][m-1]%1000000007;;
    return 0;
}

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

int main() {
	int N, D, X;
	cin >> N >> D >> X;
	for (int i = 0;i<N;++i) {
		int A;
		cin >> A;
		X += (D+A-1)/A;
	}
	cout << X << endl;
	return 0;
}


Measured memory_bytes: 3596
def compute(x):
	if x>=2:
		return (x*(x-1)//2)
	else:
		return 0

n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
	if i not in d:
		d[i] = 1
	else:
		d[i] += 1
s = 0
for j in d:
	s += compute(d[j])

for i in a:
	temp = s - compute(d[i])
	temp = temp + compute(d[i]-1)
	print(temp)

Measured memory_bytes: 25644
#include<stdio.h>

int main(void){
    char str[5];
    int i, result=0;

    scanf("%s", str);
    for(i=0; i<4; i++){
        if(str[i] == '+')
            result++;
        else
            result--;
    }
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int>cnt(9);
    rep(i,n) {
        int a;
        cin >> a;
        int rate = a/400;
        if(rate>=8)rate = 8;
        cnt[rate]++;
    }
    int minv = 0;
    int maxv = 0;
    rep(i,8) {
        if(cnt[i]) {
            minv++;
            maxv++;
        }
    }
    if(minv==0) minv++;
    maxv += cnt[8];
    cout << minv << " " << maxv << endl;
    

}

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

int main() {
    int N, M; cin >> N >> M;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    long long res = 0;
    vector<long long> plus, minus;
    for (int i = 0; i < N; ++i) {
        res += abs(a[i] - i);
        if (a[i] >= i) plus.push_back(a[i]), minus.push_back(i);
        else plus.push_back(i), minus.push_back(a[i]);
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end(), greater<long long>());

    for (int i = 0; i < M; ++i) {
        if (plus[i] < minus[i]) {
            res += (minus[i] - plus[i]) * 2;
        }
        else {
            break;
        }
    }
    cout << res << endl;
}       



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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

void solve() {
    int n;
    cin >> n;
    ll pref[n + 1];
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pref[i] = a[i];
        if (i) {
            pref[i] = 1ll*a[i] + pref[i-1];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = add(ans, mul(sub(pref[n-1], pref[i]), a[i]));
    }

    cout << ans << endl;

}

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

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 5544
import * as fs from "fs";

const input = fs.readFileSync("/dev/stdin", "utf8").split(" ");

const A = +input [0];
const B = +input [1];

if (A - 2 *B > 0) {
    console.log (A - 2 * B);
  }  else {
    console.log (0);
  }


Measured memory_bytes: 7372
from sys import stdin

lines = stdin.readlines()

n = int(lines[0].rstrip())
s = str(lines[1].rstrip())

counter = 0
for i in range(n-2):
    if s[i] == 'A':
        if s[i+1] == 'B':
            if s[i+2] == 'C':
                counter += 1
print(counter)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(void){
 int n; cin >> n;
 int m = INT_MAX, sum = 0;
 int s[n]; for(int i=0;i<n;i++){
  cin >> s[i];
  sum += s[i];
  if (s[i] < m && s[i]%10) m = s[i];
 }
 int ans;
 if (sum%10) ans = sum;
 else if (m == INT_MAX) ans = 0;
 else ans = sum - m;
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(T) for T in input().split()]
Color = [T//400 for T in A if T<3200]
ColL = len(Color)
SetL = len(set(Color))
MIN = max(1,SetL)
MAX = SetL+(N-ColL)
print('{} {}'.format(MIN,MAX))

Measured memory_bytes: 9136
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};

int s_to_i(string s) {
	stringstream ss(s);
	int res; ss >> res;
	return res;
}

int N;
string a[1010];

void solve() {
	int lb = -iINF, ub = iINF;
	
	for_(i,1,N) {
		if (a[i] == "x") {
			if (a[i - 1] == "x") {
				cout << "none" << endl;
				return;
			} else {
				int val = s_to_i(a[i - 1]);
				
				if (i % 2) {
					lb = max(lb, val + 1);
				} else {
					ub = min(ub, val - 1);
				}
			}
		} else {
			int val = s_to_i(a[i]);
			
			if (a[i - 1] == "x") {
				if (i % 2) {
					ub = min(ub, val - 1);
				} else {
					lb = max(lb, val + 1);
				}
			} else {
				int val2 = s_to_i(a[i - 1]);
				
				if (i % 2) {
					if (val2 >= val) {
						cout << "none" << endl;
						return;
					}
				} else {
					if (val2 <= val) {
						cout << "none" << endl;
						return;
					}
				}
			}
		}
		
		if (lb > ub) {
			cout << "none" << endl;
			return;
		}
	}
	
	if (lb == ub) cout << lb << endl;
	else cout << "ambiguous" << endl;
}

int main() {
	while (cin >> N, N) {
		for_(i,0,N) cin >> a[i];
		solve();
	}
	return 0;
}

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

int main() {
	int k,n,m=0;
	cin >> k >> n;
	int a[n],c[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			c[i] = k + a[0] - a[i];
		}
		else {
			c[i] = a[i + 1] - a[i];
		}
	}
	for (int i = 0; i < n; i++) {
		if (m < c[i]) {
			m = c[i];
		}
	}
	cout << k - m << endl;
	return 0;
}

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

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

Measured memory_bytes: 3644
#include <cstdio>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int S, seconds, hours, minutes;

	cin >> S;

	hours = S / 3600;
	minutes = (S % 3600) / 60;
	seconds = (S % 3600) % 60;

	printf( "%d:%d:%d\n", hours, minutes, seconds );

	return 0;
}

Measured memory_bytes: 1148