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

using namespace std;

using i64 = long long int;

#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 all(a) a.begin(), a.end()

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    vector<i64> v(12);
    rep(i, 12) cin >> v[i];
    sort(all(v));
    bool flag = true;
    rep(i, 3){
        i64 tmp = v[i * 4];
        rep(j, 4){
            if(tmp != v[i * 4 + j]) flag = false;
        }
    }
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
}


Measured memory_bytes: 3184
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = x - a;
        int cnt = ans / b;
        System.out.println(ans - b * cnt);
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

int main()
{
 int N;
 ll sum ,a;
 sum = 0;

 cin >> N;

 while(N--) {
   scanf("%ld", &a);
   int cnt = 0;
   while ( a % 2 == 0 ) {
     ++cnt;
     a /= 2;
   }
   sum += cnt;
 }

 cout << sum << endl;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
int X[15],Y[15],P[15];
ll ret[16];

ll xmin[1<<15][15];
ll ymin[1<<15][15];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i]>>P[i];
	}
	FOR(i,N+1) ret[i]=1LL<<60;
	
	FOR(i,1<<N) {
		FOR(j,N) {
			xmin[i][j]=abs(X[j])*1LL*P[j];
			ymin[i][j]=abs(Y[j])*1LL*P[j];
			FOR(x,N) if(i&(1<<x)) {
				xmin[i][j]=min(xmin[i][j],abs(X[j]-X[x])*1LL*P[j]);
				ymin[i][j]=min(ymin[i][j],abs(Y[j]-Y[x])*1LL*P[j]);
			}
		}
	}
	
	
	for(int xmask=0;xmask<1<<N;xmask++) {
		int lef=((1<<N)-1)^xmask;
		for(int ymask=lef; ymask>=0; ymask--) {
			ymask&=lef;
			ll sum=0;
			FOR(i,N) sum+=min(xmin[xmask][i],ymin[ymask][i]);
			y=__builtin_popcount(xmask|ymask);
			ret[y]=min(ret[y],sum);
		}
	}
	
	FOR(i,N) ret[i+1]=min(ret[i],ret[i+1]);
	FOR(i,N+1) cout<<ret[i]<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int main() {
  ll h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (ll i = 0; i < h; i++) {
    cin >> s[i];
  }

  vector<vector<pair<char, ll>>> counts_w(h);
  for (ll i = 0; i < h; i++) {
    counts_w[i].push_back(make_pair(s[i][0], 0));
    for (ll j = 1; j < w; j++) {
      if (s[i][j] != s[i][j - 1]) {
        counts_w[i].push_back(make_pair(s[i][j], j));
      }
    }
    counts_w[i].push_back(make_pair('#', w));
  }

  vector<vector<pair<char, ll>>> counts_h(w);
  for (ll j = 0; j < w; j++) {
    counts_h[j].push_back(make_pair(s[0][j], 0));
    for (ll i = 1; i < h; i++) {
      if (s[i][j] != s[i - 1][j]) {
        counts_h[j].push_back(make_pair(s[i][j], i));
      }
    }
    counts_h[j].push_back(make_pair('#', h));
  }
  
  vector<vector<ll>> wc(h, vector<ll>(w, 0));
  for (ll i = 0; i < h; i++) {
    ll cur = 0;
    for (ll j = 0; j < w; j++) {
      if (counts_w[i][cur + 1].second <= j) cur++;
      if (s[i][j] == '#') continue;
      wc[i][j] = counts_w[i][cur + 1].second - counts_w[i][cur].second;
    }
  }

  vector<vector<ll>> hc(h, vector<ll>(w, 0));
  for (ll j = 0; j < w; j++) {
    ll cur = 0;
    for (ll i = 0; i < h; i++) {
      if (counts_h[j][cur + 1].second <= i) cur++;
      if (s[i][j] == '#') continue;
      hc[i][j] = counts_h[j][cur + 1].second - counts_h[j][cur].second;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      ans = max(ans, hc[i][j] + wc[i][j] - 1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 131200
a=(""+require("fs").readFileSync(0)).split`\n`.slice(1,-1).map(s=>
s.split``.reduce((o,c)=>(o[c]=-~o[c],o),{})
).reduce((o,n)=>{
for(k in o)o[k]=Math.min(o[k],n[k]|0)
return o
})
b=[]
for(k in a)b.push(k.repeat(a[k]))
console.log(b.sort().join``)

Measured memory_bytes: 7884
#include<stdio.h>
using namespace std;

int main() {
	int t, h, s;
	while (1) {
		scanf("%d %d %d", &t, &h, &s);
		if (t == -1 && h == -1 && s == -1)break;
		int t_second = 3600 * t + 60 * h + s;
		int tmp1 = 7200 - t_second;
		int tmp2 = tmp1 * 3;
		printf("%02d:%02d:%02d\n%02d:%02d:%02d\n", tmp1 / 3600, tmp1 % 3600 / 60, tmp1 % 3600 % 60, tmp2 / 3600, tmp2 % 3600 / 60, tmp2 % 3600 % 60);
	}
}


Measured memory_bytes: 2588
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll modpow(ll a, ll n=MOD-2, ll mod=MOD){ // a^n % MOD の計算
    ll res = 1;
    while (n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a  % mod;
        n >>= 1;
    }
    return res;
}
vector<ll> bubunode[200010];
struct edge{ll to;};
struct graph{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;
    //vector<vector<ll>> bubunode;

    graph(ll n): N(n), G(N), used(N,false) {}

    void add_edge(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無向ならON
    }

    ll dfs(ll v=0){
        used[v]=true;
        ll ct=1;
        for(auto E : G[v]){
            if(!used[E.to]){
                ll x=dfs(E.to);
                bubunode[v].emplace_back(x);
                ct+=x;
            }
        }
        ll y=N-ct;
        if(y>0) bubunode[v].emplace_back(y);
        return ct;
    }
};

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    graph g(N);
    rep(i,N-1){
        ll a,b; cin>>a>>b;
        g.add_edge(--a,--b);
    }
    g.dfs();
    ll ans=0;
    ll ans3=modpow(2,N-1)-1;
    rep(i,N){
        auto& ve=bubunode[i];
        if(ve.size()<=1) continue;
        ll ans2=ans3;
        for(auto& x: ve){
            ans2-=modpow(2,x)-1;
            ans2+=MOD;
            ans2%=MOD;
        }
        ans+=ans2;
        ans%=MOD;
    }
    ll gya=modpow(2,N);
    gya=modpow(gya);
    ans*=gya;
    ans%=MOD;
    cout<< ans <<"\n";
}

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


Measured memory_bytes: 29184
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)

typedef long long ll;
using namespace std;

int main() {
    
    ll n, p;
    
    cin >> n >> p;
    
    ll r = p;
    ll ans = 1;
    ll bi = 0;
    while (r % 2 == 0) {
        bi++;
        r /= 2;
    }
    bi /= n;
    if (bi) REP(i, bi) ans *= 2;
    for (ll i = 3; i * i <= p; i += 2) {
        ll m = 0;
        while (r % i == 0) {
            m++;
            r /= i;
        }
        m /= n;
        if (m) REP(j, m) ans *= i;
    }
    
    if (n == 1) ans *= r;
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

a = V*T+A
b = W*T+B

if V > W:
    if abs(A-B)/(V-W) <= T:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 9080
N = gets.to_i
adjacency_list = []
N.times{
  u, _, *v = gets.split.map &:to_i
  adjacency_list[u] = v
}
d = Array.new(N+1, -1)
d[1] = 0
q = [1]
until q.empty?
  v = q.shift
  adjacency_list[v].each{|e_v|
    if d[e_v] == -1
      d[e_v] = d[v] + 1
      q << e_v
    end
  }
end

(1..N).each{|i|
  puts "#{i} #{d[i]}"
}

Measured memory_bytes: 8736
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: i32,
        m: i32,
        a: [i32;m],
    };
    let sum: i32 = a.iter().sum();
    let ans = if 0 <= n - sum {n - sum} else{-1};
    println!("{}",ans);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007
#define MAXN 200000

ll sieve[MAXN];
void makeSieve() 
{
    fill(sieve, sieve + MAXN, 1);
    sieve[0] = 0;
    sieve[1] = 0;
    for (int i = 2; i < MAXN; ++i)
    {
        if (sieve[i] == 1)
        {
            for (int j = i*2; j < MAXN; j+=i)
                sieve[j] = 0;
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll x;
    cin >> x;
    makeSieve();
    while (true)
    {
        if (sieve[x])
        {
            cout << x << '\n';
            break;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val (a, b, n) = readListLong()
    var x = n
    if (n >= b -1) x = b -1
    val ans = a * x / b - a * (x / b)
    println(ans)
}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 36452
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define int ll

#define START 0
#define GOAL 1

signed main(){
	ll t,n;
	cin>>t>>n;
	set<ll> st;
	vector<pll> data;
	rep(i,n){
		ll s,t;
		cin>>s>>t;
		data.pb(pll(s,START));
		data.pb(pll(t,GOAL));
	}
	
	sort(all(data));
	
	static ll rui[1000000];
	rep(i,1000000)rui[i] = 0;
	
	for(int i=0;i<data.size();i+=2){
		assert(data[i].second==START);
		rui[i+1] = data[i+1].first - data[i].first;
	}
	
	ll ans = 0;
	
	rep(i,1000000-1)rui[i+1] += rui[i];
	
	for(int i=0;i<data.size();i+=2){
		assert(data[i].second==START);
		
		ll end_time = data[i].first + t;
		
		int pos = upper_bound( all(data) , pll(end_time,-1) )-1-data.begin();
		

		if(data[pos].second==START){
			int r = rui[pos] - rui[i];
			ans = max(ans,r+(end_time - data[pos].first));
		}else if(data[pos].second==GOAL){
			int r = rui[pos]-rui[i];
			ans = max(ans,r);
		}
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 13804
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%p;
		x = x * x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m;
int a[200][200];
int c[200];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < n; i++) {
		int sum = 0;
		for (int j = 0; j < m; j++) {
			sum += a[i][j] * c[j];
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3248
#include<stdio.h>
int main(void)
{
    int n,h=0,m=0,s=0;
	scanf("%d",&n);
	while(n!=0){
	    if(n>=3600){
		    n=n-3600;
			h++;
		}
		else if(n>=60){
		    n=n-60;
			m++;
		}
		else{
		    s=n;
			n=0;
		}
	}
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

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

int main() {
  int x;
  while(cin >> x) {
    int ans= 0;
    for (int i=0; i<10; i++)
      for (int j=0; j<10; j++)
        for (int k=0; k<10; k++)
          for (int l=0; l<10; l++)
            if(i+j+k+l==x) ans++;
    cout << ans << endl;
  }
}



Measured memory_bytes: 3036
n = int(input())
t = [0]
x = [0]
y = [0]
count = 0
for i in range(n):
    val_list = input().split()
    if val_list:
        t.append(int(val_list[0]))
        x.append(int(val_list[1]))
        y.append(int(val_list[2]))
for i in range(n):
    distance = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
    if distance > t[i + 1] - t[i]:
        break
    elif distance == t[i + 1] - t[i]:
        count += 1
    elif distance - (t[i + 1] - t[i]) % 2 == 0:
        count += 1
    else:
        break
if count == n:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11816
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		String[] strArray = str.split("");
		int first0Result = 0;
		int first1Result = 0;
		for (int i = 0; i < strArray.length; i++) {
			if (i % 2 != Integer.parseInt(strArray[i])) {
				first0Result++;
			} else {
				first1Result++;
			}
			
		}
		

		if (first0Result > first1Result) {
			System.out.println(first1Result);
		} else {
			System.out.println(first0Result);
		}
		
	}

}

Measured memory_bytes: 35328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector <int> v(n);
	for(auto &x:v) cin>>x;
	int ans=0,j=1;
	for(int i=0;i<n;i++)
	{
		if(v[i]==j) j++;
		else ans++;
	}
	if(ans==n) cout<<"-1"<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  
  return 0;
}



Measured memory_bytes: 2072
import numpy as np

H,W = map(int,input().split())
# 周りに壁を、0,1化、壁をTrueで持つ
grid = np.ones((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(input()) for _ in range(H)]) == '#')

# x軸方向の集計
def F(transpose):
  x = grid.copy()
  if transpose:
    x = x.T
  x = np.ravel(x) # to 1D array
  
  zero_idx = np.nonzero(x)[0]
  zero_span = np.diff(zero_idx) - 1 # 次の0までにある1の個数
  
  y = np.zeros(x.shape[0],dtype=np.int32)
  y[1:][zero_idx[:-1]] = zero_span # 1の個数の加算の起点
  y[zero_idx[1:]] -= zero_span # 1の個数の反映をやめる
  y = y.cumsum()
  if transpose:
    y = y.reshape(grid.T.shape).T
  else:
    y = y.reshape(grid.shape)
  return y

answer = (F(True) + F(False)).max() - 1
print(answer)

Measured memory_bytes: 237356
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define MAX_N (100000L)
#define MAX_K (100000L)
#define NUM_MOD (1000000007L)

using namespace std;

long perm_km1[MAX_K], perm_km2[MAX_K];

void dp_init(long K) {
  // calculate permutations
  perm_km1[0] = 1;
  for (long k = 1; k < K; k++) {
    perm_km1[k] = (K - 1 - (k - 1)) * perm_km1[k - 1] % NUM_MOD;
  }
  perm_km2[0] = 1;
  for (long k = 1; k < K; k++) {
    perm_km2[k] = (K - 2 - (k - 1)) * perm_km2[k - 1] % NUM_MOD;
  }
}

long dp(const vector<vector<long>> &adj_lists, long cur, long par) {
  long res = 1;
  if (par < 0) {
    // root
    const long num_children = adj_lists[cur].size();
    res = res * perm_km1[num_children] % NUM_MOD;
    for (long nxt : adj_lists[cur]) {
      res = res * dp(adj_lists, nxt, cur) % NUM_MOD;
    }
  } else {
    // not root
    const long num_children = adj_lists[cur].size() - 1;
    res = res * perm_km2[num_children] % NUM_MOD;
    for (long nxt : adj_lists[cur]) {
      if (nxt != par) {
        res = res * dp(adj_lists, nxt, cur) % NUM_MOD;
      }
    }
  }
  return res;
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, K, as[MAX_N], bs[MAX_N];
  scanf("%ld %ld", &N, &K);
  for (long i = 0; i < N - 1; i++) {
    scanf("%ld %ld", &as[i], &bs[i]);
    as[i]--;  // NOTE : modified input
    bs[i]--;  // NOTE : modified input
  }

  // build graph
  vector<vector<long>> adj_lists(N, vector<long>());
  for (long i = 0; i < N - 1; i++) {
    const long a = as[i], b = bs[i];
    adj_lists[a].push_back(b);
    adj_lists[b].push_back(a);
  }

  // solve
  dp_init(K);
  printf("%ld\n", dp(adj_lists, 0, -1) * K % NUM_MOD);

  return 0;
}


Measured memory_bytes: 13184
#54 A - Airport Bus
N,C,K = map(int,input().split())
T = [int(input()) for _ in range(N)]
T = sorted(T,reverse = False)

ans = 0
bus = 1
first = T[0]
for i in range(1,N):
    # T[i] がバスに乗ることができるとき
    if (bus < C) and (T[i] <= first + K):
        bus += 1
    # T[i] がバスに乗ることができないとき
    else:
        # 新しいバスの first になる
        ans += 1
        bus = 1
        first = T[i]
        
print(ans+1)

Measured memory_bytes: 81892
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    while(1){
        ll n; cin >> n;
        if(!n) break;
        vector<pair<double,string>> ans;
        rep(i,n){
            string t; cin >> t;
            ll p,a,b,c,d,e,f,s,m; cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            ll time = a+b+c+d+e + (d+e)*(m-1);
            ll sum = s*m*f - p;
            double res = -sum / (double)time;
            ans.emplace_back(res, t);
        }
        sort(all(ans));
        rep(i,n) cout << ans[i].second << "\n";
        cout << "#" << "\n";
    }
}


Measured memory_bytes: 3188
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;

mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a, b;
    cin >> a >> b;
    int t = b;
    int ct = 1;
    while(t > 0){
        t /= 10;
        ct *= 10;
    }
    int n = a * ct + b;
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            if(i * i == n){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define max(p,q)((p)>(q)?(p):(q))
#define zahyoutype double
typedef struct Point{zahyoutype x,y;}P;
double distPP(P p,P q){return hypot(p.x-q.x,p.y-q.y);}
void readpoint(P*p){zahyoutype x=1;scanf(x/2?"%lf%lf":"%ld%ld",&p->x,&p->y);}

P a[80010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)readpoint(a+i);
	double ans=0;
	int r=0;
	for(int i=0;i<n;i++){
		double crr=distPP(a[i],a[r]);
		while(distPP(a[i],a[(r+1)%n])>crr){
			r=(r+1)%n;
			crr=distPP(a[i],a[r]);
		}
		ans=max(ans,crr);
	}
	printf("%.9f\n",ans);
}


Measured memory_bytes: 3008
def is_int(s):
    try:
        int(s)
        return True
    except ValueError:
        return False

A, B = map(int, input().split())
S = input()
if is_int(S[:A]) and S[A] == '-' and is_int(S[A+1:]):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
typedef long long ll;
using namespace std;

int r, g, b;
const int INF = 10e8;
void CountingRoads(){
	int n, m;
	cin >> n >> m;
	int t[100];
	fill(t, t + n + 1, 0);
	for (size_t i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		t[a]++;
		t[b]++;
	}

	for (size_t i = 1; i <= n; i++)
	{
		cout << t[i] << endl;
	}
}

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



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


int d;
int s[365][26];
int c[26];


int calc(vector<int>& v) {
	int sum = 0;
	int las[26]; rep(i, 26)las[i] = 0;


	int dec = 0;
	rep(j, 26)dec += c[j];

	int aldec = 0;

	rep(i, d) {
		aldec -= c[v[i]] * (i - las[v[i]]);

		sum += s[i][v[i]];
		las[v[i]] = i;

		sum -= aldec;
		aldec += dec;
	}
	return sum;
}

void query(vector<int> v) {
	rep(i, d) {
		cout << v[i] + 1 << "\n";
	}
}
void solve() {
	cin >> d;
	rep(i, 26)cin >> c[i];
	rep(i, d)rep(j, 26)cin >> s[i][j];

	//init_answer
	const int initm = 50000;

	vector<int> v;
	int cur = -mod;

	rep(i, initm) {
		mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
		uniform_int_distribution<> ud(0, 25);

		vector<int> w;
		int las[26]; rep(j, 26)las[j] = 0;
		int sum = 0;

		rep(i, d) {
			w.push_back(ud(mt));
		}
		sum = calc(w);
		if (cur < sum) {
			cur = sum;
			v = w;
		}
	}

	mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
	uniform_int_distribution<> ud(0, d - 1);
	uniform_real_distribution<> rd(0.0, 1.0);
	vector<int> alt = v;


	//cout << cur << "\n";

	rep(i, 80000) {
		int id = ud(mt);
		rep(j, 26) {
			if (j == v[id])continue;
			alt[id] = j;
			int val = calc(alt);
			if (cur < val) {
				//cout <<i<<" "<< val - cur << "\n";
				v = alt;
				cur = val;
			}
		}
		alt = v;
	}

	//cout << cur << "\n";
	query(v);
}


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


Measured memory_bytes: 3692
<?php



fscanf(STDIN,"%d",$N);
fscanf(STDIN,"%s",$S);

$count = 0;

for($i=0;$i<$N;$i++){
    if($S[$i] == 'A' && $S[$i+1] == 'B' && $S[$i+2] == 'C'){ 
        $count++;
    }
}

echo $count."\n";



Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t,i;
    long long int a[100001],temp,c=0,max=0;
    cin>>t;
    cin>>a[0];
    temp=a[0];
    for(i=1;i<t;i++)
    {
        cin>>a[i];
        if(a[i]<=temp)
        {
            c++;
            if(i==t-1)
            {
                if(c>max)
                    max=c;
            }
        }
        else
        {
            if(c>max)
                max=c;
            c=0;
        }
        temp=a[i];
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] list = new int[n];
		for(int i = 0; i < n-1; i++) {
			list[i+1] = list[i] + sc.nextInt();
		}
		int now = 0;
		int sum = 0;
		for(int i = 0; i < m; i++) {
			int to = sc.nextInt();
			sum += Math.abs(list[now] - list[now + to]);
			sum %= 100000;
			now = now + to;
		}
		System.out.println(sum % 100000);
		
	}
	
	
	
}

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

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

    vector<int> data(n);
    for (int i = 0; i < k; i++){
        int d;
        cin >> d;
        for (int j = 0; j < d; j++){
            int id;
            cin >> id;
            data.at(id - 1) = 1;
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++){
        if (data.at(i) == 0){
            count++;
        }
    }

    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3644
import itertools
n = int(input())
p = tuple(map(int,input().split())) 
q = tuple(map(int,input().split())) 
num_list = [x for x in range(1,n+1)]
j = list(itertools.permutations(num_list))
print(abs(j.index(p) - j.index(q)))


Measured memory_bytes: 8052
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define FORR(x,arr) for(auto& x:arr)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
// clang-format on
using namespace std;
typedef signed long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  std::random_device rd;
  std::mt19937 ran(rd());

  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vi cmsum(n);
  cmsum[0] = 0;
  for (int i = 1; i < n; ++i) {
    cmsum[i] = cmsum[i - 1];
    if (s[i - 1] == 'A' and s[i] == 'C')
      cmsum[i]++;
  }

  for (int i = 0, l, r; i < q; ++i) {
    cin >> l >> r;
    r--;
    l--;
    cout << cmsum[r] - cmsum[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1488
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, R; cin >> N >> R;
    if (N >= 10) cout << R << endl;
    else cout << R + 100 * (10 - N) << endl;
}

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

int main() {
    int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
    for(int i = 0; i < 4; ++i) {
        int n; cin >> n;
        cnt1 += n == 1;
        cnt2 += n == 9;
        cnt3 += n == 7;
        cnt4 += n == 4;
    }
    if(cnt1 == 1 && cnt2 == 1 && cnt3 == 1 && cnt4 == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,k,a[105][105],b[105][105],c[105][105],d[105][105],lk[105],s[105][105],vis[105];
int row(int x)
{
	return (x-1)/m+1;
}
int dfs(int x)
{
	if(vis[x])return 0;vis[x]=1;
	int i;fz1(i,n)if(s[x][i]){
		if(!lk[i]||dfs(lk[i])){
			lk[i]=x;return 1;
		}
	}return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,n)fz1(j,m){
		scanf("%d",&a[i][j]);
		b[i][j]=(i-1)*m+j;
	}
	fz1(i,m){
		memset(s,0,sizeof(s));
		fz1(j,n)fz(k,i,m){
			s[j][row(a[j][k])]=a[j][k];
		}
		memset(lk,0,sizeof(lk));
		fz1(j,n){
			memset(vis,0,sizeof(vis));
			if(!dfs(j))exit(-1);
		}
		fz1(j,n){
			c[lk[j]][i]=s[lk[j]][j];
			d[j][i]=s[lk[j]][j];
		}
		fz1(j,n){
			fz(k,i,m)if(s[lk[j]][j]==a[lk[j]][k]){
				swap(a[lk[j]][i],a[lk[j]][k]);
				break;
			}
		}
	}
	fz1(i,n){
		fz1(j,m){
			printf("%d%c",c[i][j],(j==m?'\n':' '));
		}
	}
	fz1(i,n){
		fz1(j,m){
			printf("%d%c",d[i][j],(j==m?'\n':' '));
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
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; }
const long long INF = 1LL << 60;
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;cin >> n;
ll a[n+10][3];
for(int i=0;i<n;i++)for(int j=0;j<3;j++)cin >> a[i][j];
ll dp[n+10][3];
for(int i=0;i<n+10;i++){
    for(int j=0;j<3;j++){
        dp[i][j]=0;
    }
}
for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
        for(int k=0;k<3;k++){
            if(j==k)continue;
            chmax(dp[i+1][k],dp[i][j]+a[i][k]);
        }
    }
}
ll ans = 0;
for(int j=0;j<3;j++)chmax(ans,dp[n][j]);
cout << ans << endl;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    vector<int> a(3);
    vector<int> b(3);
    REP(i,3) {
        cin >> a[i];
        cin >> b[i];
    }
    vector<int> c(5, 0);
    REP(i,3) {
        c[a[i]]++;
        c[b[i]]++;
    }
    sort(c.begin(), c.end());
    if (c[0] == 0 && c[1] == 1 && c[2] == 1 && c[3] == 2 && c[4] == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
a,b,C = list(map(float, input().split() ))
C = math.radians(C)
h = b*math.sin(C)
S = a*h/2
c = math.sqrt( a**2 + b**2 - 2*a*b*math.cos(C) )
L = a+b+c
print(S)
print(L)
print(h)



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

int main(){
  string o,e;
  int sz;
  cin>>o>>e;
  if(o.size()<=e.size()) sz=e.size();
  else sz=o.size();
  for(int i=0;i<sz;i++){
    if(o[i]) cout<<o[i];
    else continue;
    if(e[i]) cout<<e[i];
    else continue;
  }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string w; cin>>w;
	int ans=0;
	while(true){
		string t; cin>>t;
		if(t=="END_OF_TEXT"s)break;
		for(auto&&i:t)if(i>='A'&&i<='Z')i+='a'-'A';
		if(t==w)++ans;
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3216
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int price;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		price = Integer.parseInt(br.readLine());
		System.out.println(price * price * price);
	}
}

Measured memory_bytes: 24308
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    int T;
    std::cin >> T;
    
    REP(_, T){
        int N;
        std::cin >> N;

        int h[100];
        REP(i, N){
            std::cin >> h[i];
        }

        int max_down = 0, max_up = 0;
        FOR(i, 1, N){
            if(h[i-1] > h[i]){
                max_down = std::max(max_down, h[i-1]-h[i]);
            }else{
                max_up = std::max(max_up, h[i]-h[i-1]);
            }
        }

        std::cout << max_up << " " << max_down << std::endl;
    }
}

Measured memory_bytes: 1164
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (i % 2 == 0)
		{
			continue;
		}
		int d = 0;
		for (int j = 1; j <=i; ++j)
		{
			if (i%j == 0)
			{
				d++;
			}
		}
		if (d == 8)
		{
			ans++;
		}
	}
	cout << ans;
	system("pause");
}

Measured memory_bytes: 504
def main():
    A, B, K = map(int, input().split(" "))
    common_divisor = [1]
    for i in range(2, min(A, B) + 1):
        if A % i == 0 and B % i == 0:
            common_divisor.append(i)
    print(common_divisor[-K])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]


A.sort(reverse = True)

canSelect = True
for i in range(M):
    if A[i] < 1/(4*M)*sum(A):
        canSelect = False

if canSelect:
    print("Yes")
else:
    print("No")

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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

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

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

	int ans = 0;
	for(int i = 0; i < n; ++i) {
		int sum = 0;
		for(int j = 0; j < m; ++j) {
			int a;
			cin >> a;
			sum += a;
		}
		chmax(ans, sum);
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
#include<stdio.h>

#define S 64

int N;
int A, B;
long v[S];
long list[S];
long num[S];

void input(){
	std::cin >> N >> A >> B;
	for( int i = 0; i < N; i++ ){
		std::cin >> v[i];
	}
	for( int i = 0; i < S; i++ ){
		list[i] = -1;
		num[i] = 0;
	}
	return;
}

long combi(int n, int k){
	long re = 1;
	for( int i = 1; i <= k; i++ ){
		re *= (n-i+1);
		re /= i;
	}
	return re;
}

void run(){
	long msum = 0;
	long s = 0;
	std::sort(&v[0], &v[N]);
	//count.
	int n = 0;
	list[0] = v[N-1];
	num[0]++;
	n++;
	for( int i = N-2; i >= 0; i-- ){
		if( list[n-1] == v[i] ){
			num[n-1]++;
		}else{
			list[n] = v[i];
			num[n]++;
			n++;
		}
	}
	/*
	for( int i = 0; i < n; i++ ){
		std::cout << list[i] << "," << num[i] << std::endl;
	}
	*/
	int k = 0;
	int remain = A;
	int rf = 0;
	while( remain > 0 ){
		if( num[k] <= remain ){
			msum += list[k] * num[k];
			remain -= num[k];
			k++;
		}else{
			msum += list[k] * remain;
			rf = num[k] - remain;
			remain = 0;
		}
	}
	if( rf != 0 && k > 0 ){
		s = combi(num[k],num[k]-rf);
	}else if( rf != 0 && k == 0 ){
		for( int i = A; i <= B; i++ ){
			s += combi(num[k], i);
		}
	}else{
		s = 1;
	}
	//output.
	printf("%.6lf\n", (double)msum/A);
	std::cout << s << std::endl;
	return;
}

int main(){
	input();
	run();
	return 0;
}


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

using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if(a+b>c+d){
        cout<<"Left"<<endl;
    }else if(a+b==c+d){
        cout<<"Balanced"<<endl;
    }else{
        cout<<"Right"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits.h>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>
using namespace std;

int main()  {
     long long n;
     long long  a[100005];
    cin>>n;
    map< long long , long long >ma;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ma[a[i]]++;
    }
    for ( long long i=n-1;i>=1-n%2;i-=2){
        if(ma[i]!=2&&(!(i==0&&ma[i]==1))){
           // cout<<i<<" "<<ma[i]<<endl;
            cout<<0<<endl;
            return 0;
        }
    }
     long long ans=1;
     long long mod=1e9+7;
    for(int i=0;i<n/2;i++){
        ans=(ans*2)%mod;
    }
    cout<<ans<<endl;
}


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

fn main() {
    let o = scan!();
    let e = scan!();
    for i in 0..o.len() {
        print!("{}", o.chars().nth(i).unwrap());
        if i < e.len() {
            print!("{}", e.chars().nth(i).unwrap());
        }
    }
    println!();
}


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

int a, b, c;

int main() {
	scanf("%d %d %d", &a, &b, &c);
	printf("%d", min(min(
	min(abs(abs(a - b) + abs(b - c)), abs(abs(a - c) + abs(c - b))),
	min(abs(abs(b - a) + abs(a - c)), abs(abs(b - c) + abs(c - a)))),
	min(abs(abs(c - a) + abs(a - b)), abs(abs(c - b) + abs(b - a)))));
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

static int N;
static uint8_t S[30000];

static bool fst[10], snd[10], thd[10];

static int fst_cnt, snd_cnt, thd_cnt;

void init() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        S[i] = c - '0';
    }
}

int main() {
    init();

    int count = 0;

    for (int i = 0; i < N - 2 && fst_cnt < 10; i++) {
        if (fst[S[i]])
            continue;

        fst_cnt++;

        fst[S[i]] = true;
        for (int j = i + 1; j < N - 1 && snd_cnt < 10; j++) {
            if (snd[S[j]])
                continue;

            snd[S[j]] = true;
            for (int k = j + 1; k < N && thd_cnt < 10; k++) {
                if (thd[S[k]])
                    continue;

                thd[S[k]] = true;
                count++;
            }
            thd_cnt = 0;
            for (bool &a : thd) a = false;
        }

        snd_cnt = 0;
        for (bool &a : snd) a = false;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256