akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
import bisect
N, A, B = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

m = sum(V[:A])/A

cnts = []
cnt = 0
res = None
for i in range(N):
    if res is None or V[i] != res:
        if res is not None:
            cnts.append(cnt)
        cnt = 1
        res = V[i]
    else:
        cnt += 1
cnts.append(cnt)
fac = [1, 1]
for i in range(2, 51):
    fac.append(i*fac[-1])

if cnts[0] >= A:
    ans = 0
    for i in range(A, min(B, cnts[0])+1):
        ans += fac[cnts[0]]//fac[i]//fac[cnts[0]-i]
else:
    ans = 1
    for cnt in cnts:
        if cnt <= A:
            A -= cnt
            B -= cnt
            ans *= cnt
        else:
            ans *= fac[cnt]//fac[A]//fac[cnt-A]
print(m)
print(ans)


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

using namespace std;

typedef long ll;


vector<pair<int,bool>> st[100001];
bool mk[100001];

int n;

void dfs(int x, int old) 
{
	for (auto i : st[x]) {
		if (i.first == old) continue;
		mk[i.first] = mk[x] ^ i.second;
		dfs(i.first, x);
	}
}

int main(int, char**)
{
	double ans = 0;
	cin >> n;

// #define DB
	for (int i = 1; i < n; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		--u; --v;
		st[u].push_back({v, w & 1}); 
		st[v].push_back({u, w & 1}); 
#ifdef DB
		cerr << u << ":" << v << "=" << (w&1) << endl; 
#endif
	}
#ifdef DB
	cerr << "-------\n";
	for (int x = 0;  x < n; ++x) {
		for (auto i : st[x]) {
			cerr << x << ":" << i.first << "=" << i.second << endl; 
		}
	}
#endif

	mk[0] = false;
	dfs(0, 0);

	for (int i = 0; i < n; i++) {
		cout << (mk[i] == 1 ? "1" : "0") << "\n";
	}

	cout.flush();
	return 0;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>

int main() {
    int N,K;
    cin >> N >> K;
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin >> H.at(i);
    }
    sort(H.begin(),H.end());
    int diff = 1000000000;
    for(int i=0;i<N-K+1;i++){
        if(diff >= H[i+K-1] - H[i]){
            diff = H[i+K-1] - H[i];
        }
    }
    cout << diff << endl;
} 



Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  while(1){
    int a,b,c,n[300],max,sa,ans;
    cin>>a>>b>>c;
    if(a==0&&b==0&&c==0)break;
    for(int i=0;i<a;i++){
      cin>>n[i];
    }
    for(int i=b-1;i<=c-1;i++){
      sa=n[i]-n[i+1];
      if(i==b-1)max=sa;
      if(max<=sa){
        max=sa;
        ans=i+1;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

struct Info {
  bool with_berry;
  int16_t linked = -1;
  vector<int16_t> *linked_from = nullptr;
  void link(int16_t row) {
    if (!linked_from)
      linked_from = new vector<int16_t>();
    linked_from->push_back(row);
  }
};

int main()
{
  int H, W, K;
  cin >> H >> W >> K;

  char S[H][W];
  int32_t G[H][W];

  for (int h=0; h<H; ++h)
    for (int w=0; w<W; ++w)
      G[h][w] = 0;
  
  vector<int16_t> rows_without_berry;
  vector<Info> infos(H);
  int16_t last_row_with_berry = 0;
  
  for (int h=0; h<H; ++h) {
    infos[h].with_berry = false;
    for (int w=0; w<W; ++w) {
      cin >> S[h][w];
      if (S[h][w]=='#')
	infos[h].with_berry = true;
    }
    if (!infos[h].with_berry)
      rows_without_berry.push_back(h);
    else
      last_row_with_berry = h;
  }

  for (int16_t row : rows_without_berry) {
    if (row > last_row_with_berry) {
      infos[last_row_with_berry].link(row);
      infos[row].linked = last_row_with_berry;
    } else {
      int16_t link = row+1;
      while (!infos[link].with_berry)
	++link;
      infos[link].link(row);
      infos[row].linked = link;
    }
  }

  int32_t group_id = 1;
  for (int16_t h=0; h<H; ++h) {
    if (!infos[h].with_berry)
      continue;

    vector<int16_t> cols_with_berry;
    for (int16_t w=0; w<W; ++w) {
      if (S[h][w]=='#')
	cols_with_berry.push_back(w);
    }

    for (uint16_t ii=0; ii<cols_with_berry.size(); ++ii) {
      int16_t col = cols_with_berry[ii];
      if (cols_with_berry.size()==1) {
	for (int16_t w=0; w<=W; ++w) {
	  G[h][w] = group_id;
	  if (infos[h].linked_from) {
	    for (int16_t row : *(infos[h].linked_from))
	      G[row][w] = group_id;
	  }
	}	
      } else if (col == cols_with_berry.front()) {
	for (int16_t w=0; w<=col; ++w) {
	  G[h][w] = group_id;
	  if (infos[h].linked_from) {
	    for (int16_t row : *(infos[h].linked_from))
	      G[row][w] = group_id;
	  }
	}
      } else if (col == cols_with_berry.back()) {
	for (int16_t w=cols_with_berry[ii-1]+1; w<W; ++w) {
	  G[h][w] = group_id;
	  if (infos[h].linked_from) {
	    for (int16_t row : *(infos[h].linked_from))
	      G[row][w] = group_id;
	  }
	}
      } else {
	for (int16_t w=cols_with_berry[ii-1]+1; w<=col; ++w) {
	  G[h][w] = group_id;
	  if (infos[h].linked_from) {
	    for (int16_t row : *(infos[h].linked_from))
	      G[row][w] = group_id;
	  }
	}
      }
      ++group_id;
    }
  }

  for (int h=0; h<H; ++h) {
    for (int w=0; w<W; ++w) {
      cout << G[h][w] << ' ';
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int x, y;
    int g[] = {0, 1, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0};
    
    cin >> x >> y;
    
    if (g[x - 1] == g[y - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n;
    cin >> n;

    if (n % 10 == 9 || (n / 10) % 10 == 9) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;


int main()
{
    int n;
    cin >> n;
    int a[26];
    int b[26];
    for(int i = 0; i < 26; i++){
        a[i] = INF;
        b[i] = 0;
    }
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        for(int i = 0; i < s.size(); i++){
            b[s[i] - 'a']++;
        }
        for(int i = 0; i < 26; i++){
            a[i] = min(a[i],b[i]);
        }
        for(int i = 0; i < 26; i++){
            b[i] = 0;
        }
    }
    for(int i = 0; i < 26; i++){
        for(int j = 0; j < a[i]; j++){
            cout << static_cast<char>('a' + i);
        }
    }
    cout << endl;
}

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

using namespace std;

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

int main()
{
	n=read(); k=read(); mx=gc=read();
	for(int i=2;i<=n;i++) 
	{
		tmp=read();
		gc=__gcd(gc,tmp);
		mx=max(mx,tmp);
	}
	if(mx<k) cout << "IMPOSSIBLE" << endl;
	else if(k%gc) cout << "IMPOSSIBLE" << endl;
	else cout << "POSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = ab[0];
        var b = ab[1];

        var n = 1;
        var k = 0;
        while (n < b)
        {
            n = n - 1 + a;
            ++k;
        }
        Console.WriteLine(k);
    }
}


Measured memory_bytes: 13268
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
ll n;

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

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

	cin >> n;

	if (n % 2 == 1) {
		cout << 0 << endl;
		return 0;
	}

	ll jo = 0;
	ll num = 2;
	ll cnt = 0;
	while (num * 5 <= n) {
		num *= 5;
		jo++;
	}

	ll ans = 0;
	while (num >= 5) {
		ans += (n / num - cnt)*jo;
		cnt += (n / num - cnt);
		num /= 5;
		jo--;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const ll N = 3e5 + 7;
long long n , m , a = 1 , cnt;
vector< string >v;
string z ="O";
set<ll>st;
int main() {
   cin >> n;
   while( n !=1 ){
    n = n / 2;
    ///cout << n << endl;
    a*=2;
    cnt+=a;
   }
   cout << cnt + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll a,b;
cin>>a>>b;
cout<<a*b/__gcd(a,b);


}

Measured memory_bytes: 256
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int p[110000];
pair<int,int> ev[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		ev[i]=make_pair(-p[i],i);
	}
	std::sort(ev,ev+a);
	set<int>S;
	S.insert(-2);
	S.insert(-1);
	S.insert(a);
	S.insert(a+1);
	long long ret=0;
	for(int i=0;i<a;i++){
		int at=ev[i].second;
		int left1=(*(--(S.lower_bound(at))));
		int right1=(*(S.lower_bound(at)));
		int left2=(*(--(--(S.lower_bound(at)))));
		int right2=(*(++(S.lower_bound(at))));
		S.insert(at);
		if(left1>=0){
			long long lef=left1-left2;
			long long rig=right1-at;
			ret+=lef*rig*(-ev[i].first);
		}
		if(right1<=a-1){
			long long lef=at-left1;
			long long rig=right2-right1;
			ret+=lef*rig*(-ev[i].first);
		}
		
	}
	printf("%lld\n",ret);
}



Measured memory_bytes: 6144
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<cstdio>
using namespace std;
int N;

int main(int argc, char const *argv[])
{
cin>>N;
vector<char> S(N);
for(size_t i=0;i<S.size();i++){
    cin>>S[i];
}
auto itr = std::find(S.begin(), S.end(), 'Y');    //  最初の要素5へのイテレータを返す
    if( itr != S.end() ) {     // 発見した場合
        cout<<"Four"<<endl;
    }else{
        cout<<"Three"<<endl;
    }

return 0;
}


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

int N;

vector<string> ans;

void dfs(int depth, int c, string str){ 
  if( depth == N ){ ans.push_back(str); return ;}
  
  for(int i = 0; i <= c+1; i++){ 
    string res = str;
    res += (char)('a'+i);
    dfs(depth+1,max(i,c),res);
  }
  return;
}
  

signed main(void){ 
  
  cin >> N;
  
  dfs(1,0,"a");
  
  sort(ans.begin(),ans.end());
  
  for(auto ne : ans ){ cout << ne << endl;}
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  bool ans = false;
  
  for (int i = 1; i <=9; i++){
    for (int j=1; j<=9; j++){
      if (i*j == n) ans = true;
    }
  }
  
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */
ll bpow(ll a , ll b){
  if (b == 0) return 1;
  ll ret;
  if (b%2 == 0){
    ll  t = bpow(a, b/2);
    ret = t*t;
  }else{
    ll t = bpow(a, (b-1)/2);
    ret = a*t*t;
  }
  return ret;
}

int main() {
  int N; cin >> N;
  vector<ll> D(N); REP(i, N) cin >> D[i];
  int M; cin >> M;
  vector<ll> T(M); REP(i, M) cin >> T[i];

  sort(ALL(D)); sort(ALL(T));

  int d = 0;
  int t = 0;

  int m = D.size();
  int n = T.size();
  while(d < m && t < n ){
    if(D[d] == T[t]){
      t++;
    }
    d++;
  }

  if(t==n){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3328
from collections import deque
n,q=map(int,input().split())
que=deque([])
for _ in range(n):
    que.append((int(x) if x.isdigit() else x for x in input().split()))
log=0
while que:
    name,lefttime=que.popleft()
    if lefttime <= q:
        log+=lefttime
        print(name,log)
    else:
        lefttime-=q
        log+=q
        que.append((name,lefttime))


Measured memory_bytes: 46652
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M, Q := scanInt(), scanInt(), scanInt()
	Map := make([][]int, N+1)
	for i := 1; i <= N; i++ {
		Map[i] = make([]int, N+1)
	}

	for i := 0; i < M; i++ {
		L, R := scanInt(), scanInt()
		Map[L][R]++
	}

	for i := 1; i <= N; i++ {
		for j := 1; j <= N; j++ {
			Map[i][j] += Map[i][j-1]
		}
	}

	for i := 0; i < Q; i++ {
		p, q := scanInt(), scanInt()
		ans := 0
		for i := p; i <= q; i++ {
			ans += Map[i][q] - Map[i][p-1]
		}
		fmt.Println(ans)
	}
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N;
    cin >> N;

    vector<ll > A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};

cout << A[N-1] << endl;  

}

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

using namespace std;

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

int ret(int k)
{
	if (k > 0) return k;
	else return - k;
}

int main(void)
{
	while(1) {
		int n, m;
		cin >> n >> m;
		if (n == 0 || m == 0) break;
		vec<int> a(n), b(m);
		int sum = 0;
		int suma = 0, sumb = 0;
		rep(i, n) {
			cin >> a[i];
			sum += a[i];
			suma += a[i];
		}
		rep(i, m) {
			cin >> b[i];
			sum += b[i];
			sumb += b[i];
		}

		if (sum % 2) {
			cout << -1 << endl;
			continue;
		}

		int keepa = - 1;
		int keepb = - 1;
		int min = 1000000000;
		rep(i, n) rep(j, m) {
			if (suma - sumb == 2 * (a[i] - b[j])) {
				if (min > a[i] + b[j]) {
					keepa = a[i];
					keepb = b[j];
					min = keepa + keepb;
				}
			}
		}
		if (keepa == -1) cout << -1 << endl;
		else cout << keepa << " " << keepb << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())

mod = 10**9 + 7


def main():

    N = in_n()
    A = in_nl()
    T = in_nl()

    if N == 1:
        if A[0] == T[0]:
            print(1)
        else:
            print(0)
        exit()

    yama = [(0, 0)] * N
    yama[0] = (A[0], A[0])

    for i in range(1, N):
        pre_min_h, pre_max_h = yama[i - 1]
        now_h = A[i]

        if pre_max_h < now_h:
            now_min_h = now_h
            now_max_h = now_h
        else:
            now_min_h = 1
            now_max_h = pre_max_h

        yama[i] = (now_min_h, now_max_h)

    yama[-1] = (T[-1], T[-1])

    for i in range(N - 2, -1, -1):

        now_min_h, now_max_h = yama[i]
        pre_h = T[i + 1]
        now_h = T[i]

        if now_h > pre_h:
            if now_min_h <= now_h <= now_max_h:
                now_min_h = now_h
                now_max_h = now_h
            else:
                print(0)
                exit()
        else:
            now_max_h = min(now_max_h, now_h)

        yama[i] = (now_min_h, now_max_h)

    ans = 1
    for i in range(N):
        ans *= (yama[i][1] - yama[i][0] + 1)
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24520
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())
#define TEST(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }


struct tree {
  int n;
  vector<vector<int>> adj;
  tree(int n) : n(n), adj(n) { }
  void add_edge(int s, int t) {
    adj[s].push_back(t);
    adj[t].push_back(s);
  }
  vector<int> pos, tour, depth;
  vector<vector<int>> table;
  int argmin(int i, int j) { return depth[i] < depth[j] ? i : j; }
  void rootify(int r) {
    pos.resize(n);
    function<void (int,int,int)> dfs = [&](int u, int p, int d) {
      pos[u] = depth.size();
      tour.push_back(u);
      depth.push_back(d);
      for (int v: adj[u]) {
        if (v != p) {
          dfs(v, u, d+1);
          tour.push_back(u);
          depth.push_back(d);
        }
      }
    }; dfs(r, r, 0);
    int logn = sizeof(int)*__CHAR_BIT__-1-__builtin_clz(tour.size()); // log2
    table.resize(logn+1, vector<int>(tour.size()));
    iota(all(table[0]), 0);
    for (int h = 0; h < logn; ++h) 
      for (int i = 0; i+(1<<h) < tour.size(); ++i)
        table[h+1][i] = argmin(table[h][i], table[h][i+(1<<h)]);
  }
  int lca(int u, int v) {
    int i = pos[u], j = pos[v]; if (i > j) swap(i, j);
    int h = sizeof(int)*__CHAR_BIT__-1-__builtin_clz(j-i); // = log2
    return i == j ? u : tour[argmin(table[h][i], table[h][j-(1<<h)])];
  }
};

int main() {
  int n;
  scanf("%d", &n);
  tree T(n);
  for (int u = 0; u < n ; ++u) {
    int k; 
    scanf("%d", &k);
    for (int j = 0; j < k; ++j) {
      int v;
      scanf("%d", &v);
      T.add_edge(u, v);
    }
  }
  T.rootify(0);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    printf("%d\n", T.lca(u, v));
  }
}

Measured memory_bytes: 29812
main :: IO ()
main = do
  [n,y] <- map read . words <$> getLine
  otsdm n y

otsdm'
  :: Int -> Int -> [(Int,Int,Int)]
otsdm' n y
  = [(a,b,c) | let a0 = y `quot` 10000
             , a <- [0 .. a0]
             , let b0 = (y - 10000*a) `quot` 5000
             , b <- [0 .. b0]
             , let c = n-a-b
             , a*10000 + b*5000 + c*1000 == y
             ]

otsdm
  :: Int -> Int -> IO ()
otsdm n y
  | null o    = putStrLn "-1 -1 -1"
  | otherwise = putStrLn $ show a ++ " " ++ show b ++ " " ++ show c
  where
    o = otsdm' n y
    (a,b,c) = head o

Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) ((a) < (b) ? (b) : (a))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;



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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}



int main() {
	int i, j, k;
	//ll N, M, K;
	int N, M, K;
	cin >> N;
	double L = N;
	
	printf("%.12lf", L * L * L / 27);
	
	return 0;
	
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var (
		n, q int
		s    string
	)
	fmt.Scan(&n, &q, &s)
	l := make([]int, q)
	r := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&l[i], &r[i])
	}

	c := make([]int, n)
	for i := 1; i < n; i++ {
		c[i] = c[i-1]
		if s[i-1] == 'A' && s[i] == 'C' {
			c[i]++
		}
	}
	for i := 0; i < q; i++ {
		fmt.Println(c[r[i]-1] - c[l[i]-1])
	}
}


Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

class UnionFind {
    vector<int> uni;
    int n;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a) {
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind u1(n), u2(n);
    for (int i = 0; i < k; ++i) {
        int p, q;
        scanf("%d%d", &p, &q);
        u1.unite(p-1, q-1);
    }
    for (int j = 0; j < l; ++j) {
        int r, s;
        scanf("%d%d", &r, &s);
        u2.unite(r-1, s-1);
    }
    using P = pair<int, int>;
    vector<P> v;
    map<P, int> p;
    v.reserve(n);
    for (int i = 0; i < n; ++i) {
        v.emplace_back(make_pair(u1.root(i), u2.root(i)));
        p[make_pair(u1.root(i), u2.root(i))]++;
    }
    for (int i = 0; i < n; ++i) {
        if(i) cout << " ";
        cout << p[v[i]];
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 15104
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include <set>
#define ll long long
using namespace std;
ll a[200050];
ll b[200050];
int ans;
int main()
{
    int n,m,k,t;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]+=a[i-1];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>b[i];
        b[i]+=b[i-1];
    }
    for(int i=0,j=m;i<=n;i++)
    {
        if(a[i]<=k)
        {
            while(a[i]+b[j]>k)j--;
            ans=max(ans,i+j);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6692
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>

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

int main() {
    string n;
    cin >> n;

    long long count = 0;
    for(int i = 0; i < n.size(); i++) {
        count += int(n[i])-48;
    }

    if(count%9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3372
#include<cstdio>
int main() {
	int N, K; scanf("%d%d", &N, &K);
	int ans = 0;
	for(int i=1;i<=N;i++) {
		int x; scanf("%d", &x);
		ans += (x >= K);
	}
	printf("%d\n", ans);
}

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

int main(){
    string a,b;
    cin>>a>>b;
    int n = a.length();
    int m = b.length();
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i-1]==b[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
            else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            //cout<<dp[i][j]<<" ";
        }
        //cout<<endl;
    }
    string ans="";
    int i=n;
    int j=m;
    while(i>0 and j>0){

        if(a[i-1]==b[j-1]){
            ans=a[i-1]+ans;
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]){
            i--;
        }
        else j--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 35584
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    long a, b, c, x, y;
    scan(a, b, c, x, y);

    long ans;
    ans = min(x, y) * min(a + b, 2*c) + max(x - y, 0) * min(a, 2*c) + max(y - x, 0) * min(b, 2*c);

    writeln(ans);
}























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int cnt = 0;
		for (int i=0;i<3;i++) {
			if (S.charAt(i)==T.charAt(i)) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

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

#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;

typedef long long ll;


//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//

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

    cin >> N;
    vector<P > X(N);
    REP(i, 0, N) cin >> X[i].second, X[i].first = i;

    sort(X.begin(), X.end(), secondCompare);

    vector<P > ans(N);
    REP(i, 0, N){
        if(i < N/2){
            ans[i].first = X[i].first;
            ans[i].second = X[N/2].second;
        }else{
            ans[i].first = X[i].first;
            ans[i].second = X[N/2-1].second;
        }
    }
    sort(ans.begin(), ans.end(), firstCompare);
    REP(i, 0, N) cout << ans[i].second << endl;
}


Measured memory_bytes: 5376
#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>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

const int mod = 1000000007;

int train[505][505];
int tsum[505][505];

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

  int n, m, q;
  cin >> n >> m >> q;

  rep(i, m) {
    int x, y;
    cin >> x >> y;
    train[x][y]++;
  }

  rep(i, n) {
    rep(j, n) {
      tsum[i+1][j+1] = train[i+1][j+1] + tsum[i+1][j] + tsum[i][j+1] - tsum[i][j];
    }
  }

  rep(i, q) {
    int x, y;
    cin >> x >> y;
    x--;
    cout << (tsum[y][y] - tsum[x][y] - tsum[y][x] + tsum[x][x]) << endl;
  }
}


Measured memory_bytes: 2944
#!/usr/bin/perl
my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);
if( $n==0 ){
  print "0\n";
  exit(0);
}
my $bcnt = 0;
if( $n < 0 ){
  $n = - $n;
  $bcnt++;
}
my $ans = '';
while( $n > 0 ){
  my $bit = ( $n & 1 );
  $ans = ( ( $bit == 1 ) ? '1' : '0') . $ans;
  $n += 2 if $bcnt % 2 == 1 and $bit == 1;
  $bcnt ++;
  $n >>= 1;
}
print "$ans\n";



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

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

        int[] x = new int[5];
        for (int i = 0; i < x.length; i++) {
            x[i] = sc.nextInt();
        }

        for (int i = 0; i < x.length; i++) {
            if (x[i] == 0) {
                System.out.println(i+1);
                return;
            }
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<ll> buc(101010);
  ll ans = 0;
  rep(i,n){
    ll x;
    cin >> x;
    buc[x] ++;
    ans += x;
  }
  int q;
  cin >> q;
  rep(i,q){
    ll b,c;
    cin >> b >> c;
    ans += c*buc[b]-buc[b]*b;
    buc[c] += buc[b];
    buc[b] = 0;
    cout << ans << endl;
  }
}

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

using str = string;
using ss = stringstream;

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

    int h,w;cin>>h>>w;

    int m=0;
    bool ans=true;
    for(int i=0;i<h;i++)
    {
        str s;cin>>s;
        int bm=m;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='#')
            {
                if(i<m)ans=false;
                else bm=i;
            }
        }
        m=bm;
    }

    puts(ans?"Possible":"Impossible");

    return 0;
}


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

using namespace std;

int main() {
	int n,k;
	cin>>n>>k;
	int s[n] = {0};

	for(int i=0; i<k; i++) {
		int d; cin>>d;
		for(int j=0; j<d; j++) {
			int x; cin>>x;
			s[x-1]++;
		}
	}

	int ans = 0;
	for(int i=0; i<n; i++) {
		ans += s[i] == 0;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#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 sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;
struct type{
    int i, j, k;
};
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

signed main() 
{
    
    fastio;
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b and b!=c)cout<<"Yes"<<endl;
    else if(b==c and a!=b)cout<<"Yes"<<endl;
    else if(a==c and a!=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool prev_p(int*,int*);
void swap(int*,int*);
void reverse(int *,int*);
bool check(vector<int> &,vector<int> &,vector<int> &);
int check(vector<int> &);
int main(){
  int n;
  cin >> n;
  int num[9];
  char col[9];
  vector<int> R;
  vector<int> G;
  vector<int> B;
  
  
  while(--n >=  0){

    for(int i = 0;i < 9;i++){
      cin >> num[i];
      //cout << "aaaaa";

    }
    //    cout << "bb";
    for(int i = 0;i < 9;i++){
      //cout << "bb";
      cin >> col[i];
      
    }
    for(int i = 0;i < 9;i++){
      if(col[i] == 'R')R.push_back(num[i]);
      else if(col[i] == 'G')G.push_back(num[i]);
      else B.push_back(num[i]);
    }
    sort(R.begin(),R.end());
    sort(G.begin(),G.end());
    sort(B.begin(),B.end());
    if(check(R,G,B))cout << "1" << endl;
    else cout << "0" << endl;
    R.clear();
    G.clear();
    B.clear();
    
    
  }
}
bool check(vector<int> &r,vector<int> &g,vector<int> &b){
  int count = 0;
  count = check(r);
  count = count + check(g);
  count = count + check(b);
  if(count == 3)return true;
  
  return false;
  
}
int check(vector<int> &v){
  int max = 0;
  
  do{
    vector<int>::iterator it = v.begin();
    int array[3];
    int i = 0;
    int tmp = 0;
    int count = 0;
    
    while(it != v.end()){
      int flag = 0;
      array[i] = *it;
      if(i == 2){
	i = -1;
	if(array[0] == array[1] && array[1] == array[2])count++;
	else if(array[0]-array[1] == -1 && array[1]-array[2] == -1)count++;
	
	
      }
      ++i;
      ++it;
      
    }
    if(count > max)max =count;
  } while(next_permutation(v.begin(),v.end()));
  
    return max;
}

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

int main()
{
 int n;
 cin>>n;
    int h[n], dp[n];
    for(int i=0;i<n;i++) {
        cin>>h[i];
    }
    dp[0] =0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<  dp[n-1];
                    return 0;
                      
 
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  double a, b, c, d, e, f, x, y;  
  

  while(cin >> a >> b >> c >> d >> e >> f) {
    y = (a*f-c*d)/(a*e-b*d);
    x = c/a - b*y/a;

    printf("%.3lf %.3lf\n", x, y);
  }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int a,b;
    cin >> a >> b;
    if(a > b*2){
        cout << a - b*2 << endl;
    }else{
        cout << 0 << endl;
    }
  

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Caddi2018
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] np = ReadLongs();
            if (np[0] == 1)
            {
                Console.WriteLine(np[1]);
                return;
            }

            double n = np[0];
            long p = np[1];
            long max = (long)Math.Pow(p, 1 / n)+1;
            long res = 1;
            for(long i = 1; i <= max; i++)
            {
                long pow = (long)Math.Pow(i, n);
                if (pow <= p && p % pow == 0) res = i;
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	// a, b, cの中で最大のものは10倍の重み
	// 例: 10a + b + c (aが最大)
	cout << a + b + c + max(max(a, b), c) * 9 << endl;
}

Measured memory_bytes: 256
N=int(input())
if N<2:
    print(1)
elif N<4:
    print(2)
elif N<8:
    print(4)
elif N<16:
    print(8)
elif N<32:
    print(16)
elif N<64:
    print(32)  
elif N<= 100:
    print (64)

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

int main(){
  int com[4],i,res;
  char a,b,c,d;
  char str[4];
  
  cin >> a >> b >> c >> d;
  com[0]=a-'0';
  com[1]=b-'0';
  com[2]=c-'0';
  com[3]=d-'0';

  for(int bit=0; bit<8; bit++){
    res=com[0];
    for(int i=0; i<3; i++){
      if((1<<i)&bit){
        res+=com[i+1];
        str[i]='+';
      }else if(!((1<<i)&bit)){
        res-=com[i+1];
        str[i]='-';
      }
    }        
    if(res==7){
      cout<<com[0]<<str[0]<<com[1]<<str[1]<<com[2]<<str[2]<<com[3]<<"="<<res<<endl;
      break;
    }
  }
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

bool isAcgt(string s) {
  for (char c : s) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      continue;
    } else {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;

  int N = s.size();
  int longest = 0;

  rep(i, N) {
    for (int j = 0; i + j < N + 1; j++) {
      string sub = s.substr(i, j);
      if (isAcgt(sub)) {
        if (sub.size() > longest) {
          longest = sub.size();
        }
      }
    }
  }

  cout << longest << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(void){
    int N;
    cin >> N;
    int t,x,y; t=0; x=0; y=0;
    int t1,x1,y1;
    bool check = true;
    for(int i = 0; i < N; i++){
        cin >> t1 >> x1 >> y1; 
        if((x1+y1+t1+x+y+t)%2 == 1) {
            check = false; break;
        }
        if(abs(x1-x) + abs(y1-y) > t1 - t) {
            check = false; break;
        }
        t = t1; x = x1; y = y1;
    }
    if(check) printf("Yes");
    else printf("No");


}


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

double x1,y1,x2,y2,x3,y3,x4,y4;
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		x2-=x1;
		y2-=y1;
		x4-=x3;
		y4-=y3;
		int r=x2*x4+y2*y4;
		int c=x2*y4-x4*y2;
		if(r==0)puts("1");
		else if(c==0)puts("2");
		else puts("0");
	}
}


Measured memory_bytes: 2112
#include <iostream>
#include <string>

using namespace std;

int main() {
    string text;
    cin >> text;
    for (int i = 0; i < (int)text.size(); i++) {
        if (text[i] == '?') text[i] = 'D';
    }
    cout << text << endl;
    return 0;
}

Measured memory_bytes: 3736
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int lim=18;
ll ans,pw[31],a[31],b[31],k,tmp;
int i,j,n;
ll av(ll x){
	return (x>=0)?x:-x;
}
ll work(int n){
	ll res=1;
	int i;
	if (n&1) res=10;
	for (i=1;i<=n/2;i++){
		if (b[i]==0){
			res*=((i==1)?9:10);continue;
		}
		if (b[i]<0){
			res*=(10+b[i]);
		}else{
			if (i==1){
				if (b[i]==9) return 0;
				res*=9-b[i];
			}else{
				res*=10-b[i];
			}
		}
	}
	return res;
}
void dfs(int x,int n,ll p,ll v){
	int i;
	if (x>1&&av(p-v)>a[x-1]) return;
	if (x>n/2){
		if (p!=v) return;
		tmp+=work(n);
		return;
	}
	for (i=-9;i<=9;i++){
		b[x]=i;
		dfs(x+1,n,p,v+a[x]*(ll)i);
	}
}
ll calc(int x,int n){
	int i;
	for (i=1;i<=n/2;i++) a[i]=pw[n-i]-pw[i-1];
	tmp=0;dfs(1,n,x,0);
	return tmp;
}
int main(){
	for (i=pw[0]=1;i<=lim;i++) pw[i]=10LL*pw[i-1];
	scanf("%d",&n);
	for (i=2,ans=0;i<=lim;i++) ans+=calc(n,i);//,printf("%d %lld\n",i,ans);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x=0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
	string S;
    cin >> S;
    if(S=="Y"){
      x=1;
      break;
    }
      
  }
  
  if(x==1) cout << "Four" << endl;  
  else    cout << "Three" << endl;
  
 }

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <math.h>
#include <algorithm>
#include <functional>
#include <set> 
#include <map> 

using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

signed main()
{
	string sa, sb, sc;
	cin >> sa >> sb >> sc;
	int a = 0, b = 0, c = 0;
	char now = 'a';
	char winner = 'D';
	while (true) {
		if (now == 'a') { 
			if (sa.length() > a) { now = sa[a]; }
			else { winner ='A';  break; }
			a++;
		}
		if (now == 'b') {
			if (sb.length() > b) { now = sb[b]; }
			else { winner = 'B';  break; }
			b++;
		}
		if (now == 'c') {
			if (sc.length() > c) { now = sc[c]; }
			else { winner = 'C';  break; }
			c++;
		}
	}
	cout << winner << endl;
}

Measured memory_bytes: 256