akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;


int main() {

    int i=0;
    int N;
    cin >> N;
    int P[N];
    for(int i=0;i<N;i++){
        cin >> P[i];
    }
    int ans=0;
    
   int min=P[0];
   ans++;
   for(int i=1;i<N;i++){
       if(min>P[i]){
           min=P[i];
           ans++;
       }
       
   }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		Scanner cin = new Scanner(System.in);

		int N = cin.nextInt();
		int M = cin.nextInt();

		String large[] = new String[N];
		String small[] = new String[M];
		for(int i=0;i<N;i++){
			large[i] = cin.next();
		}

		for(int j=0;j<M;j++){
			small[j] = cin.next();
		}

		cin.close();
		int count = 0;
		String result = "No";
		for(int k=0;k<N;k++){
			for(int l=0;l<N-M+1;l++){
				if(count<M){
					if(large[k].charAt(l)==small[count].charAt(0)){

						if(large[k].substring(l,l+M).equals(small[count])){
							count++;
							continue;
						}else{
							count = 0;
						}
					}
				}else{
					break;
				}
			}
			if(count==M){
				result = "Yes";
				break;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 24020
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,sse4,avx,avx2")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

mt19937 rnd(time(0));

const int MOD = 1000 * 1000 * 1000 + 7;

LL binpow(LL a, LL n)
{
    LL res = 1;
    while(n)
    {
        if (n & 1)
        {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        n >>= 1;
    }
    return res;
}

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

    LL ans = binpow(10, n);
    ans -= 2 * binpow(9, n);
    while(ans < 0)
    {
        ans += MOD;
    }
    ans += binpow(8, n);
    ans %= MOD;
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

vi mx(1 << 20, 0);

void update(int a, int q) {
	a += 1 << 19;
	mx[a] = max(mx[a], q);
	while ((a /= 2) > 0)mx[a] = max(mx[a * 2], mx[a * 2 + 1]);
}

int query(int l, int r, int sl = 0, int sr = 1 << 19, int a = 1) {

	if (r <= sl || sr <= l)return 0;
	if (l <= sl && sr <= r)return mx[a];
	int sm = (sl + sr) / 2;
	int lmx = query(l, r, sl, sm, a * 2);
	int rmx = query(l, r, sm, sr, a * 2 + 1);
	return max(lmx, rmx);
}


int main() {

	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, n)cin >> a[i];

	rep(i, n) {
		update(a[i], query(max(a[i] - k, 0), a[i] + k + 1) + 1);
	}

	cout << query(1, 300001) << endl;

}

Measured memory_bytes: 8540
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
ans=[]
for i in range(x):
  r.append(p[i])
for i in range(y):
  r.append(q[i])
r.sort(reverse=True)
print(sum(r[0:x+y]))
  



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n; std::cin >> n;
  ll ans = 0;
  rrep(i, n) {
    if (i % 5 != 0 && i % 3 != 0) ans += i;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define v(n) vector<n>
using namespace std;
signed main(){
    int n,m; cin>>n>>m;
    v(int) a(m),b(m);
    v(int) ans(n);
    rep(i,m){
        cin>>a.at(i)>>b.at(i);
        ans.at(a.at(i)-1)++;
        ans.at(b.at(i)-1)++;
    }
    rep(i,n){
        cout<<ans.at(i)<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

#define INFTY 100000000;

int n, m[100][100];

int min( int a, int b )
{
  if( a < b ) return a;
  else return b;
}

void MatrixChainOrder( int *p )
{
  int i, j, l, k;
  long long q;
  
  for( i=1; i<=n; i++ )
    {
      m[i][i] = 0;
    }

  for( l=2; l<=n; l++ )
    {
      for( i=1; i<=n-l+1; i++ )
	{
	  j = i+l-1;
	  m[i][j] = INFTY;

	  for( k=i; k<j; k++ )
	    {
	      q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	      m[i][j] = min(m[i][j],q);
	    }
	}
    }
}


int main()
{
  int i;
  
  scanf("%d", &n);
  int p[n];

  for( i=1; i<=n; i++ )
    {
      scanf("%d%d", &p[i-1], &p[i]);
    }

  MatrixChainOrder(p);

  printf("%d\n", m[1][n]);

  return 0;
}

  



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

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

constexpr int INF = 2000000000;
constexpr ll LLINF = 9000000000000000000;

constexpr ll MOD = 1e9+7;
ll fac(ll n) {
	ll r = 1LL;
	for (ll i = 2LL; i <= n; ++i)
		r = (r * i) % MOD;
	return r;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m;
	cin >> n >> m;
	
	if (abs(n - m) > 1) {
		cout << 0 << endl;
		return 0;
	} else {
		ll v = fac(n) * fac(m) % MOD;
		if (n == m) v = (v * 2LL) % MOD;
		cout << v << endl;
	}
	
	return 0;
}


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

using namespace std;

#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<int> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int str_length, question_num;
    vi accumulation_ac_count_by_postion_of_str(10e5 + 1, 0);
    string str;
    cin >> str_length >> question_num >> str;
    vi answer(question_num, 0);

    int accumulation_ac_count = 0;
    for (int i = 0; i < str_length; ++i) {
        accumulation_ac_count_by_postion_of_str[i] = accumulation_ac_count;
        if (i < str_length - 1 && str[i] == 'A' && str[i + 1] == 'C') accumulation_ac_count++;
    }

    for (int i = 0; i < question_num; ++i) {
        int left, right;
        cin >> left >> right;
        left--;
        right--;

        answer[i] = accumulation_ac_count_by_postion_of_str[right] - accumulation_ac_count_by_postion_of_str[left];
    }

    for (auto ans: answer) {
        cout << ans << endl;
    }
}

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

int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	long long int total = 0;
	cin>>n>>k;
	vector<int> health(n);
	for (int i = 0; i < n; i++) {
		cin>>health[i];
	}
	sort(health.begin(), health.end());
	while(k-- && !health.empty()){
		health.pop_back();
	}
	for(int num : health){
		total += num;
	}
	cout<<total<<'\n';
	return 0;
}

Measured memory_bytes: 1024
// in the name of GOD
#include <bits/stdc++.h>
#define  S second
#define  F first
#define pb push_back
#define sz(cp) 1LL*cp.size()
#define tm are_you_now_tm_is_define_?
#define ta(c) c-'a'+1 
//#define int long long
using namespace std;
typedef long long ll ;
typedef long double ld ;
typedef pair < ll , ll > pii ;
const int maxn = 410 , maxm = 1e5 + 10 ;
int a[maxm] , b[maxm] , n , m , ans ;
bool alive[maxn] ;
bitset<maxn> A[maxn] , he1 , he2 , tohi ;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m ;
	for(int y = 1 ; y <= m ; y++){
		cin >> a[y] >> b[y] ; a[y] -- , b[y] -- ;
		he1 = A[a[y]]|A[b[y]] ;
		he2 = A[a[y]]&A[b[y]] ;
		if(!(alive[a[y]]|alive[b[y]]|he2.count()|he1[a[y]]|he1[b[y]]))
		A[a[y]] = he1 , A[a[y]][b[y]] = 1 ;
		else
		alive[a[y]] = 1 ;
		swap(a[y],b[y]) ;
		if(!(alive[a[y]]|alive[b[y]]|he2.count()|he1[a[y]]|he1[b[y]]))
		A[a[y]] = he1 , A[a[y]][b[y]] = 1 ;
		else
		alive[a[y]] = 1 ;
	}
	for(int y = 0 ; y < n ; y++)
	for(int x = 0 ; x < y ; x++)
	if(alive[y]+alive[x]+(A[y]&A[x]).count()+A[y][x]+A[x][y]==0)
	ans ++ ;
	cout << ans ;
	return 0 ;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000

#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<pair<ll,ll>>vec;
vector<ll>za;
ll ans;
ll mnx=1e18,mxx=-1e18,mny=1e18,mxy=-1e18;
struct RMQ{
	#define s (1<<19)
	ll seg[s];
	void init(){ fill(seg,seg+s,-1e18); }
	void update(int k,ll a){
		k+=s/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	ll query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return -1e18;
		if(a<=l && r<=b) return seg[k];
		else{
			ll vl=query(a,b,k*2+1,l,(l+r)/2);
			ll vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return max(vl,vr);
		}
	}
}kaede[2][2];
int main(){
	scanf("%d",&n);
	repn(i,n){
	    ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x > y) swap(x,y);
		vec.pb(mp(x,y));
		za.pb(x); za.pb(y);
		mnx = min(mnx,x); mxx = max(mxx,x);
		mny = min(mny,y); mxy = max(mxy,y);
	}
	ans = (mxx-mnx) * (mxy-mny);
	rep(a,2)rep(b,2) kaede[a][b].init();
	sort(vec.begin(),vec.end());
	rep(i,vec.size()){
		kaede[0][0].update(i,vec[i].fi);
		kaede[0][1].update(i,-vec[i].fi);
		kaede[1][0].update(i,vec[i].sc);
		kaede[1][1].update(i,-vec[i].sc);
	}
	SORT(za); ERASE(za);
	int id = POSL(za,mny);
	
	for(int i=0;i<za.size();i++){
		int pos = POSL(vec,mp(za[i],-1ll));
		//[0,pos) -> max
		//[pos,n) -> min
		ll MX = kaede[1][0].query(0,pos-1,0,0,s/2-1);
		MX = max(MX,kaede[0][0].query(pos,n-1,0,0,s/2-1));
		ll MN = kaede[1][1].query(0,pos-1,0,0,s/2-1);
		MN = max(MN,kaede[0][1].query(pos,n-1,0,0,s/2-1));
		ll val = MX+MN;
		//cout << mxy << " " << mnx << endl;
		ans = min(ans, (mxy-mnx) * val);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 24924
#include <stdio.h>

int n, m, d, p, r[11];

int main()
{
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
        
        if(n == 0 && m == 0) { break; }
        
        for(int i = 0; i < 11; i++)
        {
            r[i] = 0;
        }
        
        while(n--)
        {
            scanf("%d", &d);
            scanf("%d", &p);
            
            r[p] += d;
        }
        
        for(int i = 10; i >= 0; i--)
        {
            if(m >= r[i])
            {
                m -= r[i];
                
                r[i] = 0;
            }
            else
            {
                r[i] -= m;
                
                break;
            }
        }
        
        int sum = 0;
        
        for(int i = 0; i <= 10; i++)
        {
            sum += i * r[i];
        }
        
        printf("%d\n", sum);
    }
    
    return 0;
}

Measured memory_bytes: 2564
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const int Nmax=2e5+1;
const int Nd=61;
const int INF=1e5;


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

  rep(i,n){
    if(i==0){
      ans=k;
    }else{
      ans*=(k-1);
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    int a;cin >>a;
    cout << a + (a*a) +(a*a*a);
}

Measured memory_bytes: 3616
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = INT()
if s == 10**18:
    print(0,0,10**9,0,0,10**9)
elif s <= 10**9:
    print(0,0,1,0,0,s)
else:
    x = s // 10**9 + 1
    y = s % 10**9
    print(1,0,x,y,0,10**9)

Measured memory_bytes: 10236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int cntR = 0, cntL = 0, b = 0;
    int n = s.size();
    int ans[n] = {};
    s.push_back('R');
    rep(i, 0, n + 1) {
        if (s[i] == 'R') {
            cntR++;
            if (s[i + 1] == 'L') {
                b = i;
            }
        }
        if (s[i] == 'L') {
            cntL++;
            if (s[i + 1] == 'R') {
                if (cntR == 1 && cntL == 1) {
                    ans[b] = ans[b + 1] = 1;
                } else if ((cntR + cntL) % 2 == 0) {
                    ans[b] = ans[b + 1] = (cntR + cntL) / 2;
                } else {
                    if (max(cntR, cntL) == cntR) {
                        if (cntR % 2 == 0) {
                            ans[b] = (cntR + cntL) / 2;
                            ans[b + 1] = cntR + cntL - (cntR + cntL) / 2;
                        } else {
                            ans[b] = cntR + cntL - (cntR + cntL) / 2;
                            ans[b + 1] = (cntR + cntL) / 2;
                        }
                    } else {
                        if (cntL % 2 == 0) {
                            ans[b] = cntR + cntL - (cntR + cntL) / 2;
                            ans[b + 1] = (cntR + cntL) / 2;
                        } else {
                            ans[b] = (cntR + cntL) / 2;
                            ans[b + 1] = cntR + cntL - (cntR + cntL) / 2;
                        }
                    }
                }
                cntR = cntL = 0;
            }
        }
    }
    rep(i, 0, n) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    double pi=3.14159;

double r;cin>>r;
cout<<2*pi*r<<endl;
}


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

using namespace std;

int const maxn = 2005;
int a[maxn], b[maxn], inf = 1e9 + 1, n;

inline int ok(int x, int y, int k, int q) {
    int cnt = 0, go = 0, good = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] < x) {
            cnt += max(0, min(good, go - k + 1));
            go = 0, good = 0;
        }
        else {
            go++;
            if (a[i] <= y) good++;
        }
    }
    cnt += max(0, min(good, go - k + 1));
    return cnt >= q;
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k, q, ans = inf;
    cin >> n >> k >> q;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    int i = 1, j = 1;
    while (i <= n) {
        while (j <= n && !ok(b[i], b[j], k, q)) ++j;
        if (j <= n) ans = min(ans, b[j] - b[i]);
        ++i;
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int[] ary = new int[n];
        for(int i = 0; i < n; i++)  ary[i] = Integer.parseInt(line1[i]);
        Arrays.sort(ary);
        int count = 0;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                for(int k = j + 1; k < n; k++){
                    if(ary[i] < ary[j] + ary[k] && ary[j] < ary[i] + ary[k] && ary[k] < ary[i] + ary[j])    count++;
                    else    break;
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23764
using System;

namespace Application
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			for(int i=1; i<10; i++) {
				for(int j=1; j<10; j++) {
					Console.WriteLine ("{0}x{1}={2}",i,j,i*j);
				}
			}
		}
	}
}


Measured memory_bytes: 5592
#include<iostream>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  int cnt=1;
  while(cnt>0) {
    if(N<1) {
      cout << cnt-1 << endl;
      cnt = 0;
    }
    else {
      N /= K;
      cnt++;
    }
  }
}

Measured memory_bytes: 256
n,t = map(int,input().split())
cost = []
time = []
ncost = []
f = 0
e = 0
for i in range(n):
    c,T = input().split()
    cost.append(int(c))
    time.append(int(T))

for i in time:
    if i > t:
        e += 1
    
if e == n:
    print('TLE')
    
for i in range(n):
    if time[i] <= t:
        ncost.append(cost[i])
        f = 1
    else:
        pass
if  f == 1:
    print(min(ncost))
    


Measured memory_bytes: 3064
#!/usr/bin/env python3

def main():
    n = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    dist = [abs(a[i] - a[i - 1]) for i in range(1, n + 2)]
    total = sum(dist)
    ans = [0] * n
    for i in range(n):
        ans[i] = total - dist[i] - dist[i + 1] + abs(a[i] - a[i + 2])
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()


Measured memory_bytes: 22108
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = 2*(a + b);
    System.out.println(area + " " + length);
    sc.close();
  }
}


Measured memory_bytes: 26184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int n,m;
	cin >> n >> m;
	ll a[100000];
	for(int i=0;i<n;i++) cin >> a[i];

	sort(a,a+n);

	ll sum[100001];
	sum[0] = 0;
	for (int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i-1];

	vector<P> cards;
	for(int i=0;i<m;i++){
		int b;
		ll c;
		cin >> b >> c;
		cards.push_back(make_pair(c,b));
	}
	sort(cards.begin(),cards.end());
	reverse(cards.begin(), cards.end());

		int k = 0;
	for(int i=0;i<m;i++){
		ll key = cards[i].first;
		int sec = cards[i].second;
		int num = lower_bound(a+k, a+n, key) - (a+k);
		//cout << sec << ' ' <<  num << endl; 
		if(num > 0){
			int m = min(num,sec);
			for(int j=0;j<m;j++){
				if(k+j<n) a[k+j] = key;
			}
			k += m;
			//sort(a, a + num);
		}
	}

	ll ans = 0;
	for(int i=0;i<n;i++) ans += a[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

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

    vector<ll> vec(N+1,0);
    ll tmp=0;
    for(int i=0; i<N; i++){
        ll x;
        cin >> x;
        x++;
        tmp=max(tmp,i+1-(x-(x/2+x%2)));
        vec[i+1]=max(0LL,tmp);
    }
    vec[N]=MOD;

    ll ans=1;
    int h=0;
    ll cnt=0;
    for(int i=0; i<N; i++){
        while(vec[h]<=i){
            h++;
            cnt++;
        }

        ans*=cnt;
        ans%=MOD;
        cnt--;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    ll n,i,j,k;
    vi a,b;

    cin>>n;
    SIZE(a,n+1);
    SIZE(b,n);
    rep(i,n+1){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    k=0;
    rep(i,n){
        j=min(a[i],b[i]);
        k+=j;
        b[i]-=j;
        j=min(a[i+1],b[i]);
        k+=j;
        a[i+1]-=j;
    }
    cout<<k;
    
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define MOD 1000000007

int min(int a, int b) {
    return a<b?a:b;
}

int max(int a, int b) {
    return a>b?a:b;
}

int compare(const void* a, const void* b) {
    return (*(int*)a - *(int*)b);
}

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

int main() {
    int n, i, j, k;
    long long int sum = 0;
    if(scanf("%d", &n)) {
        for(i=1;i<=n;i++) {
            for(j=1;j<=n;j++) {
                for(k=1;k<=n;k++) {
                    if(i == 1 || j == 1 || k == 1)
                        sum += 1;
                    else
                        sum += gcd(i, gcd(j, k));
                }
            }
        }
        printf("%lld", sum);
    }
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#define N 100009
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f;
 
LL h[N];
LL n, a, b;
 
bool judge(LL mid)
{
    LL ans = mid;
    for(int i = 1; i <= n; i++)
    {
        LL tm = h[i] - b*mid;
        if(tm > 0)
        {
            LL cnt = tm / (a - b) + (tm % (a - b) == 0 ? 0 : 1);
            ans -= cnt;
            if(ans < 0) return false;
        }
    }
    return true;
}
 
int main()
{
    scanf("%lld%lld%lld", &n, &a, &b);
    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    LL l = 0, r = INF;
    LL ans = INF;
    while(l <= r)
    {
        LL mid = (l + r)>>1;
        if(judge(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
x,n = gets.chomp.split(" ").map(&:to_i);
line = gets.chomp.split(" ").map(&:to_i);


class Array

  # 配列どうしの「差分」を求めるメソッド。
  # [1,2,2,3].diff([2,3,4]) => [1,2] 
  def diff(ary)
    temp = self.dup # selfの破壊を防ぐため。
    ary.each do |val|
      idx = temp.index(val)
      next if idx == nil # ary2の要素がary1にないときはパス。
      temp.delete_at(idx)
     end
     temp
  end

end

zeroto101line = [*0..101]

forbiddenline = zeroto101line.diff(line)



d = 100
answer = x

for i in 0..(forbiddenline.length-1) do
	if (x - forbiddenline[i]).abs < d  then
		d = (x - forbiddenline[i]).abs
		answer = forbiddenline[i]
	end
end

puts answer


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

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

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
const int dr[]={0,1,0,-1,0};


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	
	cin >> s;
	bool ok=1;
	if(s[0] !='A') ok=0;
	int ct=0, n=sz(s);
	rep(i, n) if(s[i]=='B'|| (s[i]>='D' && s[i]<='Z')) ok=0;
	
	rep(i, n) if(s[i]=='A') ct++;
	if(ct !=1) ok=0;
	ct=0;
	rep(i, n) if(s[i]=='C') ct++;
	if(ct !=1) ok=0;
	ct=0;
	rep2(i, 2, n-1) if(s[i]=='C') ct++;
	if(ct !=1) ok=0;
	if(n < 4) ok=0;
	//dbg(ct);
	puts(ok? "AC":"WA");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    vector<ll> v(n);
    REP(i,n)cin>>v[i];
    ll cnt_sum=0;
    vector<ll> w(n);
    REP(i,n)if(v[i]==i+1)w[i]=1;
    REP(i,n){
        if(w[i]==1){
            ll cnt=1;
            while(i<n){
                i++;
                if(w[i]==1){
                    cnt++;
                }else{
                    break;
                }
            }
            cnt_sum+=ceil((ld)cnt/2.0);
        }
    }
    cout<<cnt_sum<<endl;
    return 0;
}


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

int main(){
    int n,m; cin >> n >> m;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    sort(all(a));
    reverse(all(a));
    double ju=(double)1/(4*m);
    if(a[m-1]<sum*ju) cout << "No" << endl;
    else cout << "Yes" << endl;
return 0;
}


Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string a, b, c; cin >> a >> b >> c;
	if (a.back() == b[0] && b.back() == c[0])cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[i]>=b[i]:
    ans+=b[i]
  else:
    ans+=a[i]
    ans+=min(b[i]-a[i],a[i+1])
    a[i+1]=max(0,a[i+1]-b[i]+a[i])
print(ans)

Measured memory_bytes: 18476
using System;
using System.IO;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        char[] cs = s.Distinct().ToArray();
        int min = int.MaxValue;
        foreach (var c in cs)
        {
            char[] vs = s.ToArray();
            int count = 0;
            while (vs.Distinct().Count() != 1)
            {
                char[] newv = new char[vs.Length - 1];
                for (int i = 0; i < newv.Length; i++)
                {
                    if (vs[i] == c || vs[i + 1] == c) newv[i] = c;
                    else newv[i] = vs[i];
                }
                vs = newv;
                Debug.WriteLine(string.Join(" ",vs));
                count++;
            }
            min = Min(min, count);
        }
            Console.WriteLine(min);
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int a[maxn],b[maxn];
struct cnm{
	int x,y,c;
};
cnm kou[maxn];

int main(){
	int A,B,M;
	cin>>A>>B>>M;
	int mina=1000000,minb=1000000;
	for(int i=1;i<=A;i++){
		scanf("%d",&a[i]);
		mina=min(mina,a[i]);
	}
	for(int i=1;i<=B;i++){
		scanf("%d",&b[i]);
		minb=min(minb,b[i]);
	}
	for(int i=1;i<=M;i++){
		scanf("%d%d%d",&kou[i].x,&kou[i].y,&kou[i].c);
	}
	int ans=mina+minb;
	for(int i=1;i<=M;i++){
		if(a[kou[i].x]+b[kou[i].y]-kou[i].c<ans){
			ans=a[kou[i].x]+b[kou[i].y]-kou[i].c;
		}
	}
	cout<<ans;
	return 0;
}















Measured memory_bytes: 2176
import sys
input = sys.stdin.readline
a,b,c,d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
list = [a,b,c,d]
if 1 in list and 9 in list and 7 in list and 4 in list:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
program main
  implicit none
  integer(8) :: H,W,out
  integer(8) :: a,b, i,j

  read(*,*) H,W
  if (H == 1 .or. W == 1) then
     write(*,'(i0)') 1
     stop
  end if
  if (mod(W,2) == 0) then
     a = W/2
     b = W/2
  else
     a = W/2 + 1
     b = W/2
  end if
  out = 0
  if ( mod(H,2) == 0 ) then
     out = H/2*a + H/2*b
  else
     out = (H/2+1)*a + H/2*b
  end if
  write(*,'(i0)') out 
end program main

Measured memory_bytes: 768
main =do
  [n,y]<-map read.words<$>getLine
  putStr.unwords.map show.head$[[a,b,c]|a<-[0..n],b<-[0..n-a],let c=n-a-b,(a*10+b*5+c)*1000==y]++[[-1,-1,-1]]


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

int main() {
  while(1){
    int n;
    cin >> n;
    if (n == 0) break;

    int A[1000]={0};
    int sum = 0;

    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < n; i++) sum += A[i];
    double avg = 1.0*sum/n;
    double dist = 0.0;
    for (int i = 0;  i < n; i++) {
      dist += (avg - A[i])*(avg - A[i]);
    }
    printf("%.8f\n", sqrt(dist/n));
  }
  return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<mint> dp(s+1);
    mint ans = 0;
    rep(i, n) {
        vector<mint> nxt(s+1);
        dp[0] += 1;
        rep(j, s+1) {
            nxt[j] += dp[j];
            if (j+a[i] <= s) nxt[j+a[i]] += dp[j];
        }
        swap(nxt, dp);
        ans += dp[s];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int n=s.size();
  int ok=0;
  for(int i=0; i<n; i++)
  {
    int j=n-i-1;
    if((s[i]=='q'&&s[j]=='p')||(s[i]=='b'&&s[j]=='d') ||(s[i]=='d'&&s[j]=='b')||(s[i]=='p'&&s[j]=='q')) {continue;}
    ok=1;
  }
  if(ok==0)
  {
    cout<<"Yes"<<endl;
    return 0;
  }
  ok=0;
  for(int i=0; i<n; i++)
  {
    if(s[i]=='p')s[i]=='q';
    if(s[i]=='q')s[i]=='p';
    if(s[i]=='b')s[i]=='d';
    if(s[i]=='d')s[i]=='b';
  }
  for(int i=0; i<n; i++)
  {
    int j=n-i-1;
    if((s[i]=='q'&&s[j]=='p')||(s[i]=='b'&&s[j]=='d') ||(s[i]=='d'&&s[j]=='b')||(s[i]=='p'&&s[j]=='q')) {continue;}
    ok=1;
  }
  if(ok==0)cout<<"Yes"<<endl;
  else cout<<"No";
  return 0;
}


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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    int n;
    cin >> n;
    for(int i = 1; i < 10; ++i)
        for(int j = 1; j < 10; ++j)
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No" << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
L = [input() for _ in range(H)]

inf = 10**9 + 7
dp = [[inf] * W for _ in range(H)]
if (L[0][0] == '.'):
    dp[0][0] = 0
else:
    dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if (i == 0 and j == 0):
            continue
        a = dp[i][j - 1]
        b = dp[i - 1][j]
        if (L[i - 1][j] == '.' and L[i][j] == '#'):
            b += 1
        if (L[i][j - 1] == '.' and L[i][j] == '#'):
            a += 1
        dp[i][j] = min(dp[i][j], a, b)

print(dp[-1][-1])

Measured memory_bytes: 9284
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int> v, c;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int value;
		cin >> value;
		v.push_back(value);
	}
	for (int i = 0; i < N; i++) {
		int cost;
		cin >> cost;
		c.push_back(cost);
	}
	for (int i = 0; i < N; i++) {
		if ((v[i]-c[i]) > 0) {
			sum += v[i]-c[i];
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    int d,n;
    long ans=1;
    cin>>d>>n;

    for(int i=0;i<d;i++){
        ans*=100;
    }
    ans*=n;
    // int enu=n;
    // int plus=0;
    // while(enu>=100){
    //     enu/=100;
    //     plus++;
    // }
    // if(d==0){
    //     ans+=n/100;
    // }else if(d==1){
    //     ans+~
    // }else{

    // }
    // if(n==100){

    // }
    int plus=n/100;
    if(plus){
        if(d==0){
            ans+=1;
        }else if(d==1){
            ans+=100;
        }else if(d==2){
            ans+=10000;
        }
    }
    // ans+=n/100
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    ll n,k;
    cin>>n>>k;
    ll p[n],c[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
    }
    for(int i=0;i<n;i++)cin>>c[i];
    vector<vector<ll>> c_sum(n);
    ll ans=-1001001001001001;
    for(ll i=0;i<n;i++){
        ll j=-1;
        bool flag=true;
        while(flag){
            if(j==i)flag=false;
            ll v=0;
            if(j!=-1)v=c_sum[i].back();
            if(j==-1)j=p[i];
            c_sum[i].emplace_back(v+c[j]);
            j=p[j];
        }
        ll sz=c_sum[i].size();
        ll cnt=-1001001001001001;
        if(k<=sz){
            for(int l=0;l<k;l++){
                cnt=max(cnt,c_sum[i][l]);
            }
        }else{
            for(auto x:c_sum[i]){
                cnt=max(cnt,x);
            }
            ll t1=k/sz,t2=t1-1;
            ll d1=k%sz;
            ll v1=t1*c_sum[i].back(),v2=t2*c_sum[i].back();
            for(int l=0;l<d1;l++){
                cnt=max(cnt,v1+c_sum[i][l]);
            }
            for(auto x:c_sum[i]){
                cnt=max(cnt,v2+x);
            }
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 218784
#include<bits/stdc++.h> 
using namespace std;
using ll = long long;
 
double func2( double n ){ 
  return n*(n+1)/2;
}
 
double func( double n ){ //ダイスの期待値を返す
  return func2(n)/n;
}
 
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  vector<double> exp(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<n;i++){
    exp.at(i) = func(p.at(i));
  }
  
  double ans = 0,sum=0;
  for(int i=0;i<=n-k;i++){
    if( i == 0 ){
      for(int j=0;j<k;j++){
        sum += exp.at(j);     
      }
    }else{
      sum = sum - exp.at(i-1) + exp.at(i+k-1);
    }
    if( sum > ans){
      ans = sum;
    }
  }
  
  printf("%.10f\n",ans);
      
  return 0;
}

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a > c){
		swap(a,c);
		swap(b,d);
	}
	if(b - c < 0){
		cout << 0 << endl;
		return 0;
	}
	if(d < b && a < c){
		cout << d-c << endl;
		return 0;
	}
	cout << b - c << endl;
}

Measured memory_bytes: 256
n=int(input())
b=[0]*n
f=[0]*n
r=[0]*n
v=[0]*n
for i in range(0,n):
    b[i],f[i],r[i],v[i]=(int(x) for x in input().split())
for i in range(1,5):
    for j in range(1,4):
        for k in range(1,11):
            sum=0
            for l in range(n):
                if b[l]==i and f[l]==j and r[l]==k:
                    sum+=v[l]
            if k!=10:
                print(" %d"%sum,end="")
            else:
                print(" %d"%sum)
    if i!=4:
        print("#"*20)


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

vector<int> a;
vector<int> b;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    a.push_back(c);
    b.push_back(c);
  }

  auto max_it = std::max_element(a.begin(), a.end());
  int m = *max_it;
  int max_count = std::count(a.begin(), a.end(), m);

  sort(b.begin(), b.end());
  b.pop_back();
  auto second_it = std::max_element(b.begin(), b.end());
  int second = *second_it;
  
  for (int i = 0; i < n; i++) {
    if (a[i] != m) {
      cout << m << endl;
    } else {
      if (max_count > 1) {
        cout << m << endl;
      } else {
        cout << second << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
const int MAX = 1000001; 

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int k;
    cin>>k;
    int x=7%k;
    for(int i=1;i<=1e6;i++)
    {
        if(x==0)
        {
            print(i)
            return 0;
        }
        x=(x*10+7)%k;
        
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  if(a==b&&a==c)ans=1;
  else if(a==b&&a!=c)ans=2;
  else if(b==c&&b!=a)ans=2;
  else if(c==a&&c!=b)ans=2;
  else ans=3;
  cout<<ans<<endl;
    
    
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    char c; bool ok=true;
    for (int i=0; i<n; i++)
    {
        cin>>c;
        if (c=='Y') ok=false;
    }
    if (ok) cout<<"Three";
    else cout<<"Four";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  while (1) {
    string x;
    cin >> x;
    if (x == "0") break;
    int sum = 0;
    for (int i = 0; i < x.size(); i++) {
      sum += x.at(i) - '0';
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);

    int n;
    cin>>n;
    ll arr[n+5];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    ll m=1e18;
    if(arr[0]==0)
        cout<<"0"<<endl;
    else
    {
        ll ans=1;
        for(int i=0;i<n;i++){
            if(arr[i]<=m/ans)
                ans*=arr[i];
            else{
                cout<<"-1"<<endl;
                return 0;
            }

        }
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 4420
import collections

while True :

    a=[]
    n=int(input())

    if n==0 :
        break

    for i in range (n) :
        x=int(input())
        a.append(x)

    a.sort()

    c = collections.Counter(a)


    for i in range(10):
        if c[i] == 0: 
            print('-')
        else: 
            print('*'*c[i])


Measured memory_bytes: 6108
from collections import deque
n,m = map(int,input().split())
to = [[] for _ in range(n)]
v = []
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    v.append((a,b))
ans = m
seen = [False]*n
q = deque()
for i in range(m):
    a,b = v[i]
    q.clear()
    q.append((a,-1))
    for j in range(n): seen[j] = False
    flag = True
    while q and flag:
        cur,prev = q.popleft()
        seen[cur] = True
        for nxt in to[cur]:
            if nxt == b:
                if cur == a: continue
                ans -= 1
                flag = False
                break
            if nxt == prev: continue
            if seen[nxt]: continue
            q.append((nxt,cur))
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int gcd(int x, int y) {
	if (y % x == 0) return x;
	else return gcd(y % x, x);
}

int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	cout << ans << endl;
}


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

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

}




Measured memory_bytes: 3544
import numpy as np
import sys

N = int(input())

A = []
B = []
for i in range(N):
    a1, b1 = map(int, input().split())
    A.append(a1)
    B.append(b1)
    
b = np.argsort(B)

aa = [0] * N
bb = [0] * N
for i in range(N):
    aa[i] = A[b[i]]
    bb[i] = B[b[i]]

wt = 0
for i in range(N):
    l = bb[i]
    wt += aa[i]
    if wt > l:
        print("No")
        sys.exit()
        
print("Yes")
    

    

Measured memory_bytes: 31104