akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 1000000 + 1000;
i64 dp[maxn][2];
char s[maxn];

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
#endif

    cin >> (s + 1);
    int len = strlen(s + 1);
    dp[len + 1][1] = 1;
    for (int i = len; i >= 1; --i) {
        int num = s[i] - '0';
        dp[i][0] = min(dp[i + 1][0] + num, dp[i + 1][1] + num + 1);
        dp[i][1] = min(dp[i + 1][0] + (10 - num), dp[i + 1][1] + (10 - num - 1));
    }
    cout << min(dp[1][0], dp[1][1] + 1) << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
int k;
string s;
int main() {
    cin >> k >> s;

    if ((int)s.size() <= k) {
        cout << s;
    } else {
        for (int i = 0 ; i < k ; ++ i)
            cout << s[i];
        cout << "...";
    }
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3616
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<unordered_map>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int in[1001];
int out[1001];
int findJudge(int x, vector<vector<int>>& arr) {
	int n = arr.size();
	for (int i = 0; i < n; i++)
	{
		in[arr[i][1]]++;
		out[arr[i][0]]++;
    }
	for (int i = 1; i <= x; i++)
		if (in[i] == x - 1 && out[i] == 0)
			return i;
	return -1;

}
int main()
{
	string s, t;
	cin >> s >> t;
	for(int i=0;i<s.size();i++)
		if (s[i] != t[i]) {
			cout << "No";
			return 0;
		}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3628
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n=int(input())
    i = 2
    m = {}
    while i*i <= n:
        while n % i == 0:
            m[i] = m.get(i, 0) + 1
            n //= i
        i += 1
    if n != 1:
        m[n] = m.get(i, 0) + 1
    s = 0
    for v in m.values():
        i = 1
        while i <= v:
            s += 1
            v -= i
            i += 1
    print(s)

main()

Measured memory_bytes: 65836
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    ll x;
    cin >> n >> x;
    vector<ll> X(n + 1), P(n + 1);
    X[0] = 1, P[0] = 1;
    for(int i = 0; i < n; ++i){
        X[i + 1] = X[i] * 2 + 3;
        P[i + 1] = P[i] * 2 + 1;
    }
    ll ans = 0;
    auto dfs = [&](auto&& self, int i, ll N) -> void {
        if(N <= 0)  return;
        if(N == X[i]){
            ans += P[i];
            return;
        }
        ll bound = X[i] >> 1;
        if(N <= bound){
            if(N == bound){
                ans += P[i - 1];
                return;
            }
            --N, --i;
        }
        else{
            ans += P[--i] + 1;
            N -= bound + 1;
        }
        self(self, i, N);
    };
    dfs(dfs, n, x);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size());
#define pb push_back;
#define all(x) (x).begin(),(x).end()
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

const long double PI=3.14159265358979323846;

int main(){
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double p = H + M/60;
    long double k = abs((double)p/6 - (double)M/30)*PI;
    long double m = pow(A,2) + pow(B,2) - 2*A*B*cosl(k);
    long double n = sqrtl(m);
    cout << setprecision(30) << n;
}

Measured memory_bytes: 4152
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <array>
#include <climits>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1000000000 + 7;
const ll INF = LLONG_MAX;
const ll MAX_V = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

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

int main() {
    int n,h,amax = 0,b[100005], cnt = 0;
    cin >> n >> h;
    for(int i=0;i<n;i++){
        int a;
        cin >> a >> b[i];
        amax = max(amax,a);
    }
    sort(b,b+n,greater<int>());
    for(int i=0;i<n;i++){
        if(b[i]<amax)break;
        h -= b[i];
        cnt++;
        if(h<=0){
            cout << cnt << endl;
            return 0;
        }
    }
    cnt += (h-1)/amax+1;
    cout << cnt << endl;
    return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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

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


        ll a, b;
        cin >> a >> b;
        cout << a*b << endl;;


    return 0;
}



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

int get_distance(int a, int b) {
    return pow(a - b, 2.0);
}

int main() {
    int n;
    int x[105];
    int sum = 0;
    int min_dis = 0;
    int min_dis2 = 0;

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

    for(int i = 0; i < n; i++) {
        sum += x[i];
    }

    int avg = sum / n;

    for(int i = 0; i < n; i++) {
        min_dis += get_distance(x[i], avg);
    }

    for(int i = 0; i < n; i++) {
        min_dis2 += get_distance(x[i], avg+1);
    }
    if(min_dis2 < min_dis) {
        min_dis = min_dis2;
    }
    cout << min_dis << endl;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(2)]

ans = 1
law = 10 ** 9 + 7

i = 0
while i < n:
    if s[0][i] == s[1][i]:
        if i == 0:
            ans *= 3
        else:
            ans *= 3 - len({s[0][i-1], s[1][i-1]})
        i += 1
    else:
        if i == 0:
            ans *= 6
        else:
            if s[0][i-1] == s[1][i-1]:
                ans *= 2
            else:
                ans *= 3
        i += 2
    ans %= law
print(ans)

Measured memory_bytes: 3064
#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>
#include<set>
using namespace std;


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


int main() {
	cout << fixed << setprecision(18);

	long long int N,M,K,P[200005],mymin=INF,res=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>P[i];
		if(mymin>=P[i]){res++;mymin=P[i];}
	}
	cout<<res;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MAX 200005
int h[MAX],v[MAX],a[MAX],tree[MAX*4];
void update(int ss, int se, int i, int diff, int si)  
{  
    if (i < ss || i > se)  
        return; 
	if(ss==se) 
    tree[si] = tree[si] + diff;  
    else
    {  
        int mid = (ss+se)/2;  
        update( ss, mid, i, diff, 2*si + 1);  
        update( mid+1, se, i, diff, 2*si + 2);  
        tree[si]=max(tree[2*si+1],tree[2*si+2]);
    }  
}  
int query(int ss, int se, int qs, int qe, int si) 
{ 
	if (ss>se || ss>qe || se<qs) 
		return 0; 
	if (ss>=qs && se<=qe) 
		return tree[si]; 
	int mid = (ss + se)/2; 
	return max(query(ss, mid, qs, qe, 2*si+1) ,
		query(mid+1, se, qs, qe, 2*si+2)); 
}  
signed main()
{
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
	cin>>h[i];
	for(i=0;i<n;i++)
	cin>>v[i];
	int m=0;
	memset(tree,0,sizeof(tree));
	for(i=0;i<n;i++)
	{
		int l=query(0,n,0,h[i]-1,0);
		m=max(l+v[i],m);
		update(0,n,h[i],l+v[i],0);
	}
	cout<<m<<"\n";
}

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

/*-- template --*/

int main() {
    int N, Qn;
    cin >> N >> Qn;
    vector<vector<int>>G(N);
    vector<ll> tree(N, 0);
    vector<bool> visited(N, false);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;--a;--b;
        G[a].pb(b);
        G[b].pb(a);
    }
    rep(i, Qn) {
        ll p, x; cin >> p >> x;
        --p;
        tree[p] += x;
    }
    queue<int>Q;
    Q.push(0);
    visited[0] = true;
    while(!Q.empty()) {
        int q = Q.front();Q.pop();
        for(int next : G[q]) {
            if(!visited[next]) {
                Q.push(next);
                visited[next] = true;
                tree[next] += tree[q];
            }
        }
    }
    rep(i, N) {
        cout << tree[i] << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 16372
#!/usr/bin/env python
# coding: utf-8

# In[7]:


A, B = map(int, input().split())


# In[8]:


def func(A):
    ret = []
    if A % 4 == 1 or A % 4 == 2:
        ret.append(1)
    else:
        ret.append(0)

    m = 4
    while True:
        if A % m  < m // 2:
            ret.append(0)
        elif A % 2 == 0:
            ret.append(1)
        else:
            ret.append(0)
        
        if m > A:
            break
        m *= 2
        
    return ret


# In[9]:


a = func(A - 1)
b = func(B)
a += [0] * (len(b) - len(a))


# In[10]:


ans = ''
for i in range(len(a)):
    ans = str(a[i]^b[i]) + ans


# In[11]:


a, b, ans


# In[12]:


print(int(ans, 2))


# In[ ]:






Measured memory_bytes: 38256
#include<cstdio>
#include<algorithm>
#define maxn 105
using namespace std;
int n,a[maxn],k;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int i;
	for(i=1;i<=n;i++)
	{
		k-=a[i];
		if(k<0) break;
	}
	if(k>0) i--;
	printf("%d\n",i-1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF=1e9+7;
const LL N=100001;
priority_queue<pair<LL,pair<LL,LL> > > Q;
LL n,par[N],a,ans=0;
void init(int n){
	for(LL i=1;i<n+1;i++) par[i]=i;
}
int root(int x){
	if(par[x]==x) return x;
	else return par[x]=root(par[x]);
}
void unite(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y) return;
	par[x]=y;
}
pair<LL,LL> x[N],y[N];
int main(){
	cin>>n;
	init(n);
	for(LL i=0;i<n;i++){
		cin>>x[i].first>>y[i].first;
		x[i].second=i;
		y[i].second=i;
	}
	sort(x,x+n);
	sort(y,y+n);
	for(LL i=0;i<n-1;i++){
		Q.push(make_pair(-(abs(x[i].first-x[i+1].first)),make_pair(x[i].second,x[i+1].second)));
		Q.push(make_pair(-(abs(y[i].first-y[i+1].first)),make_pair(y[i].second,y[i+1].second)));
	}
	while(!Q.empty()){
		pair<LL,LL> e;
		LL cost,xx,yy;
		pair<LL,pair<LL,LL> > q;
		q=Q.top();
		e=q.second;
		cost=-q.first;
		xx=e.first;
		yy=e.second;
		Q.pop();
		if(root(xx)==root(yy))continue;
		unite(xx,yy);
		ans+=cost;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12400
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=505;
char s[N],t[N];
int k,n;

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%s%d",s+1,&k);
	n=strlen(s+1);
	if(k==1){
		ri ans=0;
		rep(i,1,n){
			ri j=i;
			while(j+1<=n&&s[j]==s[j+1]) ++j;
			ri x=j-i+1;x/=2;ans+=x;
			i=j;
		}
		cout<<ans;return 0;
	}
	if(s[1]==s[n]){
		ri y=n;ll ans=0;
		while(y-1&&s[y-1]==s[y]) --y;
		if(y==1){
			ans=1ll*n*k;cout<<(ans/2);
			return 0;
		}
		rep(i,1,n) t[i]=s[i];
		rep(i,n+1,n+n) t[i]=s[i-n];
		rep(i,y,y+n-1){
			ri j=i;
			while(j+1<=y+n-1&&t[j]==t[j+1]) ++j;
			ri x=j-i+1;x/=2;ans+=x;
			i=j;
		}//cout<<y<<' '<<ans<<endl;
		ans*=(k-1);
		rep(i,1,y-1){
			ri j=i;
			while(j+1<=y-1&&s[j]==s[j+1]) ++j;
			ri x=j-i+1;x/=2;ans+=x;
			i=j;
		}
		rep(i,y,n){
			ri j=i;
			while(j+1<=n&&s[j]==s[j+1]) ++j;
			ri x=j-i+1;x/=2;ans+=x;
			i=j;
		}
		cout<<ans;
	}
	else{
		ll ans=0;
		rep(i,1,n){
			ri j=i;
			while(j+1<=n&&s[j]==s[j+1]) ++j;
			ri x=j-i+1;x/=2;ans+=x;
			i=j;
		}
		ans*=k;
		cout<<ans;
	}
	return 0; 
}

Measured memory_bytes: 256
//ABC079C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <numeric>
using namespace std;

int main() {
	string s;
	cin >> s;
	vector<int> a(4);
	for(int i=0;i<4;i++){
		a.at(i) = s.at(i) - '0';
	}
	for(int i=0;i<(1 << 3);i++){
		int sigma = a.at(0);
		bitset<3> s(i);
		for(int j=0;j<3;j++){
			if(s.test(j)){
				sigma += a.at(j+1);
			}else{
				sigma -= a.at(j+1);
			}
		}
		if(sigma == 7){
			cout << a.at(0);
			for(int i=0;i<3;i++){
				if(s.test(i)){
					cout << "+";
				}else{
					cout << "-";
				}
				cout << a.at(i+1);
			}
			cout << "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readString()
	m := make([]rune, 0)
	for _, r := range n {
		x := '1'
		if r == '1' {
			x = '9'
		}
		m = append(m, x)
	}
	println(string(m))
}

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


Measured memory_bytes: 640
program atcoder
    implicit none
    integer(8) :: i,n,a,b,c
    integer(8),allocatable,dimension(:,:) :: dp
    read*,n
    allocate(dp(0:n,0:2))
    dp = 0
    do i = 1,n
        read*,a,b,c
        dp(i,0) = max( dp(i-1,1) , dp(i-1,2) ) + a
        dp(i,1) = max( dp(i-1,0) , dp(i-1,2) ) + b
        dp(i,2) = max( dp(i-1,1) , dp(i-1,0) ) + c
    enddo
    write(*,'(I0)')max(dp(n,0),dp(n,1),dp(n,2))
    stop 
!---------------------------------------
contains

end program atcoder


Measured memory_bytes: 2560
N = int(input())
*A, = map(int, input().split())

def gcd(a,b):
    if a > b: a,b=b,a
    while a: a,b=b%a,a
    return b

L = [0]*(N)
R = [0]*(N)
L[0] = A[0]
R[-1] = A[-1]
for i in range(1,N):
    L[i] = gcd(L[i-1],A[i])
    R[-1-i] = gcd(R[-i],A[-1-i])

ans=R[1]
for i in range(1,N-1):
    ans = max(ans, gcd(L[i-1],R[i+1]))
ans = max(ans, L[N-2])

print(ans)

Measured memory_bytes: 64612
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include<math.h>
#include <algorithm>
#define ll long long
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int main(){
    double d,t,s;
    cin >> d >> t >> s;
    string ans = "No";
    if(d / s <= t) ans = "Yes";
    cout << ans << endl;
}

Measured memory_bytes: 3704
n=int(input())
alist=list(map(int,input().split()))
alist.sort()
nolist=[False]*(10**6+1)
 
counter=0
for i,a in enumerate(alist):
    if not nolist[a]:
        for j in range(10**6 // a):
            nolist[a*(j+1)] = True
 
        if i == n-1:
            counter += 1
        elif alist[i+1] != a:
            counter += 1
print(counter)

Measured memory_bytes: 32228
import java.util.*;




public class Main {


    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int[] a = new int[n+1];
        a[0] = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = cin.nextInt();
        }
        int ans = 0;
        for (int i = 1; i <= 111; i++) {
            for (int j = 1; j <= n; j++) {
                if (a[j - 1] == 0 && a[j] > 0) {
                    ans++;
                }
            }
            for (int j = 1; j <= n; j++) {
                if (a[j]>0) {
                    a[j]--;
                }
            }
        }

        System.out.println(ans);
    }


}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100;
const int mod=1e9+7;

char s1[N],s2[N];
int n;
int f[N];
int cnt;
int main()
{
    scanf("%d",&n);
    scanf("%s",s1+1);
    scanf("%s",s2+1);
    for(int i=1;i<=n;i++){
        if(i+1<=n&&s1[i]==s1[i+1])f[++cnt]=1,i++;
        else{
            f[++cnt]=2;
        }
    }
    ll sum=0;int pre=0;
    if(f[1]==1)sum=6,pre=1;else sum=3,pre=2;
    for(int i=2;i<=cnt;i++){
        if(pre==1&&f[i]==1){
            sum=(sum*3)%mod;
        }else if(pre==1&&f[i]==2){
            sum=sum%mod;
        }else if(pre==2&&f[i]==1){
            sum=(sum*2)%mod;
        }else if(pre==2&&f[i]==2){
            sum=(sum*2)%mod;
        }
        pre=f[i];
    }
    cout<<sum<<endl;
}


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

bool isPrime(int x); 
int gcd(int a, int b); 
vector<int> primeFactorization(int x); 
void printVector(vector<long> list, string str); 
void setPrecision(int n);

int hoge(int count, int num, int div) {
  if (num == 0) return count;

  return hoge(count+1, num/div, div);
}

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

  int result = hoge(0, n, k);

  cout << result << endl;
}

int gcd(int a, int b) {
  if (a%b == 0) {
    return b;
  } else return gcd(b, a%b);
}

bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;

  double num = sqrt(x);
  for (int i = 3; i <= num; i+=2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

// 素因数分解
// example: primeFactorization(12) = vector<int>{2, 2, 3}
vector<int> primeFactorization(int x) {
  vector<int> ans;
  int i = 2;
  while (i*i <= x) {
    if (x % i == 0) {
      ans.push_back(i);
      x /= i;
    } else {
      i++;
    }
  }
  ans.push_back(x);
  return ans;
}

void printVector(vector<long> list, string str) {
  for (int i = 0; i < list.size(); i++) {
    cout << str << ": " << list[i] << endl;
  }
}

void setPrecision(int n) {
  cout << fixed << setprecision(n);
}

Measured memory_bytes: 256
function Main (S) {
  S = S.split("\n")[0].split("");
  var ans = "Yes";
  S.forEach((element, index) => {
    switch ((index+1)%2) {
      case 0:
        switch (element) {
          case "L":
          case "U":
          case "D":
            break;
          default:
            ans = "No";
            break;
                       }
        break;
      case 1:
        switch (element) {
          case "R":
          case "U":
          case "D":
            break;
          default:
            ans = "No"
            break;
         }
                       }
    });
  console.log(ans);
}

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

Measured memory_bytes: 9420
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  string S; cin >> S;
  int ans=0;
  rep(i,N){
    if(i+2>=N) break;
    if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C'){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
fun main() {
    val (x, y) = nextIntList()
    val b = (y - 2 * x).div(2)
    val a = x - b
    println(if (a >= 0 && b >= 0 && 2 * a + 4 * b == y) "Yes" else "No")
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

Measured memory_bytes: 36396
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
string s;
cin >> s;
if(s=="keyence"){cout<<"YES"<<endl; return 0;}
int n = s.size();
for(int i=0;i<n;i++){
  for(int j=i;j<n;j++){
     string t;
    for(int k=0;k<n;k++){
      if(i<=k&&k<=j)continue;
      else t+=s.at(k);
    }
    if(t=="keyence"){cout<<"YES"<<endl; return 0;}
}
}
cout <<"NO"<<endl; return 0;
}







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

int main()
{
    int n;
    scanf("%d", &n);

    long long *a = new long long[n + 1];
    a[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", a + i);
        a[i] += a[i - 1];
    }
    const long long sum = a[n];
    long long min{10000000000000000};
    for (int i = 1; i < n; i++)
    {
        min = std::min(min, std::abs(a[i] - (sum - a[i])));
    }
    printf("%lld\n", min);

    
    delete[] a;
    return 0;
}

Measured memory_bytes: 1792
def calc(x, y, z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

n = int(input())
ans = [0]*n

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = calc(x, y, z)
            if a <= n:
                ans[a-1] += 1

b = [str(i) for i in ans]
print('\n'.join(b))


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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d)
		printf("Yes\n");
	else if(abs(a-b)<=d && abs(b-c)<=d)
		printf("Yes\n");
	else
		printf("No\n"); 
	return 0; 
} 

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>) {
    val N = 1000000
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    val ac = a.groupingBy { it }.eachCount().toSortedMap()
    //println(ac)
    val erato : MutableList<Boolean> = MutableList(N+1) { false }
    var ans = 0
    ac.forEach {
        if (it.value == 1 && !erato[it.key]) ans += 1
        for (i in it.key..N step it.key) erato[i] = true
    }

    println(ans)

}

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

using namespace std;
#define BUF (100005)
#define ll long long 

int n;
int m;


int N;
int p[BUF]; //parentp
int d[BUF]; //depth
int v[BUF];
pair<int,int> pr[BUF];

void uf_init(int n_){
    N=n_;
    for(int i=1;i<=n_;i++) p[i]=i,d[i]=0;
}

int find(int x){
    if(p[x]==x) return x;
    else{
        p[x] = find(p[x]);
        return p[x];
    }
}

void unite(int x, int y){
    x=find(x);
    y=find(y);

    if(x==y)return;

    if(d[x]<d[y]){
        p[x]=y;
    }else if(d[x]>d[y]){
        p[y]=x;
    }else{
        p[y]=x;
        d[x]++;
    }
}

bool same(int x, int y){
    return find(x)==find(y);
}


int main(void){
	cin >> n >> m;
	for(int i=1;i<=n;++i) cin >> v[i];
	for(int i=1;i<=m;++i) cin >> pr[i].first >> pr[i].second;

	uf_init(n);
	for(int i=1;i<=m;++i){
		unite(pr[i].first, pr[i].second);
	}

	int ans = 0;

	for(int i=1;i<=n;++i){
		if(same(i,v[i])) ans++;
	}	

	cout << ans << endl;


	return 0;
}


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

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

  for(int i=0;i<N;i++){
	A.push_back(a[i]);
	for(int j=i+1;j<N;j++){
	  long long t=A[A.size()-1]+a[j];
	  A.push_back(t);
	} 
  }  
  
  long long x=0;
  for(int i=40;i>0;i--){
	int c=0;
	for(int j=0;j<A.size();j++){
	  if(((x+(long long)pow(2,i-1))&A[j])==x+(long long)pow(2,i-1)){
		c++;
	  }
	  if(c>=K){
		x+=pow(2,i-1);
		break;
	  }
	}
  }

  cout << x << endl;

  return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	LL n;
	cin >> n;



	if (n % 2) {
		col(0);
	}
	else {
		LL ans = 0;
		LL n2 = n / 10;
		while (n2 > 0) {
			ans += n2;
			n2 /= 5;
		}
		col(ans);
	}
	
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <limits>

using namespace std;

int N, K;
int x[50], y[50];

int count(int x1, int y1, int x2, int y2) {
	int result = 0;
	for (int i = 0; i < N; i++) {
		if (x1 <= x[i] && x[i] <= x2 && y1 <= y[i] && y[i] <= y2) result++;
	}
	return result;
}

int main(int argc, char *argv[]) {
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}

	long long x1, x2, y1, y2;
	long long ans = numeric_limits<long long>::max();
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			x1 = min(x[i], x[j]);
			x2 = max(x[i], x[j]);
			for (int k = 0; k < N; k++) {
				for (int l = k + 1; l < N; l++) {
					y1 = min(y[k], y[l]);
					y2 = max(y[k], y[l]);

					if (K <= count(x1, y1, x2, y2)) {
						ans = min(ans, (x2 - x1) * (y2 - y1));
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[2002][2002],arr1[2002][2002],arr2[2002][2002],arr3[2002][2002];
char a[2002][2002];
int main()
{
	long long h,w,i,j,k,l,x,y,z,mx;
	cin>>h>>w;
	for (i=0;i<h;i++)
	{
		for (j=0;j<w;j++)
		{
			cin>>a[i][j];
		}	
	}
	for (i=0;i<h;i++)
	{
		x=0;
		for (j=0;j<w;j++)
		{
			if (a[i][j]=='.')
			{
				x++;
				arr[i][j]=x;
			}
			else
			{
				x=0;
			}
		}
	}
	for (i=0;i<h;i++)
	{
		x=0;
		for (j=w-1;j>=0;j--)
		{
			if (a[i][j]=='.')
			{
				x++;
				arr1[i][j]=x;
			}
			else
			{
				x=0;
			}
		}
	}
	for (j=0;j<w;j++)
	{
		x=0;
		for (i=0;i<h;i++)
		{
			if (a[i][j]=='.')
			{
				x++;
				arr2[i][j]=x;
			}
			else
			{
				x=0;
			}
		}
	}
	for (j=0;j<w;j++)
	{
		x=0;
		for (i=h-1;i>=0;i--)
		{
			if (a[i][j]=='.')
			{
				x++;
				arr3[i][j]=x;
			}
			else
			{
				x=0;
			}
		}
	}
	mx=0;
	for (i=0;i<h;i++)
	{
		for (j=0;j<w;j++)
		{
			y=arr[i][j]+arr1[i][j]+arr2[i][j]+arr3[i][j]-3;
			mx=max(mx,y);
		}	
	}
	cout<<mx<<endl;		
}

Measured memory_bytes: 129408
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#define INF 1000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;
 
int main(){
	int n, x;
	cin >> n >> x;
	int a[n];
	REP(i, n) cin >> a[i];
	ll ans = max(0, a[0] - x);
	if(a[0] > x) a[0] = x;
	FOR(i, 1, n){
		if(a[i] + a[i-1] > x){
			ans += a[i] + a[i-1] - x;
			a[i] = x - a[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
    int n;
    cin >> n;
    int x = n%1000;
    if(x != 0)
        cout << 1000 - x << endl;
    else
    {
        cout << 0 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
//i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
//vector <i64> dp;


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

    cin >> n;

    i64 res = 0;
    
    if (n < 600) {
        res = 8;
    }
    else if (n < 800) {
        res = 7;
    }
    else if (n < 1000) {
        res = 6;
    }
    else if (n < 1200) {
        res = 5;
    }
    else if (n < 1400) {
        res = 4;
    }
    else if (n < 1600) {
        res = 3;
    }
    else if (n < 1800) {
        res = 2;
    }
    else if (n < 2000) {
        res = 1;
    }

    cout << res << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

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

ld L;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> L;
	cout << fixed << setprecision(6) << pow(L / 3, 3);
    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: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int p = 0, q = 0, r = 0;
    for(ll b : a){
        if(b%2 != 0){
            p++;
        }
        else if(b%4 == 0){
            q++;
        }
        else{
            r++;
        }
    }
    if(r == 0){
        if(q >= p - 1) puts("Yes");
        else puts("No");
    }
    else{
        if(q >= p) puts("Yes");
        else puts("No");
    }
}

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

#define ll long long

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n, ans = 0;
	cin >> n;
	for (int i=1; i<=n; i++) {
		if (i%3 != 0 && i%5 != 0) ans += i;
	}
	cout << ans;
	return 0;
}


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

const int MAXN = 2e5+2;

int n, to[MAXN<<1], nex[MAXN<<1], fir[MAXN], cur = 0;
int w[MAXN];
void addEdge(int a, int b) {
	to[cur] = b; nex[cur] = fir[a]; fir[a] = cur++;
	to[cur] = a; nex[cur] = fir[b]; fir[b] = cur++;
}
int ans[MAXN];

void getAns(int x, int fa) {
	ans[x] = w[x] + ans[fa];
	for (int i=fir[x]; i!=-1; i=nex[i]) if (to[i] != fa) {
		getAns(to[i], x);
	}
}


int main() {
	int q;
	scanf("%d%d", &n, &q);
	memset(fir, -1, sizeof(fir));

	for (int i=1, a, b; i<n; ++i) {
		scanf("%d%d", &a, &b);
		addEdge(a, b);
	}

	while (q--) {
		int pos, val;
		scanf("%d%d", &pos, &val);
		w[pos] += val;
	}

	getAns(1, 0);
	for (int i=1; i<=n; ++i)
		printf("%d ", ans[i]);

	return 0;
}


Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll prime[1000015];

ll power(ll x , ll y){
	if(y==0)return 1;
	ll ps = power(x,y/2)%mod;
	ll ss = (ps%mod*ps%mod)%mod;
	if(y&1)ss=(ss%mod*x%mod)%mod;
	return ss;
}

void seive(){
 	prime[0]=prime[1]=1;
 	ll n=1000004;
 	for(ll i=2 ; i<=n ;i++){
 		if(prime[i]==0){
 			for(ll j=i*i ; j<=n ;j+=i){
 				prime[j]=i;
 			}
 			prime[i]=i;
 		}
 	}
}

ll lcm(ll* arr , ll n ){
	unordered_map<ll,ll> fmp ;
	for(ll i=0;i<n;i++){
		unordered_map<ll,ll> mp ;
		ll num= arr[i];
		while(num>1){
			ll factor=prime[num];
			mp[factor]++;
			num/=factor;
		}
		for(auto x: mp){
			fmp[x.f]=max(fmp[x.f] , x.s);
		}
	}
	ll ans=1;
	for(auto x:fmp){
		ans = (ans%mod * power(x.f,x.s))%mod;
	}
	return ans ;
}

int main(){
	//mahakal();fast;
	seive();
	ll n ;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)cin>>arr[i];
	ll lc=lcm(arr , n);
	ll ans =0 ;
	// cerr<<lc<<endl;
	for(ll i=0;i<n;i++){
		arr[i]=power(arr[i],mod-2);
		ans += (lc%mod*arr[i]%mod)%mod;
		ans= ans % mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 3005;
const long double PI = acos(-1);

int n,L;
int T[MAXN];

class Point{
public:
	long double x,y;
	
	Point(long double _x = 0,long double _y = 0) : x(_x),y(_y) {}
	
	friend Point operator + (const Point &x,const Point &y){
		return Point(x.x + y.x,x.y + y.y);
	}
	
	friend Point operator - (const Point &x,const Point &y){
		return Point(x.x - y.x,x.y - y.y);
	}
	
	friend Point operator * (const Point &x,const Point &y){
		return Point(x.x * y.x - x.y * y.y,x.x * y.y + x.y * y.x);
	}
	
	friend Point operator * (const Point &x,const long double &y){
		return Point(x.x * y,x.y * y);
	}
	
	friend Point operator / (const Point &x,const long double &y){
		return Point(x.x / y,x.y / y);
	}
	
	long double GetDis(Point p){
		return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
	}
};

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%d",&n,&L);
	for(int i = 1;i <= n;i++)
		scanf("%d",&T[i]);
	long double x = 0,y = 0;
	for(int i = 1;i <= n;i++){
		for(int j = i + 1;j <= n;j++){
			x += (n - 2 * (j - i)) * cos(PI * (T[i] + T[j]) / L);
			y += (n - 2 * (j - i)) * sin(PI * (T[i] + T[j]) / L);
		}
	}
	ll tmp = 1ll * n * (n - 1) * (n - 2) / 6;
	printf("%.10Lf %.10Lf\n",x / tmp,y / tmp);
	return 0;
}



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

int main(){
	long n;
	cin >> n;
	long cnt = 0;
	for (long i = 0; i < n; i++){
		long m;
		cin >> m;
		bool p = 1;
		long o;
		o = sqrt(m);
		for (long j = 0; j < o; j++){
			if (j > 0 && m % (j + 1) == 0){
				p = 0;
			}
		}
		if (p == 1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	string s, t;
	cin >> s >> t;
	vector<map<char, int>> a(s.size());
	for (int i = s.size() - 1; i >= 0; i--) {
		rep(zz, 26) {
			char c = 'a' + zz;
			if (i == s.size() - 1) {
				a[i][c] = -1;
			}
			else {
				if (s[i + 1] == c) {
					a[i][c] = i + 1;
				}
				else {
					a[i][c] = a[i + 1][c];
				}
			}
		}
	}

	map<char, int> a0;
	rep(zz, 26) {
		char c = 'a' + zz;
		if (s[0] == c) {
			a0[c] = 0;
		}
		else {
			a0[c] = a[0][c];
		}
	}

	rep(i, t.size()) {
		if (a0[t[i]] == -1) {
			cout << -1 << endl;
			return 0;
		}
	}

	ll ans0 = 0;
	int ans1 = 0;

	rep(i, t.size()) {
		if (i == 0) {
			ans1 = a0[t[i]];
			continue;
		}
		if (a[ans1][t[i]] != -1) {
			ans1 = a[ans1][t[i]];
		}
		else {
			ans0++;
			ans1 = a0[t[i]];
		}

	}
	cout << s.size() * ans0 + ans1 + 1 << endl;
}



Measured memory_bytes: 127104
#include<cstdio>
#include<algorithm>
typedef long long ll;

template<typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
int main(){
    int pre = 0,ans = 0;
    for(int i = 1;i <= 3; i++){
        char ch = getchar();
        for(;ch != 'R' && ch != 'S'; ch = getchar()) ;
        if(ch == 'R') ans = std::max(ans,pre + 1), pre++;
        else pre = 0;
    }
    printf("%d\n",ans);
    return 0;
}
/*

*/

Measured memory_bytes: 1548
from collections import defaultdict
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
def ls(): return stdin.readline().split()
N = ii()
city_r = defaultdict(list)
for i in range(1, N + 1):
    c, s = ls()
    s = int(s)
    city_r[c].append( (s, i) )
keys = sorted(city_r.keys())
for k in keys:
    vs = city_r[k]
    vs.sort(key=lambda x:-x[0])
    for v in vs:
        print(v[1])


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int n,k,q;
pair<int,int> a[2022];
int b[2022],c[2022],lc,d[2022],ld;
bool f[2022];
int main(){
	scanf("%d%d%d",&n,&k,&q);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i].first);
		a[i].second = i;
		b[i] = a[i].first;
	}
	sort(a,a+n);
	int res = 2000000000;
	for(int i=0; i<n; i++){
		memset(f,0,sizeof(f));
		for(int j=0; j<i; j++)
			f[a[j].second] = true;
		ld = 0;
		for(int j=0; j<=n; j++)if(j==n || f[j]){
			sort(c,c+lc);
			for(int t=0; t<=lc-k; t++){
				d[ld++] = c[t];
			}
			lc = 0;
		}else
			c[lc++] = b[j];
		sort(d,d+ld);
		if(ld >= q)
			res = min(res, d[q-1]-d[0]);
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int k;
  int s;
  scanf("%d %d\n", &k, &s);

  int ans = 0;

  for (auto x = 0; x <= k; x++) {
    for (auto y = 0; y <= k; y++) {
      auto z = s - x - y;
      if (0 <= z && z <= k)
        ans++;
      ;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if (a <= b)cout << a << endl;
    else cout << a - 1 << endl;
    return 0;
}


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

const int w = 6;
const int h = 12;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
const int dd[] = {2, 3, 0, 1};

char m[h][w + 1];
char c[h][w + 1];

void rec_check(int y, int x, char p, int d) {
    if (y < 0 || h <= y || x < 0 || w <= x || c[y][x] > 0) {
        return;
    }

    if (m[y][x] == 'O') {
        c[y][x] = 2;
        return;
    } else if (m[y][x] != p) {
        c[y][x] = 3;
        return;
    }

    c[y][x] = 1;
    for (int i = 0; i < 4; i++) {
        if (i != d) {
            rec_check(y + dy[i], x + dx[i], p, dd[i]);
        }
    }
}


bool clear(int cx, int cy) {
    memset(c, 0, sizeof(c));
    rec_check(cy, cx, m[cy][cx], -1);

    int counter = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (c[y][x] == 1) {
                counter++;
            }
        }
    }
    if (counter < 4) {
        return false;
    }

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (c[y][x] == 1 || c[y][x] == 2) {
                m[y][x] = '.';
            }
        }
    }
    return true;
}

bool run() {
    bool c = false;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (m[y][x] == '.' || m[y][x] == 'O') {
                continue;
            }
            if ((x+1 < w && m[y][x] == m[y][x+1]) || (y+1 < h && m[y][x] == m[y+1][x])) {
                c |= clear(x, y);
            }
        }
    }
    return c;
}

void down() {
    for (int x = 0; x < w; x++) {
        for (int y = h - 1, iy = h - 1; y >= 0; y--) {
            if (m[y][x] != '.') {
                m[iy][x] = m[y][x];
                if (y != iy) {
                    m[y][x] = '.';
                }
                iy--;
            }
        }
    }
}

int main () {
    int t;
    cin >> t;
    while (t--) {
        for (int i = 0; i < h; i++) {
            cin >> m[i];
        }

        int counter = 0;
        while (run()) {
            down();
            counter++;
        }
        cout << counter << endl;
    }
}

Measured memory_bytes: 1164
n,m,q=map(int,input().split())
from itertools import combinations_with_replacement as com
l=[list(map(int,input().split())) for _ in range(q)]
ans=0
for z in com(range(m),n):
    now=0
    for a,b,c,d in l:
        if z[b-1]-z[a-1]==c:
            now+=d
    ans=max(ans,now)
print(ans)


Measured memory_bytes: 67836