akhauriyash/Code-Regression huggingface dataset:
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    ts = sum(a) - sum(a[1::2]) * 2
    ls = [0] * n
    ls[0] = ts
    for i in range(1, n):
        ls[i] = (a[i-1] - ls[i-1] // 2) * 2
    print(*ls)


if __name__ == '__main__':
    slove()


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


int main(){
    double PI = acos(-1);
    double R;
    cin >> R;

    printf("%.20f\n", 2.0*R*PI);
    return 0;
}

Measured memory_bytes: 3788
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

def main():
    a,b = map(int,input().split())
    a_set = set(prime_factor(a))
    b_set = set(prime_factor(b))
    c_set = a_set & b_set
    print(len(c_set)+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include <bits/stdc++.h>
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int lli;
lli gcd(lli a, lli b){
    return !b? a : gcd(b, a % b);
}
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
lli f(lli n){
    if(n < 2)return 1;
    return n * f(n - 2);
}
void solve(){
    lli n;
    cin >> n;
    if(n & 1){
        cout << 0 << endl;
        return;
    }
    lli ten = 10;
    lli ans = 0;
    lli cnt = 1;
    while(ten <= n){
        ans += (((n / ten)));
        ten *= 5;
        cnt++;
    }
    cout << ans << endl;
}
int main(){
    
    fastio
    solve();

    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
  double x[10];
  char u[10];
  int N, i;
  double count;
  
  scanf("%d", &N);
  
  for (i = 0; i < N; i++) {
  	scanf("%lf %s", &x[i], &u[i]);
  }
  
  for (i = 0; i < N; i++) {
  	count += (u[i] == 'J' ? x[i] : x[i] * 380000.0);
  }
  
  printf("%lf", count);
  
  return 0;
}

Measured memory_bytes: 128
S=str(input())
if S=='SUN':
  print(str(7))
elif S=='MON':
  print(str(6))
elif S=='TUE':
  print(str(5))
elif S=='WED':
  print(str(4))
elif S=='THU':
  print(str(3))
elif S=='FRI':
  print(str(2))
else:
  print(str(1))

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

int main()
{
    map<string, int> mp;
    int i, N;
    cin >> N;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    for(i=0;i<N;i++)
    {
      string S;
      cin >> S;
      mp[S]++;
    }

      cout<< "AC"<<" x "<<mp["AC"]<<endl;
      cout<< "WA"<<" x "<<mp["WA"]<<endl;
      cout<< "TLE"<<" x "<<mp["TLE"]<<endl;
      cout<< "RE"<<" x "<<mp["RE"]<<endl;

    return 0;

}


Measured memory_bytes: 3636
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int itemNum, popItemNum, totalVotes = 0;
    int votesArray[100];
    double winVotes = 0;
    
    scanf("%d %d", &itemNum, &popItemNum);
    
    // Counting total number of votes, also creating an array with partial votes
    for(int i = 0; i < itemNum; i++)
    {
        int partVotes;
        scanf("%d", &partVotes);
        totalVotes += partVotes;
        votesArray[i] = partVotes;
    }
    
    winVotes = totalVotes * (1.0 / (4 * popItemNum));
    
    /* Using popItemNum(M) as counter to judge if the requirement of task is fulfilled.
     If goes beyond 0, then it means M popular items can be selected. */
    
    for(int i = 0; i < itemNum; i++)
    {
        if(votesArray[i] >= winVotes)
        {
           popItemNum--;
        }
    }
    
    if(popItemNum <= 0)
    {
        printf("Yes \n");
    }
    else
    {
        printf("No \n");
    }
    
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<double,double> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<bool> eratosthenes(int n){
    vector<bool> prime(n,true);
    prime[0]=false;prime[1]=false;
    for(int i=2;i<=n;i++){
        if(prime[i]){
            for(int j=i*2;j<=n;j+=i){
                prime[j]=false;
            }
        }
    }
    return prime;
}
int main(){
    vector<bool> p=eratosthenes(60000);
    int n;
    while(cin>>n){
        for(int i=n-1;i>=0;i--){
            if(p[i]){
                cout<<i<<" ";
                break;
            }
        }
        for(int i=n+1;i<=60000;i++){
            if(p[i]){
                cout<<i<<endl;
                break;
            }
        }
    }
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    if(K == 1) cout << 0;
    else cout << N - K;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int dp[10001];
int main(void){
  char s[100001];
  scanf("%s",s);
  int a[2]={0,0};
  FOR(strlen(s))a[s[i]-'0']++;
  PRN(min(a[0],a[1])*2);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            int n = scanner.nextInt();
            int q = scanner.nextInt();
            String s = scanner.next();

            int[] sum = new int[s.length()];
            for(int i = 1; i < s.length(); i++) {
                sum[i] = sum[i - 1];
                if (s.charAt(i - 1) == 'A' && s.charAt(i ) == 'C') {
                    sum[i]++;
                }
            }
            for (int i = 0; i < q; i++) {
                int L = scanner.nextInt();
                int R = scanner.nextInt();
                // ACACTACG
                // 01234567
                // 01122233
                System.out.println(sum[R - 1] - sum[L - 1]);
            }
        }
    }
}


Measured memory_bytes: 69596
class Node():
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None


class BinarySearchTree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        root_node = self.root
        insert_node = Node(key)
        parent_node = None

        while root_node:
            parent_node = root_node
            if insert_node.key < root_node.key:
                root_node = root_node.left
            else:
                root_node = root_node.right

        insert_node.parent = parent_node

        if parent_node is None:
            self.root = insert_node
        elif insert_node.key < parent_node.key:
            parent_node.left = insert_node
        else:
            parent_node.right = insert_node

    def show_preorder(self, node):
        node_list = []

        node_list.append(node.key)
        if node.left is not None:
            node_list.extend(self.show_preorder(node.left))
        if node.right is not None:
            node_list.extend(self.show_preorder(node.right))

        return node_list

    def show_inorder(self, node):
        node_list = []

        if node.left is not None:
            node_list.extend(self.show_inorder(node.left))
        node_list.append(node.key)
        if node.right is not None:
            node_list.extend(self.show_inorder(node.right))

        return node_list

    def print(self):
        print(' ' + ' '.join(map(str, self.show_inorder(self.root))))
        print(' ' + ' '.join(map(str, self.show_preorder(self.root))))


if __name__ == '__main__':
    tree = BinarySearchTree()

    n = int(input())

    for i in range(n):
        command = input().split()

        if command[0] == 'insert':
            tree.insert(int(command[1]))
        elif command[0] == 'print':
            tree.print()

Measured memory_bytes: 189664
/* ***********************************************
Author        :yang12138
Created Time  :2017年12月29日 星期五 17时17分31秒
File Name     :C.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=2e5+10;

int bit[N];

void add(int i,int d){
	while(i<N){
		bit[i]+=d;
		i+=i&-i;
	}
}

int sum(int i){
	int ans=0;
	while(i){
		ans+=bit[i];
		i-=i&-i;
	}
	return ans;
}

char s[N];
int cnt[26];
int pos[26][N];
bool vis[N];

void solve(){

	scanf("%s",s+1);
	int len=strlen(s+1);

	for(int i=1;i<=len;i++){
		int ch=s[i]-'a';
		cnt[ch]++;
		pos[ch][++pos[ch][0]]=i;
		add(i,1);
	}

	int num=0;
	for(int i=0;i<26;i++){
		num+=cnt[i]&1;
	}
	if(num>1){
		printf("-1\n");
		return ;
	}

	ll ans=0;

	for(int i=1;i<=len;i++){
		if(vis[i]) continue;

		int ch=s[i]-'a';
		int nex=pos[ch][pos[ch][0]--];
		if(nex==i){
			ans+=(sum(len)-1)/2;
			add(nex,-1);
		}
		else{
			ans+=sum(len)-sum(nex);
			add(i,-1),add(nex,-1);
		}
		vis[i]=vis[nex]=1;
	}
	cout<<ans<<endl;

}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


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

int main(){
    int N, count = 0;
    cin >> N;
    vector<int> m(N);
    vector<int> single;
    for(int i = 0; i < N; i++) cin >> m.at(i);
    single.push_back(m.at(0));

    for(int j : m){
        bool a = true;
        for(int k : single){
            if(j == k) a = false;
        }
        if(a == true) single.push_back(j);
    }

    cout << single.size() << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val x = readInt
  if (x == 1) {
    println(0)
  } else {
    println(1)
  }
}

trait StdInHelper {
  def readStrings = readLine.split(" ")
  def readInts = readStrings.map(_.toInt)
  def readLongs = readStrings.map(_.toLong)
  def readDoubles = readStrings.map(_.toDouble)
  def readBigInts = readStrings.map(BigInt.apply(_))
  def readBigDecimals = readStrings.map(BigDecimal.apply(_))
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


signed main(){

	lli n;
	cin>>n;
	vector<lli> p(n),q(n);
	REP(i,0,n)cin>>p[i];
	REP(i,0,n)cin>>q[i];

	vector<lli> a(n);

	REP(i,0,n)a[i] = i+1;

	lli cnt=1;
	lli aNum,bNum;

	do{
		bool aFlag=true,bFlag=true;
		REP(i,0,n){
			if(p[i]!=a[i]){
				aFlag=false;
				break;
			}
		}
		if(aFlag){
			aNum = cnt;
		}

		REP(i,0,n){
			if(q[i]!=a[i]){
				bFlag=false;
				break;
			}
		}
		if(bFlag){
			bNum = cnt;
		}
		cnt++;
	}while(next_permutation(a.begin(),a.end()));

	cout<<abs(aNum-bNum)<<endl;
	return 0;
}

Measured memory_bytes: 256
function main()
	n = parse.(split(readline()))
	x = n[2]
	min = 1000
	for i in 1:n[1]
		m=parse(readline())
		if m < min
			min = m
		end
		x -= m
	end
	y = x%min
	z = convert(Int, (x-y)/min)
	print(z+n[1])
end

main()

Measured memory_bytes: 173460
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int mod=1000000007;
ll dp[2002][2002];
int n,m;
int s[2002],t[2002];
int main(){
    cin>>n>>m;
    rep(i,n) cin>>s[i];
    rep(i,m) cin>>t[i];
    rep(i,n+1) dp[i][0]=1;
    rep(i,m+1) dp[0][i]=1;
    rep(i,n)rep(j,m){
        dp[i+1][j+1]=dp[i+1][j]+dp[i][j+1]+mod-dp[i][j]%mod;
        if(s[i]==t[j]){
            dp[i+1][j+1]+=dp[i][j]%mod;
        }
        dp[i+1][j+1]%=mod;
    }
    cout<<dp[n][m]<<endl;
    return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

bool cmp(pll a, pll b) {
  if (a.first + a.second != b.first + b.second) {
    return a.first + a.second < b.first + b.second;
  }
  else {
    return a.second < b.second;
  }
}

int main() {
  int n;
  cin >> n;
  vector<pll> hp(n);
  rep (i, n) {
    cin >> hp[i].first >> hp[i].second;
  }
  sort(all(hp), cmp);
  vll dp(n + 1, vl(n + 1, INF));
  dp[0][0] = 0;
  rep (i, n) {
    rep (j, n + 1) {
      if (dp[i][j] == INF) {
        continue;
      }
      chmin(dp[i + 1][j], dp[i][j]);
      if (dp[i][j] <= hp[i].first) {
        chmin(dp[i + 1][j + 1], dp[i][j] + hp[i].second);
      }
    }
  }
  rrep (i, n + 1) {
    if (dp[n][i] != INF) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 195968
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
typedef long long ll;
double *dp;




void solve(){
	
	int  N;
	int ans = 0;
	int *L;
	cin >> N;
	L = new int[N];
	for (int i = 0;i < N;i++)cin >> L[i];

	sort(L, L + N);

	for (int i = 0;i < N;i++) {
		for (int j = 0;j < i;j++) {
			for (int k = 0;k < j;k++) {
				if (L[j] + L[k] > L[i])ans++;
			}
		}
	}
	cout<<ans << endl;
	
}


int main() {
	solve();

}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

// ここまで

use std::io::Write;

fn root(p: &Vec<i32>, mut x: usize) -> usize {
    while p[x] >= 0 {
        x = p[x] as usize;
    }
    x
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1, u64); m],
        q: usize,
        p: [(usize1, usize1); q],
    }
    let mut e = e;
    e.sort_by(|a, b| a.2.cmp(&b.2));
    let mut parent = vec![-1; n];
    let mut cost = vec![1000000000 + 1; n];
    let mut sum = 0;
    for (a, b, c) in e {
        let mut a = root(&parent, a);
        let mut b = root(&parent, b);
        if a == b {
            continue;
        }
        sum += c;
        if parent[a] > parent[b] {
            std::mem::swap(&mut a, &mut b);
        }
        parent[a] += parent[b];
        parent[b] = a as i32;
        cost[b] = c;
    }
    for (mut s, mut t) in p {
        let mut ans = 0;
        while s != t {
            if cost[s] < cost[t] {
                ans = cost[s];
                s = parent[s] as usize;
            } else {
                ans = cost[t];
                t = parent[t] as usize;
            }
        }
        writeln!(out, "{}", sum - ans).unwrap();
    }
}

fn main() {
    run();
}


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

int main(){
  ll H,W;cin >> H >> W;
  if(H==1||W==1){
    cout << 1 << endl;
    return 0;
  }
  if(H%2>0&&W%2>0){
    ll ans = H*W+1;
    cout << ans/2<< endl;
  }else{
    cout << H*W/2 << endl;
  }
}

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

const int maxn = 1e5 + 5;

int n, k, a, b, v, p, reqparity[2][maxn];
vector<int> adj[maxn];
vector<pii> mivals[maxn], mavals[maxn]; // {mi / ma, from}

void up(int x, int p)
{
    for(auto v : adj[x])
        if(v != p)
        {
            up(v, x);
            mivals[x].push_back({mivals[v][0].first - 1, v});
            mavals[x].push_back({mavals[v][0].first + 1, v});
            for(int j = 0; j < 2; j++)
                reqparity[j][x] |= reqparity[j ^ 1][v];
        }
    nth_element(mivals[x].begin(), mivals[x].begin(), mivals[x].end(), greater<pii>());
    nth_element(mavals[x].begin(), mavals[x].begin(), mavals[x].end());
    // sort(mivals[x].begin(), mivals[x].end(), greater<pii>());
    // sort(mavals[x].begin(), mavals[x].end());
}

void down(int x, int p, int parmi, int parma)
{
    if(p != -1)
    {
        mivals[x].push_back({parmi - 1, p});
        mavals[x].push_back({parma + 1, p});
        for(int j = 0; j < 2; j++)
            reqparity[j][x] |= reqparity[j ^ 1][p];
        nth_element(mivals[x].begin(), mivals[x].begin() + 1, mivals[x].end(), greater<pii>());
        nth_element(mavals[x].begin(), mavals[x].begin() + 1, mavals[x].end());
        // sort(mivals[x].begin(), mivals[x].end(), greater<pii>());
        // sort(mavals[x].begin(), mavals[x].end());
    }
    for(auto v : adj[x])
        if(v != p)
        {
            int takemi = -2e9, takema = 2e9;
            for(auto y : mivals[x])
                if(y.second != v)
                {
                    takemi = y.first;
                    break;
                }
            for(auto y : mavals[x])
                if(y.second != v)
                {
                    takema = y.first;
                    break;
                }
            down(v, x, takemi, takema);
        }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 2; j++)
            reqparity[j][i] = 0;
        mivals[i].push_back({-2e9, i});
        mavals[i].push_back({2e9, i});
    }
    for(int i = 0; i < n - 1; i++)
    {
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> k;
    for(int i = 0; i < k; i++)
    {
        cin >> v >> p;
        v--;
        reqparity[p & 1][v] = 1;
        mivals[v].push_back({p, v});
        mavals[v].push_back({p, v});
    }
    up(0, -1);
    down(0, -1, -2e9, 2e9);
    int bad = 0;
    for(int i = 0; i < n; i++)
        if((reqparity[0][i] && reqparity[1][i]) || mivals[i][0].first > mavals[i][0].first)
            bad = 1;
    if(bad)
        cout << "No\n";
    else
    {
        cout << "Yes\n";
        for(int i = 0; i < n; i++)
            cout << mivals[i][0].first << "\n";
    }
    return 0;
}

Measured memory_bytes: 44272
#include "bits/stdc++.h"
using namespace std;

int used[1000010];
int main() {
	while (true) {
		int a, l, ans, res;
		cin >> a >> l;
		if (!a && !l) break;

		vector<int> b, before;
		before.push_back(a);
		for(int i=1; i<21; ++i) {
			b = { 0, 0, 0, 0, 0, 0 };
			b.resize(l);
			string aa = to_string(a);
			for (int j = 0; j < aa.size(); ++j) b[j] = (aa[j] - '0');
			sort(b.begin(), b.end());
			//REP(j, b.size()) cout << b[j] << " "; cout << endl;
			string aamin = "", aamax = "";
			for (int j = 0; j < b.size(); ++j) { aamin += to_string(b[j]); }
			for (int j = 0; j < b.size(); ++j) { aamax += to_string(b[b.size() - j - 1]); }
			for (int j = 0; j < (l - b.size()); ++j) { aamax += '0'; }
			
			a = stoi(aamax) - stoi(aamin);
			
			bool flag = true;
			for (int j = 0; j < before.size(); ++j) {
				if (a == before[j]) {
					ans = j;
					res = i - j;
					flag = false;
				}
			}
			if (!flag)
				break;
			before.push_back(a);
		}

		cout << ans << " " << a << " " << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#include <stdio.h>

void qsort(int a[], int l, int r) {
  int il = l, ir = r, p = a[(il+ir)/2];
  if (l < r) {
    while (1) {
      while (a[il] > p) {
        il++;
      }
      while (a[ir] < p) {
        ir--;
      }

      if (il > ir) {
        break;
      }
      int tmp;
      tmp = a[il];
      a[il] = a[ir];
      a[ir] = tmp;
      il++;
      ir--;
    }

    qsort(a, l, ir);
    qsort(a, il, r);
  }
}


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

  int i, a[100] = {};
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  qsort(a, 0, n);

  int s = 0;
  for (i = 0; i < n; i++) {
    if (i % 2  == 0) {
      s += a[i];
    } else {
      s -= a[i];
    }
  }

  printf("%d\n", s);

  return 0;
}


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

int main(){
    int n;
    int a[100];

    int mini, maxi;

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

    if (a[0] < a[1]){
        mini = a[0];
        maxi = a[1];
    }else{
        mini = a[1];
        maxi = a[0];
    }

    for(int i = 2; i < n; i++){
        if (a[i] < mini){
            mini = a[i];
        }
        if (a[i] > maxi){
            maxi = a[i];
        }
    }
    cout << maxi - mini;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

N, K = map(int, input().split())
td = [[int(i) for i in input().split()] for _ in range(N)]

counter = [0] * (N + 1)
h = []
for t, d in td :
    counter[t] += 1
    heappush(h, (d, d, t))

kind = len(set(t for t, d in td))
for _ in range(N - K) :
    while True :
        _, d, t = heappop(h)
        if counter[t] == 1 :
            loss = kind * kind - (kind - 1) * (kind - 1) + d
            if loss <= h[0][0] :
                counter[t] -= 1
                kind -= 1
            else :
                heappush(h, (loss, d, t))
                continue
        else :
            counter[t] -= 1
        
        break
        
print(sum(d for _, d, t in h) + kind * kind)

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

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int  main() {
	
	int n, ans = 0;
	int s[110];

	cin >> n;

	rep(i, n) {
		cin >> s[i];
		ans += s[i];
	}

	sort(s, s + n);
	
	if (ans % 10 != 0) {
		pr(ans);
		return 0;
	}
	else {
		for (int i = 0; i < n; i++) {
			if (i == n - 1)ans = 0;
			if (s[i] % 10 == 0)continue;
			ans -= s[i];
			break;
		}
	}
	pr(ans);

	return 0;

}

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

int main() {
  string S;
  cin >> S;
  
  if (S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if (S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}



Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define INF 105

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);  
    string a;
    cin >> a;
    char c=a[a.size()-1];
    if(c=='2' || c=='4' || c=='5' || c=='7' || c=='9')
    {
    	cout << "hon" << endl;	
    }else
    if(c=='0' || c=='1' || c=='6' || c=='8')
    {
    	cout << "pon" << endl;
    }else
    {
    	cout << "bon" << endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n;
    cin >> n;
    int ans = 0;
    int a = 0,b = 0,c = 0;//a:B*A, b:B**, c:**A
    rep(i,n){
        string s;
        cin >> s;
        rep(i,s.size()-1){
            if(s.substr(i,2) == "AB")ans++;
        }
        if(s.front() == 'B' && s.back() == 'A')a++;
        else if(s.front() == 'B')b++;
        else if(s.back() == 'A')c++;
    }
    //cout << ans << " " << a << " " << b << " " << c << endl;
    if(a == 0){
        ans += min(b,c);
    }else{
        if(b+c > 0)ans += a + min(b,c);
        else ans += a-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,Q,top;
ll st[101000],p[101000],h[101000];
int main(){
	read(n);read(Q);
	st[++top]=n;
	for(int i=1;i<=Q;i++){
		ll x;read(x);
		while(top>0&&st[top]>=x) top--;
		st[++top]=x;
	}
	p[top]=1;
	for(int i=top;i>1;i--){
		ll now=st[i];
		int k=lower_bound(st+1,st+top+1,now)-st-1;
		while(k){
			p[k]+=(now/st[k])*p[i];
			now%=st[k];
			k=lower_bound(st+1,st+top+1,now)-st-1;
		}
		if(now) h[now]+=p[i];
	}
	h[st[1]]+=p[1];
	for(int i=st[1]-1;i;i--) h[i]+=h[i+1];
	for(int i=1;i<=n;i++) cout<<h[i]<<'\n';
	return 0;
}

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

int main() {
	
	int H,W,Total,i,h,w,total,hashWidth;
	
	cin >> H;
	cin >> W;
	
	Total = H*W;
	i=0;
	
	h=H;
	w=W;
	total=Total;
	hashWidth= W+2;
	
	char myArray[h][w];
	
	while(h--){
		while(w--){
			cin >> myArray[h][w];		
		}
		w=W;
	}
	
	h=H;
	w=W;
	i=0;
	
	total = Total + 2;
	
	while(hashWidth--){
		cout << "#";
	}
	cout << endl;
	total = Total;
	hashWidth = W + 2;
	while(h--){
		cout << "#";
		while(w--){
			cout << myArray[h][w];		
		}
		cout << "#" <<endl;
		w=W;
	}
	
	while(hashWidth--){
		cout << "#";
	}
	
	return 0;
}


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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	TLong n,a[200];
	TLong c = 1,s = 0;
	scanf("%lld",&n);
	for (TLong i = 0; i < n; ++i){
		scanf(" %lld",&a[i]);
	}
	while(c){
		for (TLong i = 0; i < n; ++i){
			if(a[i] % 2)	c = 0;
		}
		if(c){
			for (TLong i = 0; i < n; ++i)	a[i] /= 2;
			++s;
		}
	}
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
  int a,b;
  int n,i;
  
  scanf("%d %d",&a,&b);
  
  for(i=1;i<=10000;i++){
    if((int)(i*0.08)==a && (int)(i*0.10)==b){
      printf("%d",i);
      return 0;
    }
  }
  
  printf("-1");
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int r, c, i, j;
  int table[100 + 1][100 + 1] = {0};
  scanf("%d %d", &r, &c);

  // input and calculation
  for(i = 0; i < r; i++){
    for(j = 0; j < c; j++){
      scanf("%d", &table[i][j]);
      table[i][c] += table[i][j];
      table[r][j] += table[i][j];
    }
    table[r][c] += table[i][j];
  }
    
  // output
  for(i = 0; i < r + 1; i++){
    for(j = 0; j < c + 1; j++){
      if(j)
	printf(" ");
      printf("%d", table[i][j]);
    }
    printf("\n");
  }

  return 0;
}

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

int main(){
    ll L, R; cin >> L >> R;
    ll ans=2019;
    
    if(R-L > 2100){
        cout << 0 << endl;
    }

    else{

       for(ll i=L; i<R; i++){
          for(ll j=L+1; j<=R; j++){
              ans= min(ans, (i*j)%2019);
          }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int mincost(int a[],int n,int k,int dp[])
{
    if(n==0||n==1)return 0;

    else if(dp[n]!=-1)return dp[n];
    else
    {
        int ans=INT_MAX;
        for(int i=1;i<=k;i++)
        {
            if(n-i>=1)
            {
                if(ans>(abs(a[n]-a[n-i])+mincost(a,n-i,k,dp)))
                    ans=abs(a[n]-a[n-i])+mincost(a,n-i,k,dp);
            }
            else break;
        }
        dp[n]=ans;
    }
    return dp[n];


}
/*int mcbottomup(int a[],int n)
{
    int pp;
   int p=0;
   int pnt=abs(a[2]-a[1]);


    for(int i=3;i<=n;i++)
    {
        pp=p;
        p=pnt;
        pnt=min(abs(a[i]-a[i-1])+p,abs(a[i]-a[i-2])+pp);
    }
    return pnt;
}*/
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+1],dp[n+1];
    for(int i=1;i<=n;i++){cin>>a[i];dp[i]=-1;}
    cout<<mincost(a,n,k,dp);
    return 0;
}


Measured memory_bytes: 10368
import copy
h,w,k = map(int,input().split())

C = []
for _ in range(h):
    C.append(list(str(input())))

def sw(temp,n,b):
    if n == w:
        count = 0
        for c in temp:
            count += c.count("#")
        if count == k:
            return 1
        else:
            return 0
    else:
        temp1 = copy.deepcopy(temp)
        temp2 = copy.deepcopy(temp)
        if b == True:
            for i in range(h):
                temp1[i][n] = "2"
                temp2[i][n] = "2"

        return(sw(temp1,n+1,True)+sw(temp2,n+1,False))

def sh(temp,n,b):
    if n == h:
        temp1 = copy.deepcopy(temp)
        temp2 = copy.deepcopy(temp)
        return(sw(temp1,0,True)+sw(temp2,0,False))
    else:
        temp1 = copy.deepcopy(temp)
        temp2 = copy.deepcopy(temp)
        if b == True:
            temp1[n] = ["2"]*w
            temp2[n] = ["2"]*w
        return(sh(temp1,n+1,True)+sh(temp2,n+1,False))

print(int((sh(C,0,True) + sh(C,0,False))/4))

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

int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M + 1), B(M + 1), H(N + 1), ans(N + 1);
    ans.at(0) = 0;
    for(ll i = 1; i <= N; i++){
        cin >> H.at(i);
        ans.at(i) = 1;
    }
    for(ll i = 1; i <= M; i++){
        cin >> A.at(i) >> B.at(i);
    }
    for(ll i = 1; i <= M; i++){
        if(H.at(A.at(i)) < H.at(B.at(i))){
            ans.at(A.at(i)) = 0;
        }
        else if(H.at(A.at(i)) > H.at(B.at(i))){
            ans.at(B.at(i)) = 0;
        }
        else{
            ans.at(A.at(i)) = 0;
            ans.at(B.at(i)) = 0;
        }
    }
    ll a = 0;
    for(ll i = 1; i <= N; i++){
        if(ans.at(i) == 1){
            a++;
        }
        //cout << ans.at(i) << endl;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 6424
#include<stdio.h>
#define N 20
#define Q 200
int a,b,c[N],d[Q],i;

int solve(int a,int b);

int main(){
  int res;
  
  scanf("%d",&a);
  for(i=0;i<a;i++)scanf("%d",&c[i]);
   scanf("%d",&b);
  for(i=0;i<b;i++)scanf("%d",&d[i]);

  for(i=0;i<b;i++){res=solve(0,d[i]);
    if(res==1)printf("yes");
    else printf("no");
    printf("\n");
    }
}
int solve(int j,int d){
  int ans;
  if(d==0)return 1;
  if(j>=a)return 0;
  ans=solve(j+1,d)|| solve(j+1,d-c[j]);
  return ans;
}



Measured memory_bytes: 2048
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(ll i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N;
int MAX_N = 10;

// 1234 -> 4 3 2 1
vector<int> each_digit(ll S) {
    int n_len = 0, n_dig[MAX_N];
    while (S > 0) {
        n_dig[n_len++] = S % 10;
        S /= 10;
    }
    vector<int> ret(n_dig, n_dig + n_len);
    return ret;
}

void solve() {
    ll ans = INF;
    int n_dig = each_digit(N).size();
    REPONE(i, pow(10, 6)) {
        if (N % i == 0) ans = min(ans, max(i, N / i));
    }
    vector<int> v = each_digit(ans);
    cout << v.size() << endl;
}

int main() {
    cin >> N;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n,a,f=1;
        cin >> n;
        for(int i=0;i<n;i++){
                cin >> a;
                if(a%2)continue;
                else if(a%3&&a%5){
                        f=0;
                        break;
                }
        }
        cout << (f?"APPROVED":"DENIED") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, m;
int main()
{
#ifdef _noname
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m;
	if (n > m) swap(n, m);
	if (m == 1) cout << 1 << endl;
	else if (n == 1) cout << m - 2 << endl;
	else cout << n * m - (n + m) * 2 + 4 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String nstr = br.readLine();
		int n = Integer.parseInt(nstr);

		int sn = 0;

		for (int i = 0; i < nstr.length(); i++) {
			sn += nstr.charAt(i) - '0';
		}

		if (n % sn == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


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

int main(){
    long long N,M;
    long long count = 0;
    cin >> N >>M;
    if(M > 2*N){
        count += N;
        M -= 2*N;
    }
    else if (M < 2*N){
        count += M/2;
        M = M%2;
    }

    while (M>=4){
        count ++;
        M -=4;
    }
    cout << count;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pa;
string s;
long long ans;
void go(int x, ll y, ll z) {
	if (x == s.size()) {
		ans += y + z; return;
	}
	go(x + 1, s[x] - '0', z + y);
	go(x + 1, y * 10 + (s[x] - '0'), z);
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	cin >> s;
	go(1, s[0] - '0', 0);
	cout << ans << '\n';


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main() { //int argc, const char * argv[]

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, tmp;
    cin >> n;
    int a[n];
    a[0] = 0;
    string ans = "YES";

    REP(i, n){
        cin >> tmp;
        a[i] = tmp;
    }

    sort(a, a + n);
    int b[n-1];
    REP(i, n-1){
        if(a[i+1] -a[i] == 0){
            ans = "NO";
        }
    }

    cout << ans;
    
}


Measured memory_bytes: 1024
// ?????¬???????????¬?????? (define int long long ?????????)

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool ans;
int a[10];
void dfs(int idx, int l, int r) {
    if(idx == 10) {
        ans = true;
        return;
    }

    int val = a[idx];
    if(l < val) dfs(idx+1, val, r);
    if(r < val) dfs(idx+1, l, val);
}

int main() {
    int N; cin >> N;
    while(N--) {
        ans = false;
        rep(i,0,10) cin >> a[i];
        dfs(0, -1, -1);
        cout << (ans ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 3040
<?php

while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%d', $n);
    for ($a = 0, $cnt = 0; $a < 10; $a++) {
        if ($a > $n) {
            continue;
        }
        for ($b = 0; $b < 10; $b++) {
            if ($a + $b > $n || $a + $b + 18 < $n) {
                continue;
            }
            for ($c = 0; $c < 10; $c++) {
                $d = $n - ($a + $b + $c);
                if ($d >= 0 && $d < 10) {
                    $cnt++;
                }
            }
        }
    }

    echo $cnt, PHP_EOL;
}

Measured memory_bytes: 6588
#include <iostream>
using namespace std;
int main(void){
    int N,A,tmp,ans = 100000;
    cin >> N;
    
    if(N % 2 == 1){
        A = (N - 1)/2;
        for(int i = 1;i <= A;i++){
            int x = 0,y = 0;
            int j = i;
            int k = N - i;
            while(j > 0){
                x += j % 10;
                j /= 10;
            }
            while(k > 0){
                y += k % 10;
                k /= 10;
            }
            tmp = x + y;
            if(ans > tmp){
                ans = tmp;
            }
        }
    }
    
     if(N % 2 == 0){
        A = N / 2;
        for(int i = 1;i <= A;i++){
            int x = 0,y = 0;
            int j = i;
            int k = N - i;
            while(j > 0){
                x += j % 10;
                j /= 10;
            }
            while(k > 0){
                y += k % 10;
                k /= 10;
            }
            tmp = x + y;
            if(ans > tmp){
                ans = tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll t=b-a-1;
	printf("%lld",t*(t+1)/2-a);
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

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

	int n = 3;
	while (n <= sqrt(x)) {
		if (x % n == 0)
			return false;
		n += 2;
	}
	return true;
}

int main() {

	int n;
	scanf("%d", &n);
	int x[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x[i]);
	}

	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (isPrime(x[i])) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3208
//AGC C
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const string S4[4] = {"abcc", "abdd", "ccab", "ddab"};
const string S5[5] = {"abbcc", "ad..a", "bd..a", "b.eez", "oorrz"};
const string S6[6] = {"oorrzz", ".a.b.c", ".a.b.c", "d.e.f.", "d.e.f.", "oorrzz"};
const string S7[7] = {".oorrzz", "oabb...", "oa.c...", "rddc...", "r...abb", "z...a.c", "z...ddc"};

char s[1010][1010];

inline void solve(int&n, int x) {
	if(x == 4)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S4[i][j];
	if(x == 5)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S5[i][j];
	if(x == 6)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S6[i][j];
	if(x == 7)
		for(int i = 0; i < x; i++)
			for(int j = 0; j < x; j++)
				s[n + i][n + j] = S7[i][j];
	n += x;
}

int main() {
	int n = ri;
	if(n <= 2) return puts("-1"), 0;
	if(n == 3) {
		puts("a..");
		puts("a..");
		puts(".bb");
		return 0;
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			s[i][j] = '.';
	int x = n % 4, N = 1;
	if(x == 0) solve(N, 4);
	if(x == 1) solve(N, 5);
	if(x == 2) solve(N, 6);
	if(x == 3) solve(N, 7);
	while(N <= n) solve(N, 4);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++)
			putchar(s[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2176
// I have to work harder than anyone else to make it! I’ll never catch up otherwise… 

// ICPC next year.

#include<bits/stdc++.h>
using namespace std;

#define P pair<int,int>
#define P pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define str std::string 
#define pb push_back 
#define ll long long
#define pq(x) std::priority_queue<x> 
#define ultapq(x) priority_queue<x,vector<x>,greater<x>> 
#define show_pq(x) for(int i = 0; i < n; i++){cout<<yes.top(); yes.pop();} 
#define itrt(yo) for(auto x:yo){std::cout<<x<<nl;} 
#define vec(x) std::vector<x> 
#define nl '\n' 
#define DRI(X) ll (X); scanf("%lld", &X)
#define DRII(X, Y) ll X, Y; scanf("%lld%lld", &X, &Y)
#define DRIII(X, Y, Z) ll X, Y, Z; scanf("%lld%lld%lld", &X, &Y, &Z)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define F first
#define S second
#define ALL(x) x.begin(),x.end() 
#define BN(x) x.begin()
#define ED(x) x.end()
#define MAP_traverse(it,x)  for(auto it = BN(x); it!= ED(x); it++)
#define PI 3.14159265358979323846264338327950L
const unsigned int M = 1000000007;



int main()
{
	IOS;
	char a;
	cin>>a;
	if (a>=97 && a<=122)
	{
		cout<<"a";
	}else
	{
		cout<<"A";
	}
	
	
	
	
}

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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int tree[1200010];
int tab[300010];

void upd(int node,int l,int r,int val,int ix)
{
    if (l == r)
    {
        tree[node] = val;
        return;
    }
    int mid = (l + r) >> 1;
    int child = node << 1;
    if (ix > mid)
        upd(child | 1,mid + 1,r,val,ix);
    else
        upd(child,l,mid,val,ix);
    tree[node] = max(tree[child],tree[child | 1]);
}

int rangeQuery(int node,int nodeL,int nodeR,int queryL,int queryR)
{
    if (queryL > nodeR || queryR < nodeL) return -INF;
    if (queryL <= nodeL && nodeR <= queryR) return tree[node];
    int mid = (nodeL + nodeR) >> 1;
    int child = node << 1;
    return max(rangeQuery(child,nodeL,mid,queryL,queryR),rangeQuery(child | 1,mid + 1,nodeR,queryL,queryR));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 1 ; i <= n ; i++)
    {
        int ta;
        cin >> ta;
        int l = max(ta - k,1);
        int r = min(ta + k,300000);
        int tmp = rangeQuery(1,1,300000,l,r) + 1;
        // cout << ta << " " << l << " " << r << " " << tmp << endl;
        ans = max(ans,tmp);
        upd(1,1,300000,tmp,ta);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7760