akhauriyash/Code-Regression huggingface dataset:
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
a,b,h,m = gets.chomp.split.map(&:to_i)
kaku = h.to_f / 12 + m.to_f / 60 / 12 - m.to_f / 60
puts Math.sqrt(a**2 + b**2 - 2.0*a*b*Math.cos(kaku * 360 * Math::PI / 180))


Measured memory_bytes: 15108
n=int(input())
divisors = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
            divisors.append(n//i)
if n==divisors[-1]**2:
    print(divisors[-1]*2-2)
else:
    print(divisors[-1]+divisors[-2]-2)

Measured memory_bytes: 3268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int [] a = new int[n];
		for(int i=0;i<a.length;i++) {
			a[i]=sc.nextInt();
		}
		for(int i=a.length-1;i>=0;i--) {
			if(i!=a.length-1) {
				System.out.printf(" ");
			}
			System.out.printf("%d",a[i]);
		}
		System.out.printf("\n");
		
	}
}

	


Measured memory_bytes: 26732
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  double pi = 3.1415926535;
  int n;
  cin >> n;
  cout << n * 2 * pi << endl;
}

Measured memory_bytes: 3780
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
 
using namespace std;
 
 
#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif
 
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
 
typedef long long int lint;
typedef pair<int,int> pi;
 
namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}
 
//const int INF=5e8;
 
int ecnt[1005];
int main(){
  int n;cin>>n;
  for(int i=2;i<=n;++i){
    int tmp=i;
    for(int j=2;j*j<=tmp;++j) if(tmp%j==0){
      while(tmp%j==0){
        tmp/=j;
        ++ecnt[j];
      }
    }
    if(tmp>1) ++ecnt[tmp];
  }
  const int mod=1000000007;
  lint res=1;
  REP(i,n+1) res=res*(ecnt[i]+1)%mod;
  cout<<res<<endl; 
 
 
 
  return 0;
}
 
 


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

long long n, cnt=1;

int main(){
	cin >> n;
	for (int i=0;i<n;i++){
		long long a;
		cin >> a;
		if (a==cnt) cnt++;
	}
	if (cnt==1) cout << -1 << "\n";
	else cout << n-cnt+1 << "\n";
}

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

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int *a = new int[n], *pos = new int[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        pos[a[i]] = i;
    }
    set<int> s;
    s.insert(-1);
    s.insert(n);
    long long result = 0;
    for (int i = 0; i < n; ++i) {
        int ps = pos[i];
        int l = *(--s.lower_bound(ps));
        int r = *s.lower_bound(ps);
        result += (1LL * (r - ps - 1) * (ps - l - 1) + (r - l - 1)) * (i + 1);
        s.insert(ps);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 11264
s = list(input())
s1 = int("".join(s[:2]))
s2 = int("".join(s[2:]))

if 1 <= s1 <= 12 and 1 <= s2 <= 12:
    print('AMBIGUOUS')
elif 1 <= s1 <= 12:
    print('MMYY')
elif 1 <= s2 <= 12:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 9036
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m, n | m) {
        vector<int> ma(n, 0), mi(n, 0);
        for (int i = 0; i < m; i++) {
            int sc, k;
            cin >> sc >> k;
            for (int j = 0; j < k; j++) {
                int c;
                cin >> c;
                ma[c - 1] += sc;
                if (k == 1) mi[c - 1] += sc;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                ans = max(ans, ma[i] - mi[j] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
/*input
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 300005
#define hell 1000000007
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll h,w;
string g[1002];

int main() 
{
    off;
    cin>>h>>w;
    for(ll i=0;i<h;i++)
        cin>>g[i];
    ll dp[h][w];
    memset(dp,0,sizeof(dp));
    for(ll i=0;i<h;i++)
    {
        if(g[i][0]=='.')
            dp[i][0]=1;
        else
            break;
    }
    for(ll i=0;i<w;i++)
    {
        if(g[0][i]=='.')
            dp[0][i]=1;
        else
            break;
    }
    for(ll i=1;i<h;i++)
    {
        for(ll j=1;j<w;j++)
        {
            if(g[i][j]=='.')
                dp[i][j]=((dp[i-1][j]%hell)+(dp[i][j-1]%hell))%hell;
            else
                dp[i][j]=0;
        }
    }
    cout<<dp[h-1][w-1];
    return 0;
}

Measured memory_bytes: 9088
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let k = scan!(usize);

    println!("50");
    let mut arr: Vec<usize> = (0..50).map(|i| i + (k / 50)).rev().collect();

    for v in arr.iter_mut().take(k % 50) {
        *v += 1
    }

    for (i, &v) in arr.iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", v);
    }
    println!();
}


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

int pat(int a)
{
    return a * (a - 1) / 2;
}

int main()
{
    int N, ans = 0;
    cin >> N;
    vector<int> L(N);
    for (int i = 0; i < L.size(); i++)
    {
        cin >> L.at(i);
    }

    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());

    for (int i = 0; i < L.size() - 2; i++)
    {
        int num = L.size() - (i + 1);
        int T = pat(num);
        for (int j = i + 1; j < L.size() - 1; j++)
        {
            if (L.at(i) >= L.at(j) + L.at(j + 1))
            {
                T -= pat(N - j);
                for (int k = j - 1; k > i; k--)
                {
                    for (int l = j + 1; l < L.size(); l++)
                    {
                        if (L.at(i) >= L.at(k) + L.at(l))
                        {
                            T -= (N - l);
                            break;
                        }
                    }
                }
                break;
            }
        }
        ans += T;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N = int(input())

power = 1
for i in range(N):
    power = (power * (i+1)) % mod
print(power)


Measured memory_bytes: 5576
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        x: usize,
    }
    let mut i = 0;
    while i * (i + 1) / 2 < x {
        i += 1;
    }
    println!("{}", i);
}


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

int main(){
  int a,b,ans;
  cin >> a >> b;
  ans = 0;
  int i,j,k;
  i = a+b;
  j = a-b;
  k = a*b;
  ans = max(j,k);
  ans = max(i,ans);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    
    static class State implements Comparable<State>{
        String name;
        double cost;
        State(String name, double cost){
            this.name=name;
            this.cost=cost;
        }
        public int compareTo(State s) {
            if(s.cost==this.cost) {
                return this.name.compareTo(s.name);
            }
            else if(this.cost>s.cost) {
            	return -1;
            }
            else {
            	return 1;
            }
        }
    }
    
    
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int N=sc.nextInt();
                if(N==0) break;
                PriorityQueue<State> pq=new PriorityQueue<State>();
                for(int i=0; i<N; i++) {
                    String name=sc.next();
                    int p=sc.nextInt();
                    int a=sc.nextInt();
                    int b=sc.nextInt();
                    int c=sc.nextInt();
                    int d=sc.nextInt();
                    int e=sc.nextInt();
                    int f=sc.nextInt();
                    int s=sc.nextInt();
                    int m=sc.nextInt();
                    int turn1=a+b+c+d+e;
                    int turn2=d+e;
                    int benefit=f*s*m-p;
                    double cost=1.0*benefit/(double)(turn1+(m-1)*turn2);
                    pq.add(new State(name, cost));
                }
                for(int i=0; i<N; i++) {
                    State st=pq.remove();
                    System.out.println(st.name);
                }
                System.out.println("#");
            }


        }
    }
} 


Measured memory_bytes: 47892
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int A,B;
	cin>>A>>B;
	ce((A+B)%24)
	
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int main() {
	int n;
	cin >> n;
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		mp[a - 1] += 1;
		mp[a    ] += 1;
		mp[a + 1] += 1;
	}
	int ans = 0;
	for (auto &x : mp) {
		ans = max(ans, x.second);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4736
using System;
using System.Linq;
class Program{
  public static void Main(string[] args){
    decimal[] input = Console.ReadLine().Split(' ').Select(a => decimal.Parse(a)).ToArray();
    decimal minA = Math.Floor(input[0] / .08m), maxA = Math.Floor((input[0]+1m) / .08m);
    decimal minB = Math.Floor(input[1] / .1m), maxB = Math.Floor((input[1]+1m) / .1m);
    decimal min = Math.Max(minA, minB);
    decimal max = Math.Min(maxA, maxB);

    for(decimal i = min; i < max; i += 1m){
      if(Math.Floor(i * .08m) == input[0] && Math.Floor(i * .1m) == input[1]){
        Console.WriteLine(i);
        return;
      }
    }
    Console.WriteLine(-1);
  }
}

Measured memory_bytes: 13396
def main():
    N = int(input())
    S = list(input())
    # print(S)

    right_white = S.count('.')
    left_black = 0

    ans = min(S.count('.'), S.count('#'))
    for i in range(len(S)):
        if S[i] == '#':  # black
            left_black += 1
        else: # white
            right_white -= 1

        ans = min(ans, left_black + right_white)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4840
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import Text.Printf

readInt = ( readLn :: IO Int )
getInts = map ( read :: String -> Int ) . words <$> getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	x : ab <- getInts
	let
		[ a, b ] = map abs . map ( (-) x ) $ ab
	putStrLn . which "A" "B" $ a < b


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

int main() {
	int N,T,ans;
    double A;
    double m = 550;
    cin >> N >> T >> A;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
        double tx = T - H.at(i) * 0.006;
        if ((max(tx,A) - min(tx,A)) < m) {
            ans = i;
            m = max(tx,A) - min(tx,A);
        }
    }
    cout << ans + 1 << endl;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll a[400000];
ll b[62][400000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%lld",&a[i]);
		rep(j,62){
			if(a[i]>>j&1)b[j][i]=1;
		}
	}
	ll ans=0;
	rep(i,62){
		for(int j=n-2;j>=0;j--){
			if(a[j]>>i&1){
				ans+=(1LL<<i)%MOD*(n-j-1-(b[i][j+1]))%MOD;
			}
			else{
				ans+=(1LL<<i)%MOD*(b[i][j+1])%MOD;
			}
			ans%=MOD;
			b[i][j]+=b[i][j+1];
		}
	}
	cout<<ans<<endl;
}

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

#define x first
#define y second
#define int64 long long
#define debug(x) cerr << #x << " is " << x << endl;
#define MaxN 100000

char s[MaxN+2];
int N;

int main(){

    int i, now, next;

    scanf("%s", s);
    N = strlen(s);

    for(i = N; i >= 1; --i) s[i] = s[i-1];
    for(i = 1; i < N; ++i)
        if(s[i] != s[N-i]){
            printf("-1\n");
            return 0;
        }

    if(s[1] != '1' || s[N] != '0'){
        printf("-1\n");
        return 0;
    }

    now = 2;
    next = 3;
    printf("1 2\n");
    for(i = 2; i <= N / 2; ++i)
    if(s[i] == '0'){
        printf("%d %d\n", now, next);
        ++next;
    } else {
        printf("%d %d\n", now, next);
         now = next;
         ++next;
    }

    while(next <= N){
        printf("%d %d\n", now, next);
        ++next;
    }


return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

void showIntArray(int a[], int n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}

int main() {
  int N, H[10000], c=0, flag;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> H[i];
    flag = 1;
    for (int j=0; j<i; j++) {
      if (H[i] < H[j]) {
        flag = 0;
        break;
      }
    }
    if (flag == 1) {
      c++;
    }
  }
  cout << c << endl;
  return 0;
}

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

int digit(ll p)
{
    ll c=0;
    while(p>0)
    {
        c++;
        p=p/10;
    }
    return c;
}

void solve()
{
    ll n;
     cin >> n;
     ll ans=0;
     for(int i=1;i<=n;i++)
     {
         if(digit(i)%2!=0)
            ans++;
     }
     cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=100005,Mod=1e9+7;
int a[N];
inline int qpow(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=1ll*ans*a%Mod;
		a=1ll*a*a%Mod,b>>=1;
	}
	return ans;
}
int f[N],fac[N];
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&a[i]);fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	int now=0,p=0;
	for (int i=2;i<=n;i++){
		p=(p+qpow(i-1,Mod-2))%Mod;
		now=(now+1ll*p*(a[i]-a[i-1]))%Mod;
	}
	printf ("%d",1ll*now*fac[n-1]%Mod);
	return 0;
}


Measured memory_bytes: 1024
from collections import deque
S = deque([str(x) for x in input()])
T = deque([str(x) for x in input()])
U = deque([str(x) for x in input()])

f = 0
while True:
    if f == 0:
        l = S.popleft()
    elif f == 1:
        l = T.popleft()
    else:
        l = U.popleft()
    if l == "a":
        f = 0
    elif l == "b":
        f = 1
    else:
        f = 2
    if f == 0 and len(S) == 0:
        print("A")
        exit(0)
    elif f == 1 and len(T) == 0:
        print("B")
        exit(0)
    elif f == 2 and len(U) == 0:
        print("C")
        exit(0)


Measured memory_bytes: 38896
h,w = map(int,input().split())
C = [list(input()) for i in range(h)]

queue = []
visited = [] 
ans = 0
for i in range(h):
    T = [0]*w
    visited.append(T) 


for i in range(h):
    for j in range(w):
        if C[i][j] == '.':
            queue.append([i,j])
            visited[i][j] = 1

            dy_dx = [[1,0],[0,1],[-1,0],[0,-1]]

            while len(queue) > 0:
                now = queue.pop(0)
                for k in range(4):
                    y = now[0]+dy_dx[k][0]
                    x = now[1]+dy_dx[k][1]
                    if 0 <= y < h and 0 <= x < w:
                        if C[y][x] != '#' and visited[y][x] == 0:
                            visited[y][x] = visited[now[0]][now[1]]+1
                            queue.append([y,x])
                    
        for ii in range(h):
            for jj in range(w):
                ans = max(ans,visited[ii][jj])
            
        queue = []
        visited = [] 
        for l in range(h):
            T = [0]*w
            visited.append(T) 
                        
        
print(ans-1)

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

int main() {
    int K,N;
    cin >>K>>N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    int m=0;
    for (int i = 0; i < N-1; i++){
        m=max(m,A[i+1]-A[i]);
    }
    m=max(m,A[0]-A[N-1]+K);
    cout << K-m<<endl;
}

Measured memory_bytes: 1024
<?php
fscanf(STDIN, "%d", $N);
$d = [];
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $a[$i], $b[$i]);
    $c[$i] = $a[$i] + $b[$i];
}
array_multisort($c, SORT_DESC, $a, $b);

$T = array_sum(array_filter($a, function($v, $k) {
    return $k % 2 === 0;
}, ARRAY_FILTER_USE_BOTH));

$A = array_sum(array_filter($b, function($v, $k) {
    return $k % 2 === 1;
}, ARRAY_FILTER_USE_BOTH));

printf("%d", $T - $A);


Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>


#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)

using namespace std;

constexpr int M = 10000;

bool is_same_char(char a, char b)
{
	if (a == '?') return true;
	if (b == '?') return true;
	return (a == b);
}


void construct(vector<bool>& dst, const string& lhs, const string& rhs)
{
	FOR_LT(i, 0, rhs.size()) {
		bool is_ok = true;
		FOR_LT(j, 0, min(lhs.size(), rhs.size() - i)) {
			if (!is_same_char(lhs[j], rhs[j + i])) {
				is_ok = false;
				break;
			}
		}
		dst[M-i] = is_ok;
	}
	FOR_LT(i, 0, lhs.size()) {
		bool is_ok = true;
		FOR_LT(j, 0, min(lhs.size() - i, rhs.size())) {
			if (!is_same_char(lhs[j + i], rhs[j])) {
				is_ok = false;
				break;
			}
		}
		dst[M+i] = is_ok;
	}
}

void print(unordered_map<int, bool>& src)
{
	for (auto& s : src) {
		cout << s.first << " " << s.second << endl;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	string a, b, c; cin >> a >> b >> c;
	vector<bool> is_ok_ab(M * 2, true);
	vector<bool> is_ok_ac(M * 2, true);
	vector<bool> is_ok_bc(M * 2, true);
	construct(is_ok_ab, a, b);
	construct(is_ok_bc, b, c);
	construct(is_ok_ac, a, c);

	/*
	cout << "ab" << endl;
	print(is_ok_ab);
	cout << "bc" << endl;
	print(is_ok_bc);
	cout << "ca" << endl;
	print(is_ok_ac);
	*/

	int ans = INT_MAX;
	FOR_LE(ib, -((int)(b.size() + c.size())), a.size() + c.size()) {
		FOR_LE(ic, -((int) (b.size() + c.size())), a.size() + b.size()) {
			int s = min(min(0, ib), ic);
			int e = max(max((int)a.size(), ib + (int)b.size()), ic + (int)c.size());
			int curans = e - s;
			if (!is_ok_ab[M + ib]) {
				continue;
			}
			if (!is_ok_ac[M + ic]) {
				continue;
			}
			int ibc = ic - ib;
			if (!is_ok_bc[M + ibc]) {
				continue;
			}
			ans = min(ans, curans);
		}
	}
	cout << ans << endl;

	return 0;
}

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



int main() {
  string s;
  cin>>s;
  ll num=0, all=0, ans=0,keta=1, mod=2019;
  int dp[s.size()+1];
  dp[s.size()]=0;
  dp[s.size()-1]=s[s.size()-1]-'0';
  for(ll i=s.size()-2; i>=0; i--){
    keta=(keta*10)%mod;
    num=(s[i]-'0')*keta;
    dp[i]=(dp[i+1]+num%mod)%mod;
    
  }
  
  for(int i=0; i<2019; i++){
    int cnt=0;
    for(int j=0; j<s.size()+1; j++){
      if(i==dp[j])
        cnt++;
    }
    
    ans+=cnt*(cnt-1)/2;
  }
  
  
    
  cout<<ans<<endl;
  
  
  
  
}

Measured memory_bytes: 4484
import Data.List


splittable :: String -> Bool

splittable "" = True

splittable l = if "eraser" `isPrefixOf` l
                  then splittable (drop 6 l)
                  else if "erase" `isPrefixOf` l
                    then splittable (drop 5 l)
                    else if "dreamer" `isPrefixOf` l && (length l <= 7 || (l!!7) /= 'a')
                        then splittable (drop 7 l)
                        else if "dream" `isPrefixOf` l
                            then splittable (drop 5 l)
                            else False




main = do
    l <- getLine
    let result = if (splittable l) then "YES" else "NO"
    putStrLn result


Measured memory_bytes: 7164
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
using namespace std;
typedef long long ll;
ll c[26],s[400][30],last[400][30],d,now = -100000000000;
vector<ll> ans,w;
ll score(int l, int r, vector<ll> &v){//[l,r)
    ll i,j,res = 0;
    for(i=l;i<r;i++){
        for(j=0;j<26;j++){
            last[i][j] = 0;
        }
    }
    for(i=l;i<r;i++){
        int x = v[i]; x--;
        if(x<0 || x>25){
            cout << " b " << x << endl;
            exit(1);
        }
        res += s[i][x];
        if(i!=0){
            for(j=0;j<26;j++){
                last[i][j] = last[i - 1][j];
            } 
        }
        last[i][x] = i + 1;
        for(j=0;j<26;j++){
            res -= c[j]*(i + 1 - last[i][j]);
        }
    }
    return res;
}

void score2(int x,int y){
    vector<ll> vv; vv.resize(d);
    vector<ll> st,ww;
    int i,j;
    for(i=0;i<d;i++){
        ll k = -1,mx = -1000000000;
        for(j=0;j<26;j++){
            if(s[i][j]>mx){
                mx = s[i][j]; k = j + 1;
            }
        }
        if(k!=-1 && mx>x) vv[i] = k;
        else st.push_back(i);
    }
    for(i=0;i<d;i++){
        if(vv[i]==0){
            bool flag = true;
            for(int x:st){
                if(x==i) flag = false;
            }
            if(flag){
                cout << " a " << -1 << endl;
                exit(1);
            }
        }
    }
    for(i=0;i<26;i++){
        if(c[i]>=y) ww.push_back(i + 1);
    }
    int sz = ww.size();
    if(sz==0) return;
    for(j=1;j<=sz;j++){
        int y = j;
        for(int x:st){
            vv[x] = ww[y - 1]; y++;
            if(y==sz + 1) y = 1;
        }
        ll sc = score(0,d,vv);
        if(sc>now){
            swap(ans,vv); now = sc; 
        }
    }
}

void score3(int x){
    vector<ll> vv;
    int i,j;
    for(i=0;i<26;i++){
        if(c[i]>=x) vv.push_back(i + 1);
    }
    int sz = vv.size();
    vector<ll> vvv;
    for(j=0;j<(d + sz - 1)/sz;j++){
        random_device seed_gen;
        mt19937 engine(seed_gen());
        shuffle(vv.begin(),vv.end(),engine);
        for(i=0;i<sz;i++){
            vvv.push_back(vv[i]);
        }
    }
    vvv.resize(d);
    int sc = score(0,d,vvv);
    if(sc>now){
        swap(ans,vvv); now = sc;
    }
}

int main(){
    int i,j; cin >> d;
    for(i=0;i<26;i++) cin >> c[i];
    for(i=0;i<d;i++){
        for(j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    for(i=0;i<d;i++) ans.push_back(i%26 + 1);
    now = score(0,d,ans);
    for(j=1;j<26;j++){
        w.clear();
        for(i=0;i<d;i++) w.push_back((i + j)%26 + 1);
        int sc = score(0,d,w);
        if(sc>now){
            swap(ans,w); now = sc;
        }
    }
    for(i=0;i<=20000;i+=10) score2(i,0);
    for(i=0;i<=20000;i+=10) score2(i,1);
    int cnt = 0;
    for(i=0;i<26;i++){
        if(c[i]!=0) cnt++;
    }
    if(cnt==26){
        for(i=0;i<300;i++) score3(0);
    }
    if(cnt!=26 && cnt!=0){
        for(i=0;i<150;i++) score3(0);
        for(i=0;i<150;i++) score3(1);
    }
    for(i=0;i<d;i++) cout << ans[i] << "\n";
}

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  string s; cin >> s;
  rep(i, s.size()-1) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  cout<<r*r<<endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int N;
struct P {
    double x, y;
};
vector<P> p;

double dist(P a, P b) {
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

double f(double x, double y) {
    double res = 0;
    rep(i, N) chmax(res, dist(P{x, y}, p[i]));
    return res;
}

double g(double x) {
    double l = 0, r = 1000;
    rep(i, 80) {
        double c1 = (l * 2 + r) / 3;
        double c2 = (l + r * 2) / 3;
        if (f(x, c1) > f(x, c2)) l = c1; else r = c2;
    }
    return f(x, l);
}

int main() {
    cin >> N;
    p = vector<P>(N);
    rep(i, N) cin >> p[i].x >> p[i].y;

    double l = 0, r = 1000;
    rep(i, 80) {
        double c1 = (l * 2 + r) / 3;
        double c2 = (l + r * 2) / 3;
        if (g(c1) > g(c2)) l = c1; else r = c2;
    }

    double ans = g(l);
    printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string s,t;
vector<int> v[26];
int main(){
    cin>>s>>t;
    int x=0,y;
    long long ans=0;
    for(int i=0;i<s.size();i++)v[s[i]-'a'].push_back(i+1);
    for(int i=0;i<t.size();i++){
        int c=t[i]-'a';
        if(v[c].size()==0){
            cout<<-1;
            return 0;
        }
        if(v[c][v[c].size()-1]<=x){
            y=v[c][0];
            ans+=y+s.size()-x;
        }else{
            y=*upper_bound(v[c].begin(),v[c].end(),x);
            ans+=y-x;
        }x=y;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1216
from collections import defaultdict
import math
n = int(input())
def is_prime(n):
  if n == 1:
    return False
  
  for k in range(2, int(math.sqrt(n)) + 1):
    if n%k == 0:
      return False
  return True

d = defaultdict(int)

p = []
for i in range(2,n+1):
  if is_prime(i):
    d[i] = 1
    p.append(i)
    continue
  x = i
  for j in p:
    while x%j == 0:
      x //= j
      d[j] += 1

#75
c = 0
for i in d.values():
  if i >= 74:
    c += 1
ans = c

#25 * 3
c,e = 0,0
for i in d.values():
  if i >= 24:
    c += 1
  if i >= 2:
    e += 1
ans += c*(e-1)

#15 * 5
c, e = 0, 0
for i in d.values():
  if i >= 14:
    c += 1
  if i >= 4:
    e += 1
ans += c*(e-1)

#5 * 5 * 3
c,e = 0,0
for i in d.values():
  if i >= 4:
    c += 1
  if i >= 2:
    e += 1
ans += (c*(c-1)//2)*(e-2)

print (ans)



Measured memory_bytes: 9428
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct UnionFind{
  vector<int> par; // 親ノード
  vector<int> rank; // ランク

  UnionFind(int n) { //初期化
    par.resize(n); rank.resize(n);
    rep(i,n) {par[i] = i, rank[i] = 0;}
  }

  int root(int x) { //ノードの根を返す
    if (par[x] == x) return x; //親が自分なら自分を返す
    else {
      int r = root(par[x]); //根まで遡りながら経路圧縮
      return par[x] = r;
    }
  }
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x; //ランクの小さい方に接続
    return true;
  }
};


void Main(){

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

  UnionFind uf(N);

  int p[N];
  rep(i,N){
    cin>>p[i];
  }
  rep(i,M){
    int x,y; cin>>x>>y; --x; --y;
    uf.merge(x,y);
  }
  int ct=0;
  rep(i,N){
    ct+=uf.issame(i,p[i]-1);
  }

  cout<< ct<<"\n";


}

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


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  set<string> s ;
  string ans = "Yes";
  char now ;
  
  rep(i,n){
    string  c ;
    cin >> c ;
    s.insert(c);
    if( i>0 && c.at(0) != now) ans = "No";
    now = c.at(c.size()-1);
    
  }
  
  if(s.size() != n) ans = "No";
  
 cout << ans ;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;

string str;
long long int n,m,a,b,cou=0,res=0;

queue<long long int>que,nextque;
int main() {
	cout << fixed << setprecision(10);
	cin>>str;
	if(str=="Sunny"){
		cout<<"Cloudy"<<endl;
	}else if(str=="Cloudy"){
		cout<<"Rainy"<<endl;
	}else{
		cout<<"Sunny"<<endl;
	}
} 


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

int main(){
    //ios:stdio(false), cin.tie(NULL), cout.tie(NULL);
    int n;
    cin >> n;
    vector<double>a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    
    map<pair<int, int>, int>p;
    for(int rep = 0; rep < n; rep++){
        long long v = llround(a[rep]*1e9);
        
        int two = 0, five = 0;
        while(v%2 == 0){
            two++;
            v/= 2; 
        }
        while(v%5 == 0){
            five ++;
            v /= 5;
        }
        
        p[{two, five}]++;
    }
    long long result = 0;
    for(auto p1 : p){
        for(auto p2 : p){
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
            if(p1 < p2){
                result += (long long)p1.second*p2.second;
            }else if(p1 == p2){
                result += (long long )p1.second*(p1.second - 1)/2;
            }
        }
        }
    }
    
    cout << result << endl;
    
     
}


Measured memory_bytes: 4884
#include <bits/stdc++.h>
using namespace std;
						
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long

int n, a, b;
int h[(int)1e5 + 5];

bool tryit(int mid) {
	bool possible = true;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		if (h[i] - b * mid > 0) {
			sum += (h[i] - b * mid + (a - b - 1)) / (a - b);
		}
	}
	if (sum > mid) possible = false;
	return possible;
}

int32_t main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	IOS
 
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) cin >> h[i];
	sort(h + 1, h + n + 1);
	int l = 0, r = (int)1e9 + 1;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		if (tryit(mid)) r = mid;
		else l = mid;
	}
	cout << r << endl;
 
 
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
for i in range(n):
    if b[i] < a[i]:
        c += b[i]
    else:
        d = min(a[i+1],b[i]-a[i])
        a[i+1] -= d
        c += a[i] + d
print(c)

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int ttl = 0;
  rep2(i, A, B + 1) {
    if ((i % 10 == i / 10000 % 10) && (i / 10 % 10 == i / 1000 % 10)) {
      ttl += 1;
    }
  }
  cout << ttl << endl;
}


Measured memory_bytes: 3632
import itertools
N, M, Q = map(int, input().split())
query = [list(map(int, input().split())) for _ in range(Q)]
l = list(range(1, M+1))
ans = 0
for v in itertools.combinations_with_replacement(l, N):
    A = sorted(list(v))
    cost = 0
    for i in range(Q):
        if A[query[i][1]-1] - A[query[i][0]-1] == query[i][2]:
            cost += query[i][3]
    ans = max(ans, cost)
print(ans)

Measured memory_bytes: 9136
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  cout << n*n*n;
  return 0;
}

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

using namespace std;

int a[300100];

int main()
{
    long long n,m,k,i,ans = 0;
    cin >> n;
    for(i = 1; i <= n; i ++)
    {
        k = i % 10;
        m = i;
        while(m/10) m /= 10;
        a[k*10+m] ++;
    }
    for(i = 1; i <= n; i ++)
    {
        k = i % 10;
        m = i;
        while(m/10) m /= 10;
        ans += a[m*10+k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true) {
        if(c > b) {
            c -= b;
        } else {
            cout << "Yes" << endl;
            return 0;
        }
        if(a > d) {
            a -= d;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3632
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	list := make([]string, a)
	for i := 0; i < a; i++ {
		fmt.Scan(&list[i])
	}

	sort.Strings(list)

	for i := 0; i < a; i++ {
		fmt.Print(list[i])
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i*4+j*7==n){
				ans++;
			}
		}
	}
	
	if(n%4==0 || n%7==0){
		cout<<"Yes"<<endl;
	}
	
	else if(ans>=1){
	cout<<"Yes"<<endl;
	}
	
	else cout<<"No"<<endl;
	
}

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

typedef long long ll;

using namespace std;

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.length()-1; i++){
        if(s[i] == s[i+1]) {
            cout << "Bad" << endl;
            return 0;
        } 
    }
    cout << "Good" << endl;
    return 0;
}

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

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

    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    sort(a.begin(), a.end());

    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            int cnt = lower_bound(a.begin(), a.end(), a[i] + a[j]) - a.begin();
            ans += cnt - j - 1;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
N = int(input())
for i in range(N):
    n,k = map(int,input().split())
    L = list(map(int,input().split()))
    if n <= k:
        print(0)
    else:
        A = []
        for j in range(1,n):
            A.append(L[j]-L[j-1])
        A.sort()
        A.reverse()
        S = L[n-1]-L[0]
        for l in range(k-1):
            S -= A[l]
        print(S)


Measured memory_bytes: 21300
#include<iostream>
using namespace std;
int main()
{
    string S, T, U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;


    if (S == U) {
        A--;
    } else if (T == U) {
        B--;
    }
    
    

    cout << A << " " << B << endl;


    
    return 0;
}

Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
ans=[0]*n

for i in range(len(a)):
    ans[a[i]-1]+=1
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 32200
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    using AB = tuple<int, int>;
    vector<AB> ab(n);
    rep(i, n){
        int a, b; cin >> a >> b;
        ab[i] = AB(a, b);
    }
    sort(_all(ab));

    ll res = 0LL;
    for(auto& e : ab){
        int a, b; tie(a, b) = e;
        res += 1LL * min(m, b) * a;
        m -= b;

        if(m <= 0) break;
    }

    cout << res << endl;

    return 0;
}


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

int main() {
	// your code goes here
	int n, m;
	string s;
	cin >> s;
	
	n = s.find("A");
	m = s.rfind("Z");
	
	cout << m - n  + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;


public class B
{	
	public static void Main()
	{	
		string[] args = Console.ReadLine().Split(' ');
		long N = Int64.Parse(args[0]);
		long M = Int64.Parse(args[1]);
		
		bool[,] flag = new bool[M,N];  // all false
		
		for(int i = 0; i < N; i++)
		{
			args = Console.ReadLine().Split(' ');
			long K = Int64.Parse(args[0]);
			for(int j = 1; j <= K; j++)
				flag[Int64.Parse(args[j]) - 1, i] = true;
		}
		
		long result = 0;
		for(int i = 0; i < M; i++)
		{
			bool like = true;
			for(int j = 0; j < N; j++)
				like &= flag[i,j];
			
			if(like)
				result++;
		}
			
		Console.WriteLine(result);
	}
}

Measured memory_bytes: 11092
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine

mod' :: Integral a => a -> a
mod' n = if n < 1000000007 then n else n `mod` 1000000007

cnt :: Integer -> Integer -> Integer -> Integer
cnt k inv lt = mod' $ (mod' $ inv*k) + (mod' $ lt*(k*(k-1) `div`2))

main :: IO ()
main = do
  [n',k] <- map read.words <$> getLine :: IO [Integer]
  as <- getIntList
  let n = fromInteger n' :: Int
      vec = (V.fromList as)
      inv = toInteger $ (mod' :: Int -> Int) $ foldl' (\x y -> mod' $ x + y) 0 [if (vec V.! i) > (vec V.! j) then 1 else 0 | i <- [0..n-1], j <- [0..n-1], i < j]
      lt  = mod' $ (+inv) $ toInteger $ (mod' :: Int -> Int) $ foldl' (\x y -> mod' $ x + y) 0 [if (vec V.! i) > (vec V.! j) then 1 else 0 | i <- [0..n-1], j <- [0..n-1], i > j]
  print $ cnt k inv lt


Measured memory_bytes: 1148
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,h,a,b,maxa=0,ans=0,sum=0;
	cin>>n>>h;
	vector<int> bv(n,0);
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (a > maxa) {
			maxa = a;
		}
		bv[i] = b;
	}
	sort(bv.begin(),bv.end());
	for (int i = n-1; i >=0; i--) {
		if (sum >= h) break;
		if (bv[i] > maxa) {
			sum+=bv[i];
			ans++;
		}
	}
	int t=0;
	if (sum < h) {
		t = (h - sum) / maxa;
		if (t*maxa < (h - sum))
			t++;
	}
	ans += t;
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
using namespace std;
int n,tu,lose,back;
int mp[101];
int cnt,ans;
double dp[101][101];


double game(){

  for(int i=0;i<=tu;i++) 
    for(int j=0;j<=n;j++)
     dp[i][j] = 0;

  dp[0][0] = 1;

  for(int i=1;i<=tu;i++) {
    for(int j=0;j<n;j++){
      for(int k=1;k<=6;k++) {
	int ima = j + k;
	if(ima > n) ima = 2*n - ima;

	if(mp[ima] == 1) dp[i+1][ima] += dp[i-1][j]/6;
	else if(mp[ima] == 2) dp[i][0] += dp[i-1][j]/6;
	else dp[i][ima] += dp[i-1][j]/6;	
      }
    }
  }

  double ans = 0;
  for(int i =1;i<=tu;i++) ans += dp[i][n];
  return ans;

}


int main() {

  while(1) {
    cin >> n >> tu >> lose >> back;
    if(n==0 && tu==0 && lose==0 && back==0) break;

    for(int i=0;i<=n;i++) mp[i] = 0;

    int a;
    for(int i=0;i<lose;i++)cin >> a, mp[a] = 1;
    for(int i=0;i<back;i++)cin >> a,mp[a] = 2;

    //   cout << game() << endl;
    printf("%.6f\n",game());
  }
  return 0;
}

 

Measured memory_bytes: 1268
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++){
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        if(b > a){
            cout << "No" << '\n';
            continue;
        }
        if(b > d){
            cout << "No" << '\n';
            continue;
        }
        if(c >= b){
            cout << "Yes" << '\n';
            continue;
        }
        ll g = gcd(b,d);
        if(c < b - g + a%g){
            cout << "No" << '\n';
        }else{
            cout << "Yes" << '\n';
        }
    }
}

Measured memory_bytes: 256