akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
a=list(map(int,input().split()))

count=sum(a)
a=sorted(a,reverse=True)
sum=0
for i in range(m):
	sum += a[i]

for i in range(m):
	if(a[i]*4*m < count):
		print("No")
		break
else:
	print("Yes")

Measured memory_bytes: 9124
kt = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

a.sort!
a.reverse!

if kt[1] > 2
 k = a[0] - 1 - a[1..-1].inject(:+)
 k = 0 if k<0 
 p k
else
p a[0]-1
end



Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAXN = 128;

char u[MAXN];
char v[MAXN];

int main() {
    string s,t; cin>>s>>t;
    for(int i = 0; i < s.size(); ++i) {
        u[i] = s[i];
    }
    u[s.size()] = '\0';
    for(int i = 0; i < t.size(); ++i) {
        v[i] = t[i];
    }
    v[t.size()] = '\0';

    sort(u, u + s.size());
    sort(v, v + t.size(), greater<char>());

    if(strcmp(u, v) < 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N, K;
    cin >> N >> K;

    if(K==1){
        p(0);
        return 0;
    }

    N-=K;
    p(N);
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

const int mod = (int)1e9 + 7;

int main(){
	bool p[1001];
	for(int i = 0; i <= 1000; i++){
		p[i] = true;
	}
	int n;
	scanf("%d", &n);
	for(int i = 2; i <= n; i++){
		if(p[i]){
			for(int j = i * 2; j <= n; j += i){
				p[j] = false;
			}
		}
	}
	vector<int> c(n + 1);
	for(int i = 2; i <= n; i++){
		if(p[i]){
			c[i] += n / i;
			for(int j = i * i; j <= n; j *= i){
				c[i] += n / j;
			}
		}
	}
	long long ans = 1;
	for(int i = 2; i <= n; i++){
		if(p[i]){
			ans *= (c[i] + 1);
			ans %= mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(void){
	int n;
	double v[101][2];
	double s[2];
	int ans;

	while(1){
		s[0] = 100000;
		scanf("%d", &n);
		if(n == 0) break;
		ans = n;

		for(int i=0; i<n; i++){
			scanf("%lf,%lf", &v[i][0], &v[i][1]);
			if(s[0] > v[i][0]){
				s[0] = v[i][0];
				s[1] = v[i][1];
			}else if(s[0] == v[i][0] && s[1] < v[i][1]){
				s[1] = v[i][1];
			}
		}

		double t[2];
		t[0] = s[0];
		t[1] = s[1];
		double next[2];
		double bias = -M_PI/2.0;
		double min;
		double theta;
		do{
			min = 2*M_PI;
			for(int i=0; i<n; i++){
				if(v[i][0] == -10000 || v[i][1] == -10000) continue;
				if(v[i][0] == t[0] && v[i][1] == t[1]) continue;
				if(t[0] == v[i][0]){
					if(t[1] < v[i][1]) theta = M_PI/2;
					else if(t[1] > v[i][1]) theta = -M_PI/2;
				}else{
					theta = atan((t[1] - v[i][1]) / (t[0] - v[i][0]));
				}
				if(t[0] > v[i][0]) theta += M_PI;
				if(bias <= theta && min > theta){
					min = theta;
					next[0] = v[i][0];
					next[1] = v[i][1];
				}
			}
			ans--;
			t[0] = next[0];
			t[1] = next[1];
			bias = min;
			for(int i=0; i<n; i++){
				if(v[i][0] == t[0] && v[i][1] == t[1]){
					v[i][0] = -10000;
					v[i][1] = -10000;
					break;
				}
			}
		}while(t[0] != s[0] || t[1] != s[1]);

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

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
N,Q= map(int,input().split())
S=input()
lst=[0]*(N+1)
for i in range(N-1):
 if S[i+1]=="C" and S[i]=="A":
  lst[i+2]=lst[i+1]+1
 else:
  lst[i+2]=lst[i+1]
for j in range(Q):
 l,r = map(int,input().split())
 print(lst[r]-lst[l])

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

const int N = 1e6 + 10;

int n, prime[N], check[N], cnt, p[N], tot;
long long ans = 1;

int D(int x) {
    tot = 0;
    for(int i = 1; prime[i] * prime[i] <= x; i++)
        if(x % prime[i] == 0) {
            tot++, p[tot] = 0;
            while(x % prime[i] == 0) x /= prime[i], p[tot]++; 
        }
    if(x != 1) p[++tot] = 1;
    int Sum = 1;
    for(int i = 1; i <= tot; i++) Sum *= (p[i] + 1);
    return Sum;
}

int main() {
    scanf("%d",  &n);
    check[1] = true;
    for(int i = 2; i <= n; i++){
        if(check[i] == 0) prime[++cnt] = i;
        for(int j = 1; j <= cnt && i * prime[j] <= n; j++){
            check[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
        }
    } 
    for(int i = 2; i < n; i++) ans += D(i);
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 7996
// ABC055_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18

const ll MOD7 = 1000000007; // 1 000 000 007

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N;
    cin >> N;
    
    // calculation
    ll res = 1;
    for (ll i = 1; i <= N; ++i) {
        res *= i;
        res %= MOD7;
    }
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;

	long long dp[1009][1009];
	char grid[1009][1009];
	
	#define MOD 1000000007

int main(){

	memset(grid,'#',sizeof grid);
	int n , m; cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> grid[i][j];
		}
	}
	
	dp[1][1] = 1;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			dp[i][j] += ((grid[i-1][j] == '#')?0:dp[i-1][j]) + ((grid[i][j-1] == '#')?0:dp[i][j-1]);
			dp[i][j] %= MOD;
		}
	}
	cout << dp[n][m];




	return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn],num[maxn];
int n,k,q;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k>>q;
    for(int i=0;i<q;i++)
    {
        int tmp;
        cin>>tmp;
        num[tmp]++;
    }
    for(int i=1;i<=n;i++)
    {
        a[i] = k - (q - num[i]);
        if(a[i]<1)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 1408
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                ans += 1

print(ans)

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int i;
string s;
ll num();
ll ll1() {
	//cout << "si" << endl;

	vi v;
	if (isdigit(s[i])) {
		int numm = num();
		assert(s[i] == ']');
		i++;
		return numm;
	}

	while (i<s.size()&&s[i] != ']') {
		//cout << i << endl;
		assert(s[i] == '[');
	
	
		i++;
		v.push_back(ll1());
	}
	sort(ALL(v));
	int res=accumulate(v.begin(), v.begin() + (v.size() + 1) / 2, 0LL);
	++i;
	return res;
}
ll num() {
	ll ret = 0;
	//cout << "num" << endl;
	while (isdigit(s[i])) {
		ret *= 10;
		ret += s[i] - '0';
		++i;
	}
	return (ret+1)/2;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(fdasfd, n) {
		cin >> s;
		i = 0;
		cout << ll1() << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*n/2+(m-1)*m/2<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


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

int main(){
  int i,j,u,k,v,n,d[101][101]={0};
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> u >> k;
    for(j = 0; j < k; j++){
      cin >> v;
      d[u][v]=1;
    }
  }
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      if(j==n){
      cout << d[i][j];
      }else{
      cout << d[i][j] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    long x,y; cin>>x>>y;
    o((x%y==0?-1:x));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
  Int N;
  cin >> N;
  vector<Int> A(N), B(N), C(N);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> B[i];
  rep(i,N) cin >> C[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  
  vector<Int> AtoB(N,0), BtoC(N,0), BtoC2(N+1,0);
  
  rep(i,N) {
    auto ite = upper_bound(B.begin(),B.end(),A[i]);
    AtoB[i] = ite - B.begin();
  }
  
  rep(i,N) {
    auto ite = upper_bound(C.begin(),C.end(),B[i]);
    BtoC[i] = C.end() - ite;
  }
  
  BtoC2[N-1] = BtoC[N-1];
  rep1(i,N-1) {
    BtoC2[N-1-i] = BtoC2[N-i] + BtoC[N-1-i];
  }
  
  Int ans = 0;
  rep(i,N) {
    ans += BtoC2[AtoB[i]];
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 4992
SA = input()
SB = input()
SC = input()

i = 1
while True:
    if i == 1:
        prev = SA[0]
        SA = SA[1:]
    else:
        if prev == 'a':
            if prev == 'a' and len(SA) == 0:
                ans = 'A'
                break
            prev = SA[0]
            SA = SA[1:]
        elif prev == 'b':
            if prev == 'b' and len(SB) == 0:
                ans = 'B'
                break
            prev = SB[0]
            SB = SB[1:]
        else:
            if prev == 'c' and len(SC) == 0:
                ans = 'C'
                break
            prev = SC[0]
            SC = SC[1:]
    i += 1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll INF = (ll)(1e18);

vector<ll> xx[(1<<15)+10];
vector<ll> yy[(1<<15)+10];

struct ST {
  ll x, y;
  ll p;
};

void prepare(int S, const vector<ST>& v){
  int N = v.size();
  {
    rep(i,N) xx[S].push_back(abs(v[i].x));
    rep(i,N){
      rep(j,N){
        if((S>>j)&1){
          xx[S][i] = min(xx[S][i], abs(v[i].x - v[j].x));
        }
      }
    }
  }
  {
    rep(i,N) yy[S].push_back(abs(v[i].y));
    rep(i,N){
      rep(j,N){
        if((S>>j)&1){
          yy[S][i] = min(yy[S][i], abs(v[i].y - v[j].y));
        }
      }
    }
  }
}

ll calc(const vector<ST>& v, int T, int R){
  int N = v.size();
  ll ret = 0;
  rep(i,N){
    ret += min(xx[T][i], yy[R][i]) * v[i].p;
  }
  return ret;
}


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

  vector<ST> v;
  rep(i,N){
    ST st;
    cin >> st.x >> st.y >> st.p;
    v.push_back(st);
  }

  for(int S=0; S<(1<<N); S++){
    prepare(S, v);
  }
  
  vector<ll> ret(N+1, INF);

  for(int S=0; S<(1<<N); S++){
    int cnt = 0;
    rep(i,N) if((S>>i)&1) cnt++;
    for(int T=S; T>=0; T--){
      T &= S;
      int R = S^T;
      ret[cnt] = min(ret[cnt], calc(v, T, R));
    }
  }

  rep(i,ret.size()){
    cout << ret[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 14384
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,al=0;cin>>n;
  V<ll> v(n);
  rep(i,0,n){
    cin>>v[i];
    al^=v[i];
  }

  V<ll> ans(n,0);
  rep(i,0,n){
    ans[i]=al^v[i];
  }

  rep(i,0,n)cout<<ans[i]<<" ";
  cout<<ENDL;

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 6364
import java.util.Scanner;

public class Main {

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

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

		int[][] S = new int[M][N+1];

		for(int i = 0 ; i < M ; i ++){
			int k = sc.nextInt();
			for(int j = 0 ; j < k ; j++){
				S[i][j] = sc.nextInt();
			}
		}

		int[] P = new int[M];
		for(int i = 0 ; i < M ; i++){
			P[i] = sc.nextInt();
		}
		sc.close();

		//スイッチパターンを2進数で表現
		int aans = (int)Math.pow(2, N);

		String denkyu;
		//スイッチオフを表現するために、桁埋め
		String ar = "%0" + N + "d";

		int count = 0;
		int a = 0;
		int ans = 0;
		for(int i = 0 ; i < aans ; i++){
			denkyu = String.format(ar ,Integer.parseInt(Integer.toBinaryString(i)));
			//System.out.println(denkyu);


			//各電球ごとのスイッチパターンを全探索
			for(int j = 0 ; j < M ; j++){
				for(int k = 0 ; k < N ; k++){
					if(S[j][k] ==0){
						break;
					}
					//System.out.println("S : " + S[j][k]);

					//スイッチオンの数を合計
					a += Integer.parseInt(String.valueOf(denkyu).substring(S[j][k]-1,S[j][k]));

					}
				//System.out.println("a : " + a);

				//2で割ったときの余りは適切か
				if(a%2 == P[j]){
					count++;
				}
				a = 0;
			}
			//System.out.println(count);
			//全電球が点灯するパターン(countがMになるパターン)は何個あるか
			if(count == M){
				ans++;
			}
			count = 0;
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 29652
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,K,dp[100001],h[100001];
    fill(dp,dp+100001,1e9);
    dp[0]=0;
    cin>>N>>K;
    for(int i=0;i<N;i++)cin>>h[i];
    for(int i=0;i<N;i++)for(int k=1;k<=K;k++)if(i+k<N)dp[i+k]=min(abs(h[i+k]-h[i])+dp[i],dp[i+k]);
    cout<<dp[N-1]<<endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> t(n), v(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	b[n-1] = 0;
	for (int i = n-1; i > 0; i--) {
		b[i-1] = min({b[i] + t[i], v[i], v[i-1]});
	}

	int a = 0;
	double ans = 0;
	for (int i = 0; i < n; i++) {
		if (a+t[i] < b[i]) b[i] = min(b[i], a+t[i]);
		double x = double(b[i]+t[i]-a) / 2;
		ans += a*x + x*x/2 + b[i]*(t[i]-x) + (t[i]-x)*(t[i]-x)/2;
		if (a + x > v[i]) {
			double tmp = double(a+b[i]+t[i]) / 2 - v[i];
			ans -= tmp * tmp;
		}
		a = b[i];
	}
	cout << fixed << setprecision(15);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less

using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define ppi pair<int, int>
#define ppl pair<ll, ll>
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ff first
#define lb lower_bound
#define ub upper_bound
#define ss second
#define inf 1e9
#define enld '\n'
#define cuot cout
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z)                                                        \
  cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
       << z << endl
#define trace4(a, b, c, d)                                                     \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e)                                                  \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f)                                               \
  cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
       << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
       << #f << ": " << f << endl
#define trace(v)                                                               \
  for (auto it = v.begin(); it != v.end(); it++)                               \
    cerr << *it << " ";                                                        \
  cerr << endl;
#define linf 1e18
#define reset(x) memset(x, 0, sizeof(x))
#define rep(i, a, b) for (int i = a; i < b; i++)

using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    oset;

void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int par[100005];
int rankk[100005];
int findd(int x){
    if(par[x]==x)return x;
    return par[x]=findd(par[x]);
}

void unionn(int xx,int yy){
    int x=findd(xx);
    int y=findd(yy);
    if(rankk[x]<rankk[y]){
        par[x]=y;
    }
    else
        par[y]=x;
    if(rankk[x]==rankk[y])
        rankk[x]++;
}

void solve() {
    int n,m;cin>>n>>m;
    rep(i,1,n+1){
        par[i]=i;
    }

    rep(i,0,m){
        int x,y,z;
        cin>>x>>y>>z;
        unionn(x,y);
    }
    int ans=0;
    rep(i,1,n+1){
        if(par[i]==i){
            ans++;
            // cout<<i<<endl;
        }
    }
    cout<<ans<<endl;
}
int main() {
  fastio();
  int t;
  t = 1;
  //   cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> mp(h, vector<char> (w));
  rep(i, h) rep(j, w) cin >> mp[i][j];
  
  int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
  
  rep(i, h) {
    rep(j, w) {
      if(mp[i][j] == '.') {
        int bombs = 0;
        rep(k, 8) {
          int ni = i+dx[k];
          int nj = j+dy[k];
          
          if(ni<0 || h <= ni) continue;
          if(nj<0 || w <= nj) continue;
          if(mp[ni][nj] == '#') ++bombs;
        }
        mp[i][j] = char(bombs+'0');
      }
    }
  }
  
  rep(i, h) {
    rep(j, w) cout << mp[i][j];
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3584
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = Array.init 2 @@ fun _ -> read_line () |> split_string ~pattern:" " |> List.map int_of_string |> Array.of_list

let () =
  for i = 1 to n - 1 do a.(0).(i) <- a.(0).(i - 1) + a.(0).(i) done;
  a.(1).(0) <- a.(1).(0) + a.(0).(0);
  for i = 1 to n - 1 do a.(1).(i) <- max a.(0).(i) a.(1).(i - 1) + a.(1).(i) done;
  Printf.printf "%d\n" a.(1).(n - 1)

Measured memory_bytes: 3864
#include <stdio.h>

int main(void){
    int a,b,ans;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?')
            break;
        switch(op){
            case '+':
                printf("%d\n",a+b);
                break;
            case '-':
                printf("%d\n",a-b);
                break;
            case '*':
                printf("%d\n",a*b);
                break;
            case '/':
                printf("%d\n",a/b);
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;

int main() {
	int n; cin >> n;
	vector<int>a(n);
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			count++;
		}
	}
	if (count == n) {
		cout << "second" << endl;
	}
	else {
		cout << "first" << endl;
	}
}

	

Measured memory_bytes: 640
N = int(input())
S = list(input())
arr_R = []
arr_G = []
arr_B = []

for idx,s in enumerate(S):
  if s=="R":
    arr_R.append(idx+1)
  elif s=="G":
    arr_G.append(idx+1)
  else:
    arr_B.append(idx+1)

ans = len(arr_R)*len(arr_G)*len(arr_B)
omit = 0

for i in range(N):
  for j in range(i+1,N):
    k = 2*j-i
    if k<N:
      if not (S[i]==S[j] or S[j]==S[k] or S[k]==S[i]):
        omit += 1
print(ans-omit)
      

Measured memory_bytes: 74260
a, b, c = [int(n) for n in input().split()]
d = c-a-b
if d < 0:
    print("No")
elif 4*a*b < d*d:
    print("Yes")
else:
    print("No")

#a + 2sqrt(ab) + b < c
#sqrt(4ab) < c-a-b
#4ab < d^2


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

using namespace std;

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

	int n, s;
	cin >> n >> s;
	const int mod = 998244353;
	int d[3005][3005]{};
	d[0][0] = 1;
	for(int i =1; i<=n; ++i) {
		int a; cin >> a;
		for(int j =0; j<=s; ++j) {
			d[i][j] += 2 * d[i - 1][j];
			d[i][j] %= mod;
			if (j - a >= 0) {
				d[i][j] += d[i - 1][j - a];
				d[i][j] %= mod;
			}
		}
	}
	cout << d[n][s];
}

Measured memory_bytes: 38908
#include<bits/stdc++.h>
#define ll long long
#define maxn 20000
using namespace std;
ll a[505][505];
ll prime[1005];
int cnt,p[20005],n;

void print(ll x){
	if(x>=10) print(x/10);
	putchar(x%10+'0');
}

ll lcm(ll x,ll y){
	return x/__gcd(x,y)*y;
}

int main(){
	for(int i=2;i<=maxn;i++){
		if(p[i]==0) prime[++cnt]=i;
		if(cnt==1000) break;
		for(int j=1;j<=cnt&&i*prime[j]<=maxn;j++){
			p[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	scanf("%d",&n);
	if(n==2){
		print(4),putchar(' '),print(7);puts("");
		print(23),putchar(' '),print(10);puts("");
		return 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(!((i&1)^(j&1))) a[i][j]=prime[(i+j)/2]*prime[n+(n+1+i-j)/2];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if((i&1)^(j&1)){
				a[i][j]=1;
				if(i>1) a[i][j]=lcm(a[i][j],a[i-1][j]);
				if(i<n) a[i][j]=lcm(a[i][j],a[i+1][j]);
				if(j>1) a[i][j]=lcm(a[i][j],a[i][j-1]);
				if(j<n) a[i][j]=lcm(a[i][j],a[i][j+1]);
				a[i][j]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) print(a[i][j]),putchar(' ');
		puts("");
	}

	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include<stdio.h>
#include<vector>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    char A,B,C,D;
    int A1,B1,C1,D1;
    scanf("%c%c%c%c",&A,&B,&C,&D);
    A1=A-'0';
    B1=B-'0';
    C1=C-'0';
    D1=D-'0';
    if(A1+B1+C1+D1==7)
        printf("%c+%c+%c+%c=7\n",A,B,C,D);
    else if(A1+B1+C1-D1==7)
        printf("%c+%c+%c-%c=7\n",A,B,C,D);
    else if(A1+B1-C1+D1==7)
        printf("%c+%c-%c+%c=7\n",A,B,C,D);
    else if(A1-B1+C1+D1==7)
        printf("%c-%c+%c+%c=7\n",A,B,C,D);
    else if(A1+B1-C1-D1==7)
        printf("%c+%c-%c-%c=7\n",A,B,C,D);
    else if(A1-B1+C1-D1==7)
        printf("%c-%c+%c-%c=7\n",A,B,C,D);
    else if(A1-B1-C1+D1==7)
        printf("%c-%c-%c+%c=7\n",A,B,C,D);
    else if(A1-B1-C1-D1==7)
        printf("%c-%c-%c-%c=7\n",A,B,C,D);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int top[100004], middle[100004], bottom[100004];
	long long hitung[100004], hitung2[100004];
	
	int n,i,j;
	
	cin >> n;
	for (i=1; i<=n; i++)cin >> top[i];
	for (i=1; i<=n; i++)cin >> middle[i];
	for (i=1; i<=n; i++)cin >> bottom[i];
	
	sort(top+1, top+n+1);
	sort(middle+1, middle+n+1);
	sort(bottom+1, bottom+n+1);
	top[0] = middle[0] = bottom[0] = 0;
	long long temp;
	//for (i=1; i<=n; i++)cout << top[i] << " ";
	//cout << endl;
	//for (i=1; i<=n; i++)cout << middle[i] << " ";
	/*cout << endl;
	for (i=1; i<=n; i++)cout << bottom[i] << " ";
	cout << endl;*/
	hitung[0] = 0;
	
	j=n;
	while (bottom[j-1] > middle[1])j--;
	
	for (i=1; i<=n; i++){
		while(bottom[j]<=middle[i] && j+1<=n)j++;
		
		if (bottom[j] <= middle[i])hitung[i] = 0;
		else hitung[i] = (n-j+1);
	}
	//for (i=1; i<=n; i++)cout << hitung[i] << " ";
	//cout << endl;
	
	
	
	
	j=n;
	temp = hitung[j];
	while (middle[j-1] > top[1]){
		j--;
		temp += hitung[j];
	}
	//cout << temp << endl;
	for (i=1; i<=n; i++){
		while(middle[j] <= top[i] && j+1<=n){
			temp -= hitung[j];
			j++;
		}
		if (middle[j] <= top[i])hitung2[i] = 0;
		else hitung2[i] = temp;
	}
	//for (i=1; i<=n; i++)cout << hitung2[i] << " ";
	//cout << endl;
	
	temp = 0;
	for (i=1; i<=n; i++){
		//cout << hitung[i] << endl;
		temp += hitung2[i];
	}
	cout << temp << endl;
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <stack>
using namespace std;
int main(){
int m;
int n;
int b;
int c;
int h;//現在の割った氷
int i;//割った氷の最高
int j;
int k;
while(cin >>m>>n){
if(m==0&&n==0){break;}
int a[n][m];
int g[n][m];//氷が残っているか
b=0;
while(b<n){
c=0;
while(c<m){
cin >>a[b][c];
g[b][c]=a[b][c];
c=c+1;}
b=b+1;}
stack<int> d;//nの値
stack<int> e;//mの値
stack<int> f;//次進む経路0上1下2左3右
i=0;
b=0;
while(b<n){
c=0;
while(c<m){
d.push(b);
e.push(c);
f.push(0);
h=1;
k=0;
g[b][c]=0;
while(h!=0){
if(a[b][c]==0){break;}
if(f.top()==0&&d.top()!=0&&g[d.top()-1][e.top()]==1&&k==0){d.push(d.top()-1); e.push(e.top()); f.push(0); g[d.top()][e.top()]=0; h=h+1;}
else if(f.top()==1&&d.top()!=n&&g[d.top()+1][e.top()]==1&&k==0){d.push(d.top()+1); e.push(e.top()); f.push(0); g[d.top()][e.top()]=0; h=h+1;}
else if(f.top()==2&&e.top()!=0&&g[d.top()][e.top()-1]==1&&k==0){d.push(d.top()); e.push(e.top()-1); f.push(0); g[d.top()][e.top()]=0; h=h+1;}
else if(f.top()==3&&e.top()!=m&&g[d.top()][e.top()+1]==1&&k==0){d.push(d.top()); e.push(e.top()+1); f.push(0); g[d.top()][e.top()]=0; h=h+1;}
else {k=0;
if(f.top()!=3){j=f.top(); f.pop(); f.push(j+1);}
else{g[d.top()][e.top()]=1; h=h-1; d.pop(); e.pop(); f.pop(); k=1;}}
if(h>i){i=h;}
}
c=c+1;}
b=b+1;}
cout <<i<<endl;}}

Measured memory_bytes: 1320
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		long total = 0;

		for (int i = 0; i < N; i++)
			a[i] = sc.nextInt();

		for (int i = 0; i < N; i++) {
			if (a[i] > x) {
				total += a[i] - x;
				a[i] = x;
			}
		}

		for (int i = 0; i < N - 1; i++) {
			if (a[i] + a[i + 1] > x) {
				if (a[i + 1] > a[i] + a[i + 1] - x) {
					total += a[i] + a[i + 1] - x;
					a[i + 1] -= a[i] + a[i + 1] - x;
				} else {
					total += a[i] + a[i + 1] - x;
					a[i + 1] = 0;
					a[i] -= a[i] - x;
				}
			}
		}
		System.out.println(total);
	}

}


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

int main() {
	
	int A,B;string S;
	cin>>A>>B>>S;
	if(S.at(A)=='-'){
		int y=true;
		fx(S.size()){
			if(x==A){continue;}
			if(S.at(x)=='-'){y=false;}
		}
		if(y)
		ce("Yes")
		else
		ce("No")
	}else{
		ce("No")
	}
}

Measured memory_bytes: 256
# coding: utf-8

S = input()
a = list(S)
A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])

if A+B+C+D==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B-C+D==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C+D==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C-D==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B-C-D==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

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

int n;
ll a[100000],b[100000],c[100000];
ll dp1[100000];
ll ans;

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

	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) cin>>b[i];
	REP(i,n) cin>>c[i];

	sort(a,a+n); sort(b,b+n); sort(c,c+n);
	int j=0;
	REP(i,n) {
		while (b[i]>a[j]&&j<n) {
			j++;
		}
		dp1[i]=j;
	}
	j=0;
	ll sum=0;
	REP(i,n) {
		while (c[i]>b[j]&&j<n) {
			sum+=dp1[j];
			j++;
		}
		ans+=sum;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;

//----------------library in this time--------------------------------
template <typename T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <typename T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <typename T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

//------------------------main function-------------------------------
void Main(){
    i64 k,x;
    cin >> k >> x;
    for(i64 i = x - k + 1; i <= x + k - 1; i++){
        cout << i << " ";
    }
    cout << endl;
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>

#include <stdio.h>
#include <string.h>


using namespace std;

typedef enum tagCOLOR{
	GRAY=0,
	BROWN,
	GREEN,
	CYAN,
	BLUE,
	YELLOW,
	ORANGE,
	RED,
	FREE,
	COL_NUM
}COLOR;

int main(int argc, char* argv[])
{
	int N;
	int col[COL_NUM]={0};
	int mincol=0,maxcol=0;

	cin >> N;

	vector<int> a(N);
 
	for(int i=0;i<N;i++){

		cin >> a[i];

		if(a[i]>=1 && a[i]<=399){
			col[GRAY]++;
		}else if(a[i]>=400 && a[i]<=799){
			col[BROWN]++;
		}else if(a[i]>=800 && a[i]<=1199){
			col[GREEN]++;
		}else if(a[i]>=1200 && a[i]<=1599){
			col[CYAN]++;
		}else if(a[i]>=1600 && a[i]<=1999){
			col[BLUE]++;
		}else if(a[i]>=2000 && a[i]<=2399){
			col[YELLOW]++;
		}else if(a[i]>=2400 && a[i]<=2799){
			col[ORANGE]++;
		}else if(a[i]>=2800 && a[i]<=3199){
			col[RED]++;
		}else{
			col[FREE]++;
		}

	}

	for(int i=0;i<COL_NUM - 1;i++){
		if(col[i]!=0){
			mincol++;	
		}
	}

	maxcol = mincol + col[FREE];

	if(mincol==0){
		mincol = 1;
	}

	cout << mincol << " " << maxcol << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	if(a > b) swap(a,b);
	if(a > c) swap(a,c);
	if(b > c) swap(b,c);
	c -= b;
	b -= a;
	a = 0;
	//cout<<a<<" "<<b<<" "<<c<<endl;
	int ans = 0;
	if(b & 1) ++b,++ans;
	ans += b / 2 + c;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import math
import sys
n,m = map(int,input().split())
s = input()
t = input()
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
ans = lcm(n,m)
n1 = ans//n
m1 = ans//m
atai = {}
for i in range(n):
  atai[i*n1+1] = s[i]
for i in range(m):
  kaku = atai.get(i*m1+1, -1)
  if kaku != -1 and kaku != t[i]:
    print(-1)
    exit()
print(ans)

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

int main()
{
  int a[3][3];
  bool po[3][3] = {false};
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> a[i][j];
    }
  }
  
  int n;
  cin >> n;
  int b[n];
  for(int i = 0; i < n; i++){
    cin >> b[i];
  }
  
  for(int k = 0; k < n; k++){
   for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      if(b[k] == a[i][j]){
        po[i][j] = true;
      }//if
    }//for
   }//for
  }//for
     
  for(int i = 0; i < 3; i++){
    if(po[i][0] && po[i][1] && po[i][2]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  for(int j = 0; j < 3; j++){
    if(po[0][j] && po[1][j] && po[2][j]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  if(po[0][0] && po[1][1] && po[2][2]){
    cout << "Yes" << endl;
    return 0;
  }
  if(po[0][2] && po[1][1] && po[2][0]){
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" << endl;
  
   }

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 200005;
const int M = 301;
int n,m;
int a,b,c,d;
LL dis[N];
struct nd
{
    int v;
    int nxt;
    LL c;
}edge[N<<1];
int head[N],cnt;
int vis[N];
void add_edge(int a,int b,LL c)
{
    edge[cnt].v=b;
    edge[cnt].c=c;
    edge[cnt].nxt=head[a];
    head[a]=cnt++;
}
void ini()
{
    memset(head,-1,sizeof head);
    cnt=0;
    memset(dis,0,sizeof dis);
    memset(vis,0,sizeof vis);
}
void dfs(int x)
{
    vis[x]=1;
    for (int i=head[x];~i;i=edge[i].nxt)
    {
        int e = edge[i].v;
        LL cost = edge[i].c;
        if (vis[e])
            continue;
        // cout<<"bug "<<e<<" "<<dis[e]<<endl;
        dis[e] = dis[x] + cost;
        dfs(e);
    }
}
int main()
{
    while (~scanf("%d",&n))
    {
        ini();
        for (int i=0;i<n-1;i++)
        {
            int a,b;
            LL c;
            scanf("%d%d%lld",&a,&b,&c);
            add_edge(a,b,c);
            add_edge(b,a,c);
        }
        int s;
        scanf("%d%d",&m,&s);
        dfs(s);
        // for (int i=1;i<=n;i++)
        // {
        //     cout<<i<<" "<<dis[i]<<endl;
        // }
        while (m--)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            printf("%lld\n",dis[a]+dis[b]);;
        }
    }
    return 0;
}

/*

5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5

*/

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

int main(void){
	int n;
	double u;
	double sum=0.0;
	char s[3];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lf %s",&u,s);
		if(strcmp(s,"JPY")==0){
			sum = sum + u;
		}else{
			sum = sum + (u*380000.0);
		}
	}
	printf("%.5f\n",sum);
	return 0;
}

Measured memory_bytes: 128
def main():
    n = int(input())
    ps = list(map(int, input().split()))
    ans = 0
    minp = float("inf")
    for p in ps:
        minp = min(minp, p)
        if minp >= p:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 75472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,A,B;
  cin>>N>>A>>B;
  if(A>B){
    cout<<0<<endl;
  }
  else if(N==1 && A!=B){
    cout<<0<<endl;
  }
  else if(N==2){
    cout<<1<<endl;
  }
  else{
    cout<<((N-1)*B+A)-((N-1)*A+B)+1<<endl;
  }
}


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

int main(){
  string s; cin >> s;
  int check[26] = {};
  for(int i = 0; i < s.size(); i++){
    int t = s[i]-'a';
    check[t] = 1;
  }
  for(int i = 0; i < 26; i++){
    if(check[i] == 0) { 
      char ans = 'a' + i;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 3736
#include<stdio.h>

int main(void)
{
	int i,a,count=0;
	char s[26]={0};
	for(i=0;i<4;i++){
		scanf("%c",&a);
		s[a-'A']++;
	}
	for(i=0;i<26;i++){
		if(s[i]==2)
			count++;
	}
	if(count==2)
		printf("Yes");
	else
		printf("No");
	return 0;
}
		
	

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int N;
    cin >> N;
    map<int, int> freq_1;
    map<int, int> freq_2;
    map<int, int> freq_3;

    const int kNum = 100;

    for(int i=1; i<=kNum; ++i) {
        uint64_t x2 = i * i;
        for(int j=i; j<=kNum; ++j) {
            uint64_t y2 = j * j;
            uint64_t xy = i * j;
            for(int k=j; k<=kNum; ++k) {
                uint64_t z2 = k * k;
                uint64_t tmp = x2 + y2 +z2 + xy + j*k + i*k;
//                cout << i << " " << j << " " << k << " " << tmp << endl;
                if(i == j && j == k) {
                    freq_1[tmp]++;
                } else if (i != j && j != k) {
                    freq_3[tmp]++;
                } else {
                    freq_2[tmp]++;
                }
            }
        }
    }

    rep(i, N) {
        int ret = 0;
        ret += freq_1[i+1];
        ret += freq_2[i+1]*3;
        ret += freq_3[i+1]*6;
//        cout << i+1 << " " << ret << " " << freq_1[i+1] << " " << freq_2[i+1] << endl;
        cout << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 6152
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

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

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll N;
  cin>>N;
  if(N<1200)puts("ABC");
  else if(N<2800)puts("ARC");
  else puts("AGC");
  return 0;
}

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, rev;
    long double cap;
	Edge(ll _to, long double _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, long double cap, bool revFlag, long double revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

template<typename T, typename F>
class SegmentTree {
private:
	T e;
	F op;
	ll n;
	vector<T> dat;
public:
	SegmentTree(F f, T _e, vector<T> v) :op(f), e(_e) {
		int _n = v.size();
		n = 1;
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, e);
		REP(i, _n)dat[n + i - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	SegmentTree(F f, T _e, int _n) :op(f), e(_e) {
		n = 1;
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, e);
		for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	void update(int i, T x) {
		i += n - 1;
		dat[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	T query(int l, int r) {
		//[l,r)でのクエリ処理
		T left = e, right = e;
		l += n - 1; r += n - 1;
		while (l < r) {
			if ((l & 1) == 0)left = op(left, dat[l]);
			if ((r & 1) == 0)right = op(dat[r - 1], right);
			l = l / 2;
			r = (r - 1) / 2;
		}
		return op(left, right);
	}
};



void solve(){
    ll n,q;
    cin>>n>>q;

    Array a(n,(1LL<<31)-1);
    auto op = [](ll a, ll b) {return min(a,b); };
    SegmentTree<ll, decltype(op)> seg(op,INF,a);

    REP(_,q){
        ll t,x,y;
        cin>>t>>x>>y;
        if(t==0){
            seg.update(x,y);
        }else{
            cout<<seg.query(x,y+1)<<en;
        }
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}



Measured memory_bytes: 6492
#!/usr/bin/perl

$line = 0;
while(<>) {
    if($line == 0) {
        ($n) = split /\s+/, $_;
    } else {
        @a = split /\s+/, $_;
    }
    $line++;
}

@s = sort {$a <=> $b} @a;
print $s[$#s] - $s[0], "\n";


Measured memory_bytes: 512