akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n][3],dp[n][3],max1=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
    }
    for(int i=0;i<3;i++)
    {
        max1=max(dp[n-1][i],max1);


    }
    cout<<max1;


}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

vector<int> g[200200];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int left=1,right=n;
    while(right>left){
        int mid=(left+right)/2;
        vector<pair<int,int>> v;
        bool ok=true;
        for(int i=0;i<n;i++){
            int dif=a[i];
            if(i){
               dif-=a[i-1];
            }
            if(dif>0){
                v.push_back(make_pair(0,dif));
                continue;
            }
            while(dif<0){
                int take=min(v.back().second,-dif);
                dif+=take;
                v.back().second-=take;
                if(v.back().second==0){
                    v.pop_back();
                }
            }
            int k=0;
            while(v.size()&&v.back().first==mid-1){
                k+=v.back().second;
                v.pop_back();
            }
            if(v.empty()){
                ok=false;
                break;
            }
            int x=v.back().first;
            v.back().second--;
            if(v.back().second==0){
                v.pop_back();
            }
            v.push_back(make_pair(x+1,1));
            if(k>0){
                v.push_back(make_pair(0,k));
            }
        }
        if(ok){
            right=mid;
        }
        else{
            left=mid+1;
        }
    }
    cout << left << endl;
}

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

int main()
{
    long long int n,r,m=0,g=0,k=0;
    cin>>n;
    long long int a[n];
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        m+=a[i];
    }
    double av=m/n;
    int d=av,e=av+1;
    for(long long int i=0;i<n;i++)
    {
        g+=(d-a[i])*(d-a[i]);
        k+=(e-a[i])*(e-a[i]);
    }
    cout<<min(g,k)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<stdio.h>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };
int a[114514], b[114514];
int uh[114514], uw[114514];
vector<P>V;
signed main() {
	int h, w; cin >> h >> w;
	rep(i, h)cin >> a[i];
	rep(i, w)cin >> b[i];
	rep(i, h) { V.push_back(P(a[i], i)); }
	rep(j, w) { V.push_back(P(b[j], j+inf)); }
	sort(V.begin(), V.end());
	int sum = 0;
	int nh = h, nw = w;
	rep(i, V.size()) {
		int f = V[i].first, s = V[i].second;
		if (s >= inf) {
			s -= inf;
			sum += nh*f;
			nw--;
		}
		else {
			sum += nw*f;
			nh--;
		}
	
	}
	cout << sum << endl;
}


Measured memory_bytes: 8520
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		double r = sc.nextDouble();
		sc.close();
		
		String m = String.format("%.6f", r * r * Math.PI);
		String s = String.format("%.6f", r * 2 * Math.PI);
		
		System.out.println(m + " " + s);
		
	}

}

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

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


void main() {
    int n, m;
    scan(n, m);

    auto p = readln.split.to!(int[]);
    p[] -= 1;

    auto uf = UnionFind(n);

    foreach (i ; 0 .. m) {
        int xi, yi;
        scan(xi, yi);
        xi--, yi--;
        uf.merge(p[xi], p[yi]);
    }

    int ans;

    foreach (i ; 0 .. n) {
        ans += uf.same(i, p[i]);
    }

    writeln(ans);
}


struct UnionFind {
    private {
        int _size;
        int[] _parent;
    }

    this(int N) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void merge(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
    }
}




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

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

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


Measured memory_bytes: 4924
#include <iostream>

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

using namespace std;

int V[51];
int N;

int main(void) {

	scanf("%d", &N);
	REP(i, 0, N) scanf("%d", &V[i]);

	int no = 0;

	REP(i, 0, N) if ( V[i] != i + 1 ) no++;

	if ( no == 2  || no == 0 ) printf("YES\n");
	else printf("NO\n");

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<stack>
#include<sstream>
#include<fstream>
#include<string>
#include<assert.h>
//#include<Eigen/Dense>
//using namespace Eigen;
using namespace std;

typedef long long ll;

ll a[3];
int main()
{
	while (cin >> a[0] >> a[1] >> a[2]) {
		ll temp = abs(a[0]) / a[2];

		if (a[1] <= temp)
			cout << abs(abs(a[0]) - a[1] * a[2]) << endl;
		else {
			ll add = a[1] - temp;
			if(add & 1)
				cout << abs(abs(a[0]) - (temp+1) * a[2]) << endl;
			else 
				cout << abs(abs(a[0]) - temp * a[2]) << endl;

		}
	}
	return 0;

}




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

using namespace std;
typedef long long LL;

int main(){
  LL N;
  cin >> N;
  if(N<10){
    cout << N << endl;
    return 0;
  }
  string S=to_string(N);
  LL d=pow(10,S.size()-1);
  int ans=0;
  if((N+1)%d==0){
    rep(i,S.size()) ans+=S[i]-'0';
  }
  else{
    ans=(S[0]-'0'-1)+(S.size()-1)*9;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);


 
    int d, n;
    cin >> d >> n;
    if(d == 0) {
        if(n % 100 == 0)
            cout << n + 1 << endl;
        else
            cout << n << endl;
        return 0;
    }
    if(d == 1) {
        if((n*100) % 10000 == 0)
            cout << n *101 << endl;
        else
            cout << n*100 << endl;
        return 0;
    }
    else {
        if((n*10000) % 1000000 == 0)
            cout << n *101*100 << endl;
        else
            cout << n*10000 << endl;
        return 0;
    }
}

Measured memory_bytes: 3596
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let mut a : u64 = read();
    let mut b : u64 = read();
    let mut h = HashSet::new();
    a %= b;
    let mut ans = a;
    loop {
        if h.contains(&a) {
            break;
        }
        ans = min(ans, a);
        h.insert(a);
        if a > b {
            a = a - b;
        }
        else {
            a = b - a;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

    long long S;
    const long long mod=1000000007;
    cin>>S;
    long long dp[S+10];
    for(int i=0;i<S+10;i++){
        dp[i]=0;
    }
    dp[0]=1;
    for(int i=0;i<S;i++){
        for(int k=3;k<=S-i;k++){
            dp[i+k]+=dp[i]%mod;
        }
    }

    cout<<dp[S]%mod<<endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int i,j,a,b,t=0,n,wt;
  cin>>n>>wt;
  long long int v[n],w[n];
  for(i=0;i<n;i++)
  {
    cin>>w[i]>>v[i];
    t+=v[i];
  }
  long long int d[t+1];
  for(i=0;i<=t;i++)
    d[i]=1e13+5;
  d[0]=0;
  for(i=0;i<n;i++)
  {
    for(j=t;j>=v[i];j--)
    {
      d[j]=min(d[j],d[j-v[i]]+w[i]);
    }
  }
  //wt=INF;
  j=0;
  for(i=0;i<=t;i++)
  {
    if(d[i]<=wt)
      j=i;
  }
  cout<<j;
}


Measured memory_bytes: 1024
#include<stdio.h>

/* 桁数を返す関数 */
int digitNumber(int n);

/* main関数 */
int main(){
  int i;
  int a, b;
  int digitnum;

  while(scanf("%d %d",&a,&b) != EOF){
    digitnum = digitNumber(a+b);
    printf("%d\n",digitnum);
  }

  return 0;
}

int digitNumber(int n){
  //nを0になるまでひたすら割る.
  //割った回数が桁数である。
  int cnt = 1;

  while((n/10) != 0){
    cnt ++;
    n = n/10;
  }

  return cnt;
}

Measured memory_bytes: 600
H, W = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
N = 0
Q = []
for w in range(W):
  for h in range(H-1):
    if A[h][w]%2 == 1:
      A[h][w] -= 1
      A[h+1][w] += 1
      Q.append([h+1,w+1,h+2,w+1])
      N += 1
for w in range(W-1):
  if A[H-1][w]%2 == 1:
    A[H-1][w] -= 1
    A[H-1][w+1] += 1
    Q.append([H,w+1,H,w+2])
    N += 1
print(N)
for i in range(N):
  print(" ".join(map(str,Q[i])))

Measured memory_bytes: 29812
#include<cstdio>

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

using namespace std;

int main(){
	int S3[1024];
	rep(S,1024){
		int stat=0;
		rep(j,10) if(S&(1<<j)) {
			stat^=1<<j;
			if(j>0) stat^=1<<(j-1);
			if(j<9) stat^=1<<(j+1);
		}
		S3[S]=stat;
	}

	int T; scanf("%d",&T);
	while(T--){
		int org[10]={};
		rep(i,10) rep(j,10) {
			int tmp; scanf("%d",&tmp);
			org[i]|=tmp<<j;
		}

		int ans=-1;
		rep(S,1024){
			int grid[10];
			rep(i,10) grid[i]=org[i];

			grid[0]^=S3[S];
			grid[1]^=S;
			for(int i=1;i<10;i++){
				int pttn=grid[i-1];
				grid[i-1]=0;
				grid[i]^=S3[pttn];
				if(i<9) grid[i+1]^=pttn;
			}

			if(grid[9]==0){ ans=S; break; }
		}
if(ans==-1)while(1);

		rep(j,10) printf("%d%c",!!(ans&(1<<j)),j<9?' ':'\n');
		org[0]^=S3[ans];
		org[1]^=ans;
		for(int i=1;i<10;i++){
			int pttn=org[i-1];
			org[i-1]=0;
			org[i]^=S3[pttn];
			if(i<10) org[i+1]^=pttn;
			rep(j,10) printf("%d%c",!!(pttn&(1<<j)),j<9?' ':'\n');
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	string str;
	int sum=0;
	cin >> str;
	if(str.size()==1){
		cout << str << endl;
		return 0;
	}
	for(int i=1;i<str.size();i++){
		sum+=(str[i]-'0');
	}
	if(sum==0){
		cout << int(str[0]-'0')*10 << endl;
	}
	else{
		sum+=(str[0]-'0');
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (int)(1e9+7)
#define INF (int)(1e9)
#define LLINF (int)(4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

int main() {
    int X, A, B; input(X, A, B);
    X -= A;
    cout << X%B << endl;
    getchar(); getchar();
}

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

vector <int> l;
bool posible[200010];

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

    int n, m, a, b;
    cin >> n >> m;

    while (m--) {
        cin >> a >> b;
        if (a > b)
            swap(a, b);
        if (b == n)
            posible[a] = 1;
        if (a == 1)
            l.push_back(b);
    }

    for (auto i : l) {
        if (posible[i]) {
            cout << "POSSIBLE";
            return 0;
        }
    }

    cout << "IMPOSSIBLE";

    return 0;
}


Measured memory_bytes: 1148
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

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

using Real = long double;
Real l, r, p, e, t;
int k;
Real EPS = 1e-10;
bool ok(Real a, Real t) {
    return t - e - EPS <= a and a <= t + e + EPS;
}

Real dfs(Real l, Real r, int cur) {
    if (cur == k) {
        if (ok((l + r) / 2.0, t)) return 1.0;
        else return 0.0;
    }
    if (t - e - EPS <= l and r <= t + e + EPS) return 1.0;
    if (r < t - e - EPS or t + e + EPS < l) return 0.0;
    Real mid = (l + r) / 2.0;
    Real res = 0;
    if (mid < t) res += dfs(mid, r, cur + 1) * (1 - p) + dfs(l, mid, cur + 1) * p;
    else res += dfs(mid, r, cur + 1) * p + dfs(l, mid, cur + 1) * (1 - p);
    return res;
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */

    cin >> k >> l >> r;
    cin >> p >> e >> t;
    Real res = dfs(l, r, 0);
    cout << fixed << setprecision(12) << res << endl;
    return 0;
}



Measured memory_bytes: 3300
#include<iostream>


using namespace std;

int main(){
long long A, B, C;
cin>>A>>B>>C;

if (A%2==0 || B%2==0 || C%2==0){cout<<'0'<<endl;
return 0;
}

  cout << min(min(B * C, A * C), A * B) << endl;

}



Measured memory_bytes: 3588
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

typedef std::pair<int,int> ii;

bool IsContain(ii pos,int h,int w){
  if(1<=pos.first&&pos.first<=w-1&&1<=pos.second&pos.second<=h-1){
    return true;
  }else{
    return false;
  }
}

int GetPos(ii pos,int h,int w){
  int result=0;
  if(pos.first==0){
    result= 2*w+h+(h-pos.second);
  }else if(pos.first==w){
    result= w+pos.second;
  }else if(pos.second==0){
    result= pos.first;
  }else{
   result= w+h+(w-pos.first);
  }
  // if(result>=(h+w)*2){
  //   result=0;
  // }
  return result;
}



int Solve(std::vector<ii> job,int start,int d,int w,int it){
  int result=1;
  int time=start;
  int start_itr=it;

  int itr=start_itr;
  bool looped=false;
  while(true){
    if(itr==start_itr&&looped){
      break;
    }
    if(job[itr].first<job[itr].second){
      if(!(job[itr].first<=time&&time<=job[itr].second)){
        time=job[itr].second;
        result++;
      }
    }else{
      if(!((job[itr].first<=time&&time<=2*(d+w))||(0<=time&&time<=job[itr].second))){
        time=job[itr].second;
        result++;
      }
    }
    itr++;
    if(itr>=job.size()){
      looped=true;
      itr=0;
    }
  }

  return result;
}

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

  int n,w,d;
  cin>>n>>w>>d;
  std::vector<ii> job;
  for(int i=0;i<n;i++){
    int x,y;
    char f;
    cin>>x>>y>>f;
    int limit_l,limit_r;
    ii l_pos=std::make_pair(x,y);
    ii r_pos=l_pos;
    if(f=='E'){
      while(IsContain(l_pos,d,w)){
        l_pos.first++;
        l_pos.second--;
      }
      while(IsContain(r_pos,d,w)){
        r_pos.first++;
        r_pos.second++;
      }
    } else if(f=='W'){
      while(IsContain(l_pos,d,w)){
        l_pos.first--;
        l_pos.second++;
      }
      while(IsContain(r_pos,d,w)){
        r_pos.first--;
        r_pos.second--;
      }
    } else if(f=='N'){
      while(IsContain(l_pos,d,w)){
        l_pos.first++;
        l_pos.second++;
      }
      while(IsContain(r_pos,d,w)){
        r_pos.first--;
        r_pos.second++;
      }
    } else {//f=='S'
      while(IsContain(l_pos,d,w)){
        l_pos.first--;
        l_pos.second--;
      }
      while(IsContain(r_pos,d,w)){
        r_pos.first++;
        r_pos.second--;
      }
    }

    limit_l=GetPos(l_pos,d,w);
    limit_r=GetPos(r_pos,d,w);
    if(limit_r==0){
      limit_r=32;
    }

    job.push_back(std::make_pair(limit_l,limit_r));
  }

  int result=INT32_MAX;
  std::sort(job.begin(), job.end(),[](ii a,ii b){
    return a.second<b.second;
  });

  for(int i=0;i<2*n;i++){
    if(i%2==0){
      result=std::min(result,Solve(job,job[i/2].first,d,w,i/2));
    }else{
      result=std::min(result,Solve(job,job[i/2].second,d,w,i/2));
    }


  }
  cout<<result<<endl;


  return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <vector>
#define LL long long
using namespace std;
map<int,int>mp;
LL a[100000];
int main(){
	int n=0;
	scanf("%d",&n);
	int mx=-1;
	int cnt=0;
	for(int i=0;i<n;i++){
		int temp;
		scanf("%d",&temp);
		mx=max(mx,temp);
		if(mp[temp]==0) a[++cnt]=temp;
 		mp[temp]++;
	}
	//sort(a+1,a+cnt+1);
	int res=0;

	//printf("\n");
	//for(int i=1;i<=mx;i++){
	//    printf("%d  ",mp[i]);

	//}

	for(int i=1;i<=cnt;i++){
	    //printf("A  ");
        //if(mp[a[i]]==0) continue;
        if(mp[a[i]]>a[i]){
            res+=mp[a[i]]-a[i];
        }else if(mp[a[i]]<a[i]){
            res+=mp[a[i]];
        }else if(mp[a[i]]==a[i]){
            continue;
        }
	}

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


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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; i++)cin >> a[i];
  int sxor=0;
  for(int i=0; i<n; i++){
    sxor^=a[i];
  }
  for(int i=0; i<n; i++){
    cout << (a[i]^sxor) << ' ';
  }
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
int n, a, b;
cin>>n>>a>>b;
string s;
cin>>s;
vector<string> res;
int passed = 0;
int ranking = 0;
for(int i = 0; i < n; ++i){
if(s[i]=='a'){ //japanese
if(passed < a + b){
passed++;
res.push_back("Yes");
}
else{
res.push_back("No");
}
}
if(s[i]=='b'){ //overseas
if(passed < a + b && ranking < b){
passed++;
ranking++;
res.push_back("Yes");
}
else{
res.push_back("No");
}

}
if(s[i]=='c'){ //neither
res.push_back("No");
}
}
for(auto & s : res){
cout<<s<<endl;
}
return 0;
}

Measured memory_bytes: 6260
H, W = [int(_) for _ in input().split()]
A = [list(input()) for i in range(H)]


ps = []
pcount = 0
for y, row in enumerate(A):
    for x, c in enumerate(row):
        if c == "#":
            ps.append((x, y))
            pcount += 1


result = 0

#print(A)
#print(ps)

while pcount < H * W:
    nps = []
    def pset(x, y):
        global pcount
        if 0 <= y < len(A) and 0 <= x < len(A[y]) and A[y][x] == ".":
            A[y][x] = "#"
            nps.append((x, y))
            pcount += 1
    for x, y in ps:
        pset(x - 1, y)
        pset(x + 1, y)
        pset(x, y - 1)
        pset(x, y + 1)
    ps = nps
    result += 1
    #print(A)
    #print(ps)
    #print(result)

print(result)


Measured memory_bytes: 125764
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Double> x = new ArrayList<>();
        List<String> u = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            x.add(sc.nextDouble());
            u.add(sc.next());
        }
        double sum = 0;
        for (int i = 0; i < n; i++) {
            if ("BTC".equals(u.get(i))) {
                sum += x.get(i) * 380000.0;
                continue;
            }
            sum += x.get(i);
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 24660
#include<bits/stdc++.h>
using namespace std;
long long k;
long long ksm(int p)
{
	if(p==0) return 1;
	long long base=2,res=1;
	while(p>0)
	{
		if((p&1)==1) res*=base;
		base*=base;
		p>>=1;
	}
	return res;
}
int main()
{
	cin>>k;
	for(int i=0;i<=40;i++)
	{
		long long ans=ksm(i);
		if(ans>k)
		{
			cout<<ans-1<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vl a(n);
  REP(i, n) { cin >> a[i]; }
  ll ans = 1e11;
  REP(i, (1 << n)) {
    ll tmp = 0;
    int vis = 1;
    ll ma = a[0];
    FOR(j, 1, n) {
      if ((i >> j) % 2 == 1 && a[j] <= ma) {
        tmp += ma - a[j] + 1;
        ma = ma + 1;
        vis++;
      } else if (a[j] > ma) {
        vis++;
      }
      ma = max(ma, a[j]);
    }
    if (vis >= k) {
      ans = min(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		int count=0;
		if(s.substring(0, 1).equals("2"))count++;
		if(s.substring(1, 2).equals("2"))count++;
		if(s.substring(2, 3).equals("2"))count++;
		if(s.substring(3, 4).equals("2"))count++;
		System.out.println(count);
	}
}



Measured memory_bytes: 23764
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    for (int i = 1; i < 10; i++) {
        if (N % i == 0 && N / i < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

char HA[1<<21], T[256];

int main() {
    unsigned int n, s, t;
    char c;
    T['A'] = 4;
    T['C'] = 3;
    T['G'] = 2;
    T['T'] = 1;
    scanf("%d", &n);
    getchar();
    while (n--) {
        s = 0;
        t = 1;
        int flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) HA[s] = 1; else puts( HA[s] ? "yes" : "no" );
    }
    return 0;
}

Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
string solve(int k, string s) {
    if (k == 1) return s;
    for (int i = s.size()-1; i > 0; i--) {
        if (s[i-1] < s[i]) {

        }
        else {
            if (s[i] != '9') {
                s[i]++;
                for (int j = i+1; j < s.size(); j++) {
                    s[j] = max(s[j-1]-1, (int)'0');
                }
                return solve(k-1, s);
            }
        }
    }
    if (s[0] == '9') {
        return solve(k-1, '1'+string(s.size(), '0'));
    }
    else {
        s[0]++;
        for (int j = 1; j < s.size(); j++) {
            s[j] = max(s[j-1]-1, (int)'0');
        }
        return solve(k-1, s);
    }
}
int main () {
    int K;
    cin >> K;
    cout << solve(K, "1") << endl;
}

Measured memory_bytes: 17408
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();

    let mut v = vec![0; s.len() + 1];
    for i in 0..s.len() {
        let x = if s[i] == 'g' { 1 } else { -1 };
        v[i + 1] = v[i] + x;
    }
    println!("{:?}", v[s.len()] / 2);
}


Measured memory_bytes: 4352
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int[] menu = new int[5];
    for (int i = 0; i < 5; i++){
      menu[i] = Integer.parseInt(br.readLine());
    }
    int temp = 10;
    for (int i = 0; i < 4; i++){
      if (0 < menu[i]%10 && menu[i]%10 < temp){
        temp = menu[i]%10;
      }
    }
    int result = 0;
    for (int i = 0; i < 5; i++){
      result += new BigDecimal(menu[i]).setScale(-1, RoundingMode.UP).intValue();
    }
    System.out.println(result -(10-temp));
  }
}


Measured memory_bytes: 23124
N = int(input())
ans=''

for i in range(1, 99):
  if N <= 26 ** i:
    N -= 1
    for j in range(i):
      ans += chr(ord('a') + N % 26)
      N //= 26
    break
  else:
    N -= 26 ** i

print(ans[::-1]) # reversed

Measured memory_bytes: 9176
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()

ans = 0
plus = 0
a = [ni() for _ in range(n)]

for ai in a:
    ans += ((ai+plus) // 2)
    plus = (ai+plus) % 2 if ai > 0 else 0

print(ans)

Measured memory_bytes: 7072
s = input()
a = [str(c) for c in s]
 
for i in range (len(a)-1):
	if a[i]=='?':
		if i!=0 and a[i-1]=='P':
			a[i]='D'
		elif a[i+1]=='D' or a[i+1]=='?':
			a[i]='P'
		else:
			a[i]='D'
if a[len(a)-1]=='?':
	a[len(a)-1]='D'
print(*a,sep='')

Measured memory_bytes: 13844
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[N];
	rep(i,N) cin >> A[i];
	int ans = 0;
	rep(i,N){
		if(i == 0) continue;
		if(A[i] == A[i-1]){
			++ans;
			A[i] = -1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
N = gets.to_i
a = gets.split.map(&:to_i)

b = a.dup
ans = []

(N-1).downto(0) do |i|
  if i > N / 2
    ans << i+1 if a[i] == 1
  else
    cnt = 0
    i.step(N-1, i+1) do |j|
      cnt += 1 if b[j] == 1
    end
    if cnt % 2 == a[i]
      if b[i] == 1
        ans << i+1
      end
    else
      if b[i] == 1
        b[i] = 0
      else
        b[i] = 1
        ans << i+1
      end
    end
  end
end

puts ans.size
puts ans.join(' ') if ans.size > 0

Measured memory_bytes: 22088
h, w = map(int,input().split())
s = [input() for i in range(h)]
for i in range(h):
  l = ""
  for j in range(w):
    if s[i][j] == "#":
      l += "#"
    else:
      l += str(sum([t[max(0,j-1):min(w,j+2)].count("#") for t in s[max(0,i-1):min(h,i+2)]]))
  print(l)
    

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if(a[a.size()-1]!=b[0] || b[b.size()-1]!=c[0]) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <vector>
#define NMAX 100000

using namespace std;

int n, m, sol, dp[NMAX+10];
bool viz[NMAX+10];
vector <int> nod[NMAX+10], a[NMAX+10];
stack <int> stiva;

void dfs(int x)
{   viz[x] = 1;
    for(int i=0; i<nod[x].size(); i++)
        if(!viz[nod[x][i]]) dfs(nod[x][i]);
    stiva.push(x);
}

int main()
{
    cin >> n >> m;
    for(int i=1; i<=m; i++)
        {   int nod1, nod2;
            cin >> nod1 >> nod2;
            nod[nod1].push_back(nod2);
            a[nod2].push_back(nod1);
        }
    for(int i=1; i<=n; i++) if(!viz[i]) dfs(i);
    while(!stiva.empty())
        {   int maxi = 0;
            for(int i=0; i<a[stiva.top()].size(); i++)
                maxi = max(maxi, dp[a[stiva.top()][i]]);
            dp[stiva.top()] = maxi + 1;
            sol = max(sol, dp[stiva.top()]);
            stiva.pop();
        }
    cout << sol-1 << '\n';
    return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

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

  ll ans = 0;
  map<char, int> count;
  for (int j = 1; j < N; ++j) {
    count[S[j - 1]]++;
    for (int k = j + 1; k < N; ++k) {
      if (S[j] != S[k]) {
	char color;
	if (S[j] != 'R' and S[k] != 'R') color = 'R';
	else if (S[j] != 'G' and S[k] != 'G') color = 'G';
	else color = 'B';
	ans += count[color];
	int i = j - (k - j);
	if (i >= 0 and S[i] == color) --ans;
      }
    }	
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3172
h,w = map(int, input().split())
s = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            ok = False
            for x,y in [(1,0), (0,1), (-1, 0), (0,-1)]:
                new_h, new_w = i+x, j+y
                if new_h >= h or new_h < 0 or new_w >= w or new_w < 0: continue
                if s[new_h][new_w] == "#": 
                    ok = True
                    break
            if not ok:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 9096
#include <iostream>
using namespace std;
const int MAXN = 100100;
int arr[MAXN];
int dp[MAXN];
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	}
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
	    dp[i] = min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;i++)
        cout<<s<<" ";
    if(s<1000000000)
    {
        for(int j=k;j<n;j++)
            cout<<s+1<<" ";
    }
    else
    {
        for(int j=k;j<n;j++)
            cout<<s-1<<" ";
    }
return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN], b[MAXN];
int main()
{
	int n, t;
	cin >> n >> t;
	for (int i = 0; i < n; i++)
		scanf("%d%d", &a[i], &b[i]);
	int flag = 0;
	int Min = INF;
	for (int i = 0; i < n; i++)
	{
		if (b[i] <= t)
		{
			flag = 1;
			Min = min(a[i], Min);
		}
	}
	if (flag)
		cout << Min << endl;
	else
		cout << "TLE" << endl;
	return 0;
}


Measured memory_bytes: 256
//g++  5.4.0

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

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 2e5+1;
vector<int> g[nax];
int n;
 
int func(int p , int q )
{
    return p*(n-q+1);
}

signed main()
{
    fast;
    cin >> n;
    int res = n ;
    for(int i=1 ; i<n ; i++ )
    {
        res += i*(n-i+1);
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
        res -= func(min(u,v),max(u,v));
    }
       
    cout << res ;
    
}





Measured memory_bytes: 15776
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll dif(ll x,ll y)
{
    if((x<=0 && y>=0) || (x>=0 && y<=0))
        return abs(x)+abs(y);
        return abs(abs(x)-abs(y));
    }
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,m;
    cin>>n>>m;
    vector<ll>v;
    for(int i=0;i<m;i++){
        ll a;
        cin>>a;
        v.push_back(a);
    }
    sort(all(v));
    vector<ll>dis;
    for(int i=1;i<m;i++){
        dis.push_back(dif(v[i],v[i-1]));
    }
    sort(all(dis));
    reverse(all(dis));
    ll sum=0;
    for(int i=n-1;i<dis.size();i++)
        sum+=dis[i];
    cout<<sum<<endl;


    return 0;
}


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

int main() {
	int a,b;
	cin>>a>>b;
	if(((a<=9)&&(a>=1))&&((b<=9)&&(b>=1)))
	{
	    cout<<a*b<<endl;
	}
	else{
	    cout<<"-1"<<endl;
	}
	return 0;
}


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

using namespace std;

using i64 = long long;

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


signed main(){
    string s;
    cin >> s;
    int n = s.size();
    bool fl = true;
    for(int i = 0; i < n; i += 2)
        fl &= (s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
    for(int i = 1; i < n; i += 2)
        fl &= (s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
    cout << (fl ? "Yes" : "No") << endl;
}


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

int main() {
	int n;
	cin >> n;
	int l[n],r[n];
	int m=0;
	for(int i=0;i<n;i++){
		cin >> l[i] >> r[i];
		m = m + r[i] - l[i] + 1;
	}

	cout << m << endl;
	

	return 0;
}

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

int main(){
	string s,t;
	bool hantei = false;

	cin >> s >> t;

	if(s == t){
		cout << "No" << endl;
	}
	else{
		for(int i = 0; i < s.size();i++){
			if(s.at(i) != t.at(i)){
				hantei = true;
				break;
			}
		}
	}

	if(hantei){
		cout << "No" << endl;
	}
	else{
		if(t.size() == s.size()+1){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 3632
n, m, l = map(int, input().split())

A = []
B = []
C = [[] for i in range(n)]

for i in range(n):
    tmp_row = list(map(int, input().split()))
    A.append(tmp_row)

for i in range(m):
    tmp_row = list(map(int, input().split()))
    B.append(tmp_row)

for i in range(n):
    for j in range(l):
        ab = sum([A[i][k] * B[k][j] for k in range(m)])
        C[i].append(ab)

for i in C:
    print(" ".join(map(str, i)))

Measured memory_bytes: 8864
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define scai(x) scanf("%d", &x)
#define scac(x) scanf("%c", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define pri(x) printf("%d", x)
#define prc(x) printf("%c", x)
#define pri2(x,y) printf("%d %d", x, y)
#define prif(x) printf("%lf", x)
#define prif2(x, y) printf("%lf %lf", x, y)
#define mset(x, y) memset(x, y, sizeof(x))
#define fori(i, x, y) for(int i = x; i < y; i++)
#define pii pair<int, int>
#define pic pair<int, char>
#define pdd pair<double, double>
typedef long long ll;
const int N = 13;
int a[N];
int zuo[N];
int you[N];
int lc, rc;



bool solve()
{
    for(int i = 0; i < 1024; i++)
    {
        mset(zuo, 0);
        mset(you, 0);
        lc = rc = 0;
        int cnt;
        int j;
        for(j = i, cnt = 0; cnt < 10; cnt++, j >>= 1)
        {
            if(j & 1) zuo[lc++] = a[cnt];
            else you[rc++] = a[cnt];
        }
        bool flag = true;
        for(j = 1; j < lc; j++)
        {
            if(zuo[j] < zuo[j - 1]) {
                flag = 0;
                break;
            }
        }

        if(flag){
            for(j = 1; j < rc; j++){
                if(you[j] < you[j - 1]) {
                    flag = 0;
                    break;
                }
            }
        }

        if(flag) return true;
    }
    return false;
}


int main()
{
    int n;
    cin >> n;
    while(n--)
    {
        for(int i = 0; i < 10; i++)
        {
            scai(a[i]);
        }
        puts(solve()? "YES" : "NO");
    }
    return 0;
}


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

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

    int N;
    cin >> N;
    vector<ll> A(N);
    vector<pll> ans;
    deque<ll> B, C;
    rep(i, N) {
        cin >> A[i];
        if (A[i] >= 0)
            B.push_back(A[i]);
        else
            C.push_back(A[i]);
    }

    sort(all(B)), sort(all(C), greater<ll>());

    if (B.size() == N) {
        ll n = B.front() - B.back();
        ans.push_back({B.front(), B.back()});
        B.pop_front(), B.pop_back();
        C.push_back(n);
    } else if (C.size() == N) {
        ll n = C.front() - C.back();
        ans.push_back({C.front(), C.back()});
        C.pop_back(), C.pop_front();
        B.push_back(n);
    }

    while (B.size() != 1 && !B.empty()) {
        ll b = B.front();
        ll c = C.front();
        ll n = c - b;
        B.pop_front(), C.pop_front();
        C.push_back(n);
        ans.push_back({c, b});
    }

    while (!C.empty() && !B.empty()) {
        ll b = B.front();
        ll c = C.front();
        ll n = b - c;
        B.pop_front(), C.pop_front();
        B.push_back(n);
        ans.push_back({b, c});
    }

    cout << ans.back().first - ans.back().second << endl;
    rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
}

Measured memory_bytes: 6936
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
using P = pair<int,int>;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
//const int INF =1001001001;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    rep(i,k){
        ans += p[i];
    }
    int esum = ans;
    rep(i,n-k){
        esum = esum - p[i] + p[i+k];
        ans = max(esum, ans);
    }
    double sans = (double)(ans + k);
    sans /=2 ;
    cout << fixed << setprecision(10) << sans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int N=105;
char s[N][N];
int f[N][N];
int main(){
	int h,w;scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)scanf("%s",s[i]+1);
	memset(f,0x1f,sizeof(f));f[0][1]=0;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(s[i][j]=='#'){
				f[i][j]=min(f[i-1][j]+(s[i-1][j]!='#'),f[i][j-1]+(s[i][j-1]!='#'));
			}
			else{
				f[i][j]=min(f[i-1][j],f[i][j-1]);
			}
		}
	}
	printf("%d",f[h][w]);
	return 0;
} 

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

using namespace std;

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

long int n, k;
long int a[200005], f[200005];



bool C(long int x){
    long int num = 0;
    for (int i = 0; i < n; i++){
        if (a[i] - (x / f[i]) > 0){
            num += a[i] - (x / f[i]);
        }
    }
    // cout << num << endl;
    return num <= k;
}


int main(){
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(a, a + n);
    sort(f, f + n, greater<long int>());
    // rep(i, n){
    //     cout << a[i] << " ";
    // }
    // cout << endl;
    // rep(i, n){
    //     cout << f[i] << " ";
    // }
    // cout << endl;
    long int l = 0, r = 100000000000000;
    while (l < r - 1){
        long int mid = (r + l) / 2;
        if (C(mid)){
            r = mid;
        }else{
            l = mid;
        }
        // cout << mid << endl;
    }
    // cout << l << endl;
    if (C(l)){
        cout << l << endl;
    }else{
        cout << r << endl;
    }
    
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, h, w;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> h >> w;
  n++;
  cout << (n-h)*(n-w) << endl;
}

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

int main(){
  int n,m,x,y,i,j,l,r;
  cin>>n>>m>>x>>y;
  r=x;
  l=y;
  while(n--){
    cin>>i;
    r=max(r,i);
  }
  while(m--){
    cin>>j;
    l=min(l,j);
  }
  if(r>=l)cout << "War" << endl;
  else cout << "No War" << endl;
  return 0;
}


Measured memory_bytes: 256