akhauriyash/Code-Regression huggingface dataset:
def resolve():
  mod = 1000000007
  n, k = map(int, input().split())
  a = list(map(int, input().split()))
  x = 0
  # A の転倒数を求める
  for i in range(n):
    for j in range(i+1, n):
      if a[i] > a[j]:
        x += 1
  # A のすべての数字に対して，A内に自分より小さいものが何個あるか
  y = 0
  for i in range(n):
    for j in range(n):
      if a[i] > a[j]:
        y += 1
  ans = (x * k) % mod
  # 1 ~ k の和 * y
  ans += (((k-1) * (k)) // 2) * y % mod
  ans %= mod

  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 9276
import java.util.Scanner;

class Main{

static char[][] map;
static int H;
static int W;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		H = sc.nextInt();
		W = sc.nextInt();
		map  = new char[H][W];

		for(int i = 0;i < H;i++){
			map[i] = sc.next().toCharArray();
		}
		

		for(int i= 0;i < H;i++){
			for(int j = 0;j < W;j++){
				if(map[i][j] == '#'){
					check(i,j);
				}
			}
				
		}
		System.out.println("Yes");
		
		

	}
	
	static void check(int y,int x){
		int[] dx = {-1,1,0,0};
		int[] dy = {0,0,1,-1};
		
		for(int i = 0;i < 4;i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
			if(nx >= 0 && nx < W && ny >= 0 && ny < H && map[ny][nx] == '#'){
				return;
			}
		}
		
		System.out.println("No");
		System.exit(0);
		
		
		
	}






}




class Pair implements Comparable{
	String from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}





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

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

using namespace std;

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

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

int main() {
	int A, B;
	cin >> A >> B;
	cout << lcm(A, B);
}

Measured memory_bytes: 256
//File Name: arc073_D.cpp
  //Created Time: 2017年05月14日 星期日 15时06分26秒
                                   
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 103;
int f[MAXN][MAXN][MAXN * 3];
int w[MAXN],v[MAXN];
int solve(const int n,const LL m){
	memset(f,-1,sizeof f);
	f[0][0][0] = 0;
	for(int i(0);i<n;++i){
		for(int j(0);j<=i;++j){
			for(int k(0);k<=300;++k){
				if(f[i][j][k] == -1) continue;
				f[i + 1][j][k] = max(f[i + 1][j][k],f[i][j][k]);
				f[i+1][j+1][k+w[i+1]-w[1]] = max(f[i+1][j+1][k+w[i+1]-w[1]],f[i][j][k] + v[i+1]);
			}
		}
	}
	int res(0);
	for(int j(1);j<=n;++j){
		for(int k(0);k<=300;++k){
			if((LL)j * w[1] + k <= m && f[n][j][k] > res)
				res = f[n][j][k];
		}
	}
	return res;
}
int main(){
	int n;
	LL m;
	scanf("%d %lld",&n,&m);
	for(int i(1);i<=n;++i){
		scanf("%d %d",w + i,v + i);
	}
	printf("%d\n",solve(n,m));
	return 0;
}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int N = 2e5;
ll v[N], n, m, c, p;
bool check(int i) {
  int n1 = upper_bound(v, v + n, v[i]) - v;
  if (n - n1 < p)
    return true;
  else {
    int n2 = upper_bound(v, v + n, v[i] + m) - v;
    if (n - n2 >= p)
      return false;

    ll s = m * (p - 1 + n1);
    for (int j = i + 1; j <= n - p; j++)
      s += min(m, v[i] + m - v[j]);
    if (s >= m * c)
      return true;
    else
      return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  cin >> n >> m >> c >> p;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v, v + n);
  int ans, s = 0, e = n - 1;
  while (s <= e) {
    int mid = s + (e - s) / 2;
    if (check(mid)) {
      ans = mid;
      e = mid - 1;
    }
    else
      s = mid + 1;
  }
  cout << n - ans;
  return 0;
}

Measured memory_bytes: 4416
import sys
input = sys.stdin.readline
from bisect import *

A, B, Q = map(int, input().split())
s = [-10**18]+[int(input()) for _ in range(A)]+[10**18]
t = [-10**18]+[int(input()) for _ in range(B)]+[10**18]

for _ in range(Q):
    x = int(input())
    i = bisect_left(s, x)
    sl = s[i-1]
    sr = s[i]
    i = bisect_left(t, x)
    tl = t[i-1]
    tr = t[i]
    ans = 10**18
    
    for fi in [sl, sr]:
        for se in [tl, tr]:
            ans = min(ans, abs(fi-x)+abs(se-fi))
    
    for fi in [tl, tr]:
        for se in [sl, sr]:
            ans = min(ans, abs(fi-x)+abs(se-fi))
    
    print(ans)

Measured memory_bytes: 68444
void main() {
    int k = readln.chomp.to!int;
    writeln(k / 2 * ((k + 1) / 2));
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 998244353;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

int main() {
    vector<vector<int>> retu(3,vector<int>(3));
    for(int i = 0;i<3;i++)for(int j = 0;j<3;j++) cin >> retu.at(i).at(j);
    bool ok = true;
    vector<vector<int>> compare(3,vector<int>(3));

    //三列分だけを見て引く感じ
    for(int i = 0;i<=100;i++){
        for(int j = 0;j<=100;j++){
            for(int k = 0;k<=100;k++){
                compare = retu;
                for(int l = 0;l<3;l++){
                    compare.at(0).at(l) -= i;
                    compare.at(1).at(l) -= j;
                    compare.at(2).at(l) -= k;
                }
                for(int m = 0;m<3;m++){
                    if(compare.at(0).at(m) == compare.at(1).at(m) && compare.at(1).at(m) == compare.at(2).at(m) && compare.at(2).at(m) == compare.at(0).at(m)){   
                    }
                    else ok = false;
                }
                if(ok){
                    cout << "Yes" << endl;
                    return 0;
                }
                ok = true;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());

	deque<int> dq1, dq2;
	int l = 0, r = N - 1;
	while (l <= r) {
		if (l & 1) swap(A[l], A[r]);
		dq1.emplace_back(A[l]);
		dq2.emplace_back(A[r]);
		if (l != r) {
			dq1.emplace_front(A[r]);
			dq2.emplace_front(A[l]);
		}
		l++, r--;
	}

	lint ans1 = 0;
	lint ans2 = 0;
	int prev1 = dq1.front();
	int prev2 = dq2.front();
	while (!dq1.empty()) {
		ans1 += abs(dq1.front() - prev1);
		ans2 += abs(dq2.front() - prev2);
		prev1 = dq1.front();
		prev2 = dq2.front();
		dq1.pop_front();
		dq2.pop_front();
	}

	cout << max(ans1, ans2) << "\n";

	return 0;
}


Measured memory_bytes: 4504
S = list(map(int,input().split()))
counter = 0
nuske = []

for k in range(S[0]):
  nuske.append(int(0))

for i in range(S[1]):
  roop = int(input())
  if roop == 1:
    temp = int(input())
    nuske[temp-1] = nuske[temp-1] + 1
  else:
    temp = list(map(int,input().split()))
    for l in temp:
      nuske[l-1] = nuske[l-1] + 1

for y in nuske:
  if y == 0:
    counter += 1
print(counter)
    

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<P> cntodd(100005), cnteve(100005);
  rep(i,100005) {
    cntodd[i].second = i;
    cnteve[i].second = i;
  }
  rep(i,n) {
    int a;
    cin >> a;
    if (i % 2 == 0) cnteve[a].first++;
    else cntodd[a].first++;
  } 
  sort(all(cnteve), greater<P>());
  sort(all(cntodd), greater<P>());
  int ans = 0;
  auto dif = [&](P p) {
    return fabs(p.first - n/2);
  };
  if (cnteve[0].second == cntodd[0].second) { //数が同じ
    ans = min(dif(cnteve[0]) + dif(cntodd[1]), dif(cnteve[1]) + dif(cntodd[0]));
    cout << ans << endl;
    return 0;
  }
  ans = dif(cnteve[0]) + dif(cntodd[0]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))
# 単純な話
money = 1000
stock = 0
for i in range(N-1):
    if A[i]<A[i+1]:
        stock += money//A[i]
        money %= A[i]
        money += stock*A[i+1]
        stock = 0
print(money)

Measured memory_bytes: 61880
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int a, g;
  cin >> a >> g;
  cout << 2*g-a << endl;
  return 0;
}


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

using namespace std;

const int N = 4e5 + 5, mod = 998244353;

char s[N], t[N];
int cnt[N];

int main() {
  int n;
  scanf("%d %s", &n, s);
  for (int i = 0; i < n; ++i) {
    s[i] -= '0';
  }
  for (int d = 1; d <= n; ++d) {
    if (n % d) continue;
    int x = n / d;
    if ((x & 1) == 0) continue;
    long long cur = 0;
    for (int i = 0; i < d; ++i) {
      cur = (cur * 2 + s[i]) % mod;
    }
    cur = (cur + 1) % mod;
    bool ok = 1;
    for (int i = 0; i < d; ++i)
      t[i] = s[i], t[i+d] = s[i]^1;
    for (int i = 2 * d; i < n; ++i)
      t[i] = t[i-2 * d];
    for (int i = 0; i < n; ++i) {
      if (t[i] != s[i]) {
        ok = t[i] < s[i];
        break;
      }
    }
    if (!ok) {
      cur = (cur + mod - 1) % mod;
    }
    cnt[d] = cur;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (n % i) continue;
    if (cnt[i] == 0) continue;
    ans = (ans + 1LL * cnt[i] * (2 * i)) % mod;
    for (int j = i+i; j <= n; j += i) {
      cnt[j] = (cnt[j] + mod - cnt[i]) % mod;
    }
  }
  if (ans < 0)
    ans += mod;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
    string n;cin >> n;
    bool e=false;
    rep(i,3)if(n[i]=='7')e=true;
    cout << (e ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,ans=0;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >>a[i];
    }
    sort(a,a+N);
    for(int i=0;i<N;i++){
        if(a[i]!=a[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<ll>
#define deb(x)		cout << #x << " " << x << endl

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;

void relax(ll & a , ll b){
    a = min(a , b);
}

signed main(){

#ifndef ONLINE_JUDGE
   // freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    cin >> n;

    vi h(n) , dp(n , oo);

    fo(i , n)
        cin >> h[i];
    
    //forward style dp
    dp[0] = 0;
    fo(i , n){
        if(i + 2 < n)
            relax(dp[i + 2] , abs(h[i + 2] - h[i]) + dp[i]);
        if(i + 1 < n)
            relax(dp[i + 1] , abs(h[i + 1] - h[i]) + dp[i]);
    }

    cout << dp[n - 1] << '\n';

    return 0;

}



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

int main(){
	int m,f,r;
	while(1){
		cin>>m>>f>>r;
		if(m==-1&&f==-1&&r==-1) return 0;
		if(m==-1||f==-1){
			cout<<'F'<<endl;
			continue;
		}
		if(m+f>=80){
			cout<<'A'<<endl;
			continue;
		}else if(m+f>=65){
			cout<<'B'<<endl;
			continue;
		}else if(m+f>=50){
			cout<<'C'<<endl;
			continue;
		}else if(m+f>=30){
			if(r>=50){
				cout<<'C'<<endl;
				continue;
			}
			cout<<'D'<<endl;
			continue;
		}else{
			cout<<'F'<<endl;
			continue;
		}
	}

	return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

struct Problem{
    ll point, n , c, max_point;
    Problem(ll point=0LL, ll n=0LL, ll c=0LL): point(point), n(n), c(c){
        max_point = point * n + c;
    }
};

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int D,G;
    cin >> D >> G;
    vector<Problem> problems(D);
    ll n, c;
    rep(D){
        cin >> n >> c;
        problems[i] = Problem(100*(i+1), n, c);
    }

    ll ans = LLONG_MAX;
    ll sum[1<<10] = {0LL}, num[1<<10] = {0LL};
    rep(1 << D){
        for(int j=D-1;j>=0;j--){
            if(i & (1 << j)) continue;

            ll tmp_sum = sum[i], tmp_num = num[i];
            int k = 0;
            while(k < problems[j].n && tmp_sum < G){
                tmp_sum += problems[j].point;
                k++;
            }
            if(k == problems[j].n) tmp_sum += problems[j].c;
            tmp_num += k;
            if(G <= tmp_sum) ans = min(ans, tmp_num);

            if(sum[i|(1<<j)]) continue;
            sum[i|(1<<j)] = sum[i] + problems[j].max_point;
            num[i|(1<<j)] = num[i] + problems[j].n;
        }
    }
    cout << ans << endl;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i < (n)i++)
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define abs(a) llabs(a)
#define int int64_t
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int a, b, c;
   cin >> a >> b >> c;

   int d = a + b;
   if (a + b <= c)
   {
      cout << 0 << ' ' << 0 << '\n';
   }
   else
   {
      if (a >= c)
      {
         cout << a - c << ' ' << b << '\n';
      }
      else
      {
         cout << 0 << ' ' << (a + b) - c << '\n';
      }
   }
}

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

int main() {
    int64_t N;
    std::cin >> N;

    int64_t A[N];
    for (int64_t i = 0; i < N; ++i) {
        std::cin >> A[i];
    }

    int64_t ans = 0;
    for (int64_t i = 0; i < N; ++i) {
        if (A[i] == 0) {
            continue;
        }

        ans += A[i] / 2;

        if ((A[i] % 2 != 0) && (i < (N - 1)) && (A[i + 1] > 0)) {
            A[i] -= 1;
            A[i+1] -= 1;
            ans += 1;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, m; cin >> n >> m;
    vector<vector<ll>> vec(m);
    REP(i, m) {
        ll k; cin >> k;
        vec[i].resize(k);
        REP(j, k) {
            cin >> vec[i][j];
            --vec[i][j];
        }
    }

    vector<ll> l(m);
    REP(i, m) {
        cin >> l[i];
    }

    ll ans = 0;

    REP(i, (1 << n)) {
        bool ok = true;
        REP(j, m) {
            ll c = 0;
            for (auto elem : vec[j]) {
                if ((i >> elem) & 1) c++;
            }
            if (c % 2 != l[j]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
}

Measured memory_bytes: 26476
a = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
b = []
[b.append(int(input())) for _ in range(n)]

for i in range(3):
    for j in range(3):
        for k in b:
            if a[j][i] == k:
                a[j][i] = 0


for i in range(3):
    if a[i][0] == 0 and a[i][1] == 0 and a[i][2] == 0:
        print("Yes")
        exit()
for i in range(3):
    if a[0][i] == 0 and a[1][i] == 0 and a[2][i] == 0:
        print("Yes")
        exit()
if a[0][0] == 0 and a[1][1] == 0 and a[2][2] == 0:
    print("Yes")
    exit()
if a[0][2] == 0 and a[1][1] == 0 and a[2][0] == 0:
    print("Yes")
    exit()
print("No")
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
vector<int> vec;
int n;
int b[102];
bool check = true;

void solve(int l)
{
    if (l == 0)
    {
        for (int i = n - 1; i >= 0; i--)
        {
            cout << vec[i] << endl;
        }
        return;
    }
    for (int i = l; i > 0; i--)
    {
        if (b[i] == i)
        {
            vec.push_back(i);
            for (int j = i; j <= l; j++)
            {
                b[j] = b[j + 1];
            }
            break;
        }
    }
    solve(l - 1);
    return;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        if (b[i] > i)
        {
            check = false;
        }
    }
    if (check == true)
    {
        solve(n);
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64 k:i64));

    fn get_n(mut x:i64,k:i64)->i64{
      let mut i=0;
      while x<k{
        x*=2;
        i+=1;
      }
      i
    }

    let mut res=0f64;
    for i in 1..n+1{
     res+=1f64/2i64.pow(get_n(i,k) as u32) as f64;
    }
    (res/n as f64).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3 10\n" => "0.145833333333\n",
    test2: "100000 5\n" => "0.999973749998\n",
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)
char mp[10][10];
int dp[10][10];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int h,w;
  cin>>h>>w;
  rep(i,h) {
    string s;
    cin>>s;
    rep(j,w) {
      mp[i][j] = s[j];
    }
  }
  dp[0][0] = 1;
  repeat(j,1,w) {
    dp[0][j]=0;
    if(mp[0][j-1]=='#'&&mp[0][j]=='#') dp[0][j] +=dp[0][j-1];
  }
  repeat(i,1,h) {
    dp[i][0]=0;
    if(mp[i-1][0]=='#'&&mp[i][0]=='#') dp[i][0]+=dp[i-1][0];
  }
  repeat(i,1,h) {
    repeat(j,1,w) {
      dp[i][j]=0;
      if(mp[i][j]=='#') {
        if(mp[i-1][j]=='#') dp[i][j]+=dp[i-1][j];
        if(mp[i][j-1]=='#')dp[i][j]+=dp[i][j-1];
      }
    }
  }
  // rep(i,h) {
  //   rep(j,w) {
  //     cout << dp[i][j];
  //   }
  //   cout << endl;
  // }
  int c=0;
  rep(i,h) {
    rep(j,w) {
      if(mp[i][j]=='#'&&dp[i][j]!=1) {
        cout << "Impossible"<<endl;
        return 0;
      }
      if(mp[i][j]=='#')c++;
    }
  }
  if(c==h+w-1)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    int n, w;
    cin >> n >> w;
    vector<int> weight(n), value(n);
    int maxV = -1;
    int sum;
    rep (i, n) {
        cin >> weight[i] >> value[i];
        maxV = max(maxV, value[i]);
    }
    sum = maxV * n;
    int dp[n + 1][sum + 1];
    rep (i, n + 1) {
        rep (j, sum + 1) {
            dp[i][j] = Inf;
        }
    }
    dp[0][0] = 0;

    rep (i, n) {
        rep (j, sum + 1) {
            if (j < value[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
        }
    }

    int ans = 0;
    rep (j, sum + 1) {
        if (dp[n][j] <= w) ans = j;
    }
    cout << ans << endl;
    
    return 0;
}



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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>


int main() {
  ll a, b;
  cin >> a >> b;
  if(abs(a-b) < 2) cout << "Brown" << endl;
  else cout << "Alice" << endl;
  return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> W(N);
    rep(i, N) cin >> W[i];
    //
    ll total = std::accumulate(W.begin(), W.end(), 0);
    //
    ll tmp = 0;
    ll mn = 100000000000000000;
    rep(i, N)
    {
        tmp += W[i];
        chmin(mn, abs(total - 2*tmp));
    }
    cout << mn;
    //
    return 0;
}

Measured memory_bytes: 3648
import itertools

n = int(input())
s = []
textSet = set()
ans = 0

for i in range(n):
    s.append(''.join(sorted(input())))

s.sort()

# print(s)
cnt = 0

for i in range(1, n):
    if s[i] == s[i-1]:
        cnt += 1
    elif cnt > 0:
        # ans += cntC2
        # ans += len(list(itertools.combinations(range(cnt+1), 2)))
        ans += (cnt + 1) * cnt // 2
        cnt = 0

if cnt > 0:
    # ans += len(list(itertools.combinations(range(cnt + 1), 2)))
    ans += (cnt + 1) * cnt // 2

print(ans)

Measured memory_bytes: 58584
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s,t1,t2;
	cin>>s;
	for(int i=0;i<n/2;i++)
		t1+=s[i];
	for(int i=n/2;i<n;i++)
		t2+=s[i];
	if(t1==t2)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define inf             1e18
#define MAX             1e9
#define MIN            -1e9
#define no_of_test(x)        int x; cin>>x; while(x--)
//Actual Code Is At The Top
const int mod = 1e9 + 7;
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int32_t main()
{   
	very_slow
//	no_of_test(x)
	{  
      int n;
	  cin>>n;
	  int sum=0;
	  for(int i=1;i<=n;i++)
	  {
		  if(i%3!=0 && i%5!=0)
		  {
			  sum+=i;
		  }
	  }
	  cout<<sum<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
int main(){
	int N;
	unsigned long long S=1;
	long long P[1001]={0};
	scanf("%d",&N);
	int d;
	for(int i=2;i<=N;i++){//iの約数を求める
		d = i;
		for(int j=2;d>1;j++){//素因数分解
			while(d%j==0){
				P[j]+=1;
				d /= j;
			}
		}
	}
	for(int i=2;i<=N;i++){
		S = (S * (P[i] + 1)) % 1000000007;
		//printf("%llu\n",S);
	}
	printf("%llu",S);
	return 0;
}

Measured memory_bytes: 128
num = int(input())

nowMax = 0

retu       = input().split()
list_up   = list( map((lambda x:int(x)),retu))
retu       = input().split()
list_down = list( map((lambda x:int(x)),retu))

#下に降りるタイミングを決めるためのループ
for w in range(num):
    total = 0

    #1段目の合計を足すためのループ
    for x in range(0,w+1):
        total = total + list_up[x]

    for y in range(w,num):
        total = total + list_down[y]

    if total > nowMax:
        nowMax = total

print(nowMax)



Measured memory_bytes: 3064
#!usr/bin/env python3

def seconds_to_hms_format(seconds):
    m, s = divmod(int(seconds), 60)
    h, m = divmod(m, 60)
    return "%d:%d:%d" % (h, m, s)


def main():
    seconds = input()
    print(seconds_to_hms_format(seconds))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7740
a, b, c = map(int,input().split())

def aa():
    if a == b and a == c:
        if a % 2 == 0:
            return -1
        else:
            return 0
    else:
        A = [a-b, b-c, c-a]
        j = 0
        while True:
            for i in range(3):
                if A[i] % 2 == 1:
                    return j
                else:
                    A[i] //= 2
            j += 1

print(aa())

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

int main(){
  int i,j,k,b,N;
  vector<vector<int>> A(3, vector<int>(3));

  for(i=0;i<3;++i){
    for(j=0;j<3;++j){
      cin >> A.at(i).at(j);
    }
  }
  cin >> N;
  for(i=0;i<N;++i){
    cin >> b;
    for(j=0;j<3;++j){
      for(k=0;k<3;++k){
        if(A.at(j).at(k)==b)
          A.at(j).at(k) = 0;
      }
    }
  }
  if(A.at(0).at(0)==0&&A.at(0).at(1)==0&&A.at(0).at(2)==0){
    cout << "Yes";
  }else if(A.at(1).at(0)==0&&A.at(1).at(1)==0&&A.at(1).at(2)==0){
    cout << "Yes";
  }else if(A.at(2).at(0)==0&&A.at(2).at(1)==0&&A.at(2).at(2)==0){
    cout << "Yes";
  }else if(A.at(0).at(0)==0&&A.at(1).at(0)==0&&A.at(2).at(0)==0){
    cout << "Yes";
  }else if(A.at(0).at(1)==0&&A.at(1).at(1)==0&&A.at(2).at(1)==0){
    cout << "Yes";
  }else if(A.at(0).at(2)==0&&A.at(1).at(2)==0&&A.at(2).at(2)==0){
    cout << "Yes";
  }else if(A.at(0).at(0)==0&&A.at(1).at(1)==0&&A.at(2).at(2)==0){
    cout << "Yes";
  }else if(A.at(0).at(2)==0&&A.at(1).at(1)==0&&A.at(2).at(0)==0){
    cout << "Yes";
  }else
    cout << "No";
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    //    
    int a, b;
    char c;
    //
    scanf("%d %c %d",&a,&c,&b);
    //
    if(c == '+')
        printf("%d\n",a+b);
    else
        printf("%d\n",a-b);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int a,b,c,d;
	
	scanf("%d %d %d %d",&a,&b,&c,&d);
	
	if(a+b > c+d)	printf("Left");
	else if(a+b == c+d)	printf("Balanced");
	else printf("Right");
	
	
	return 0;
}

Measured memory_bytes: 128
n, j = map(int, input().split())
t = [int(i) for i in input().split()]

ans = 0

for i in range(1, len(t)):
	if t[i] - t[i-1] < j:
		ans += (t[i] - t[i-1])
	else:
		ans += j

print(ans + j)


Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    ll K;
    cin>>K;
    queue<ll> q;
    for(ll i=1;i<10;i++){
        q.push(i);
    }
    ll res=0;
    for(ll i=1;i<=K;i++){
        res=q.front();
        ll num1=res;
        ll num2=res;
        if(res%10==0){
            num1=num1*10;
            num2=num2*10+1;
            q.push(num1);
            q.push(num2);
        }else if(res%10==9){
            num1=num1*10+9;
            num2=num2*10+8;
            q.push(num2);
            q.push(num1);
        }else{
            num1=num1*10+(res%10-1);
            num2=num2*10+(res%10+1);
            q.push(num1);
            ll x=res*10+(res%10);
            q.push(x);
            q.push(num2);
        }
        q.pop();
    }
    cout<<res<<endl;
    return 0;

}


Measured memory_bytes: 1792
N, M = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x
            
        self.par[y] = x
    
    def get_par(self):
        return self.par

t = UnionFind(N)
for u, v, _ in edges:
    t.unite(u - 1, v - 1)

print(len(set(t.find(x) for x in range(N))))


Measured memory_bytes: 94040
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define mod (int)(1e9 + 7) 

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n][n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			 cin >> a[i][j];
		}
	}
	vector<int> dp(1 << n);
	dp[0] = 1;
	for(int mask = 0; mask < (1 << n) - 1; mask++){
		int men = __builtin_popcount(mask);
		for(int women = 0; women < n; women++){
			if(a[men][women] && !(mask &(1 << women))){
				int new_mask = mask ^ (1 << women);
				dp[new_mask] += dp[mask];
				if(dp[new_mask] > mod){
					dp[new_mask] -= mod;
				}
			}
		}
	}
	cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 11392
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  int n;
  cin>>n;
  REP(aaaaa,n) {
    vector<uint64_t> a(9);
    uint64_t k = 0;
    REP(i,9) cin >> hex >> a[i];
    REP(i,32) {
      uint64_t sum = 0;
      REP(j,8) {
        sum += a[j] & ((UINT64_C(1) << (i+1)) - 1);
      }
      k |= (sum ^ a[8]) & (UINT64_C(1) << i);
      REP(j,9) {
        a[j] ^= (sum ^ a[8]) & (UINT64_C(1) << i);
      }
    }
    cout<<hex<<k<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
import java.util.*;
import java.io.*;

public class Main {
	

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.printf("%.10f\n",ans.solve());
	}

	private double solve(){

		Scanner sc= new Scanner(System.in);
		int N = sc.nextInt();
		double [] array = new double[N+1];
		for(int i=1;i<=N;i++){
			array[i] = sc.nextDouble();
		}

		double [][] dp = new double[3001][3001];
		for(int i=0;i<3001;i++) {
			Arrays.fill(dp[i], -1.0);
		}

		return solve(array, N, (N+1)/2, dp);
	}

	private double solve(double[] array, int total, int requiredHeads, double [][] dp) {
		if (requiredHeads==0) return 1;
		if (total==0) return 0;
		if (dp[total][requiredHeads] > -0.9) return dp[total][requiredHeads];
		double ans = (array[total] * solve(array, total-1, requiredHeads-1, dp)) +  ((1-array[total]) * solve(array, total-1, requiredHeads, dp));
		dp[total][requiredHeads] = ans;
		return ans;
	}
	
}

Measured memory_bytes: 119008
#include<iostream>
#include<algorithm>
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert	//tentative

int m,dp[1999][1999],c[2000][2000];

#define BIT_MAX_N 100000 

long long bit[BIT_MAX_N+1];

void update(int k,int a){
	while(k<=m){
		bit[k]+=a;
		k=(k|(k-1))+1;
	}
}

long long s(int k){
	long long r=0;
	while(k>0){
		r+=bit[k];
		k=k&(k-1);
	}
	return r;
}

int main(){
	int n,l,k[2000],a=0,ind=1;
	long long b=0;
	cin>>n>>m>>l;
	for(int i=0;i<n;++i){
		cin>>k[i];
	}
	sort(k,k+n);
	for(int j=1;j<=m;++j){
		int S;
		cin>>S;
		while(ind<n-1&&j==k[ind]){
			b+=S;
			++ind;
		}
		update(j,S);
	}
	b+=2*(s(k[n-1])-s(k[0]-1));
	for(int i=0;i<n-1;++i){
		for(int j=i+1;j<n;++j){
			c[i][j]=(s(k[j])-s(k[i]-1))%l;
		}
	}
	dp[0][1]=c[0][1];
	for(int j=2;j<n-1;++j){
		for(int i=0;i<j-1;++i){
			dp[i][j]=dp[i][j-1]+c[j-1][j];
		}
		dp[j-1][j]=0;
		for(int k=0;k<j-1;++k){
			dp[j-1][j]=max(dp[j-1][j],dp[k][j-1]+c[k][j]);
		}
	}
	for(int i=0;i<n-2;++i){
		a=max(a,dp[i][n-2]+c[i][n-1]);
	}
	a+=c[n-2][n-1];
	cout<<(b-a)/l<<endl;
}

Measured memory_bytes: 31452
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;
#define INF 1010101010
#define MOD 1000000007
#define LL long long
 
int main() {
    int x; cin >> x;
    int s = 0;
    int i = 0;
    while(s < x) {
        i++;
        s += i;
    }
    cout << i << endl;
}

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

int main() {
	int N, M, X, Y, x, y, xMax = -100, yMin = 100;
	cin >> N >> M >> X >> Y;
	for (int i = 0;i < N;++ i) {
		cin >> x;
		xMax = xMax > x ? xMax : x;
	}
	for (int i = 0;i < M;++ i) {
		cin >> y;
		yMin = yMin < y ? yMin : y;
	}
	cout << (xMax < yMin && X < yMin && xMax < Y ? "No " : "") << "War";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

xに関しては最大のみ、yに関しては最小のみ考えれば良くて、後は場合分けで終わる
*/

Measured memory_bytes: 256
package main

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

const (
	Q_CAP = 0.25
	H_CAP = 0.5
	S_CAP = 1
	D_CAP = 2
)

type IceTea struct {
	price int
	internalCapacity float64
}

func (iceTea *IceTea) set(price int,cap float64) {
	iceTea.price = price
	iceTea.internalCapacity = cap
}

func (iceTea IceTea) pricePerLiter() int {
	return int(float64(iceTea.price) * (1.0 / iceTea.internalCapacity))
}

func (iceTea IceTea) numberPerLitter() int {
	return int(1.0 / iceTea.internalCapacity)
}

func (iceTea IceTea) String() string {
	return fmt.Sprintf("%4v%v%v",iceTea.internalCapacity,":",iceTea.price)
}

type List []IceTea

func (list List) lowest() IceTea {
	var iceTea IceTea = list[0]
	var min int = iceTea.pricePerLiter()
	for _,val := range list[1:] {
		if val.pricePerLiter() < min {
			iceTea = val
			min = iceTea.pricePerLiter()
		}
	}
	return iceTea
}

func (list List) remove(index int) List {
	copy(list[index:],list[index + 1:])
	return list[:len(list) - 1]
}

func (list List) String() string {
	var str string
	for _,val := range list {
		str += fmt.Sprintln(val)
	}
	return str
}

func scanNumber(input *bufio.Scanner) int {
	input.Scan()
	num,err := strconv.Atoi(input.Text())

	if err != nil {
		panic(err)
	}

	return num
}

var capList []float64 = []float64{Q_CAP,H_CAP,S_CAP,D_CAP}

func main() {
	var Q,H,S,D IceTea
	var N int

	input := bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)

	Q.set(scanNumber(input),Q_CAP)	//0.25
	H.set(scanNumber(input),H_CAP)	//0.5
	S.set(scanNumber(input),S_CAP)	//1
	D.set(scanNumber(input),D_CAP)	//2

	N = scanNumber(input)

	list := make(List,4)
	list = []IceTea{Q,H,S,D}

	for key,val := range capList {
		if float64(N) < val {
			list = list.remove(key)
		}
	}

	var total int
	remain := N
	min := list.lowest()

	if D_CAP == min.internalCapacity {
		remain, total = remain % D_CAP,total + (D.price * (remain / D_CAP))
		min = list.remove(4 - 1).lowest()
	}

	remain,total = int(math.Mod(float64(remain),min.internalCapacity)),total + min.price * int(float64(remain) / min.internalCapacity)

	fmt.Println(total)
}


Measured memory_bytes: 640
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var lines = input.split('\n');

  var _splitNum = splitNum(lines[0]),
      _splitNum2 = _slicedToArray(_splitNum, 2),
      N = _splitNum2[0],
      X = _splitNum2[1];

  var xs = splitNum(lines[1]).slice(0, N);
  var rels = xs.map(function (x) {
    return Math.abs(x - X);
  });
  var D = rels.length > 1 ? rels.reduce(gcd) : rels[0];
  console.log(D);
}

function gcd(a, b) {
  while (b > 0) {
    if (a < b) {
      var _ref = [b, a];
      a = _ref[0];
      b = _ref[1];
      continue;
    }

    var _ref2 = [b, a % b];
    a = _ref2[0];
    b = _ref2[1];
  }

  return a;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 28308
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef long long LL;
typedef  vector<int> VI;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	VI hill;
	REP(i, 10)
	{
		int temp;
		cin >> temp;
		hill.push_back(temp);
	}
	SORT(hill);
	COUT(hill[9]);
	COUT(hill[8]);
	COUT(hill[7]);
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n,a,b;
  cin>>n>>a>>b;

  cout<<(((a-b)%2)? "Borys":"Alice")<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string.h> 
#include <vector>
#include <bits/stdc++.h> 
#include <iomanip>
#include<algorithm> 
#include <string> 
using namespace std;

int main(){
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    double dp[n+1][n+1];
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[0][i]=0;
    }
    for(int i=1;i<=n;i++){
        dp[i][0]=(dp[i-1][0])*(1-a[i-1]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j] = (dp[i-1][j])*(1-a[i-1]) + (dp[i-1][j-1])*a[i-1];
        }
    }
    double s=0;
    for(int i=(n/2)+1;i<=n;i++){
        s += dp[n][i];
    }
    cout << std::setprecision(10) << s << '\n';
}


Measured memory_bytes: 70528