akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n;
string s;

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

ll fac(int n){
    if(n==0||n==1) return 1;
    return n*fac(n-1);
}

int main(){
    cin>>n;
    vector<int> a(n);
    int m=1000,M=-1000;
    rep(i,0,n){
        cin>>a[i];
        m=min(m,a[i]);
        M=max(M,a[i]);
    }
    int mins=1000000000;
    rep(i,m,M+1){
        int sum=0;
        rep(j,0,n) sum+=(a[j]-i)*(a[j]-i);
        mins=min(mins,sum);
    }

    cout<<mins<<endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	bitset<64> bs(0);
	int Q=in();
	REP(i,Q){
		int q=in();
		if(q==1){
			bs[in()] = true;
		}
		else if(q==2){
			bs[in()] = false;
		}
		else if(q==3){
			bs[in()].flip();
		}
		else if(q==4){
			out(bs.all()?1:0);
		}
		else if(q==5){
			out(bs.any()?1:0);
		}
		else if(q==6){
			out(bs.none()?1:0);
		}
		else if(q==7){
			out(bs.count());
		}
		else if(q==8){
			out(bs.to_ullong());
		}
		else{
			out(bs[in()]?1:0);
		}
	}

	return 0;
}


Measured memory_bytes: 3148
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
Main();
function Main(){
  var one = nextIntArray();
  var A = one[0];
  var B = one[1];
  if(B % A == 0){
     myout(A + B);
  }else{
     myout(B - A);
  }
}


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
#define INF 1e9
typedef vector<int> VI;
typedef vector<string> VS;
int main()
{
int n,l;
cin>>n>>l;
VS vec(n);
for (int i = 0; i < n; i++)
{
    cin>>vec.at(i);

}
sort(ALL(vec));
for (int i = 0; i < n; i++)
{
  cout<<vec.at(i);
}
cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  dp=[inf]*100010
  dp[0]=0

  for j in range(n):
    for i in range(1,k+1):
      if i+j<n:
        dp[i+j]=min(dp[i+j],dp[j]+abs(l[i+j]-l[j]))

  return dp[n-1]

print(main())


Measured memory_bytes: 79764
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B,C,K; cin >> A >> B >> C >> K;
    string ans = "No";
    for (int i=0; i<=K; ++i){
        int r = A, g = B, b = C;
        for (int b=0; b<i; ++b) g *= 2;
        for (int c=0; c<(K-i);++c) b *= 2;
        if (r<g && g<b) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
	bool bf = false;
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		if (bf) cout << endl;

		int m[9][9];
		for (int y = 0; y < 9; ++y)
			for (int x = 0; x < 9; ++x) {
				cin >> m[y][x];
				--m[y][x];
			}

		bool wa[9][9] = {0};
		for (int y = 0; y < 9; ++y) {
			bool f[9] = {0}, w[9] = {0};
			for (int x = 0; x < 9; ++x)
				if (f[m[y][x]]) w[m[y][x]] = true;
				else f[m[y][x]] = true;

			for (int x = 0; x < 9; ++x)
				if (w[m[y][x]]) wa[y][x] = true;
		}
		for (int x = 0; x < 9; ++x) {
			bool f[9] = {0}, w[9] = {0};
			for (int y = 0; y < 9; ++y)
				if (f[m[y][x]]) w[m[y][x]] = true;
				else f[m[y][x]] = true;

			for (int y = 0; y < 9; ++y)
				if (w[m[y][x]]) wa[y][x] = true;
		}
		for (int y = 0; y < 3; ++y)
			for (int x = 0; x < 3; ++x) {
				bool f[9] = {0}, w[9] = {0};
				for (int dx = 0; dx < 3; ++dx)
					for (int dy = 0; dy < 3; ++dy) {
						int nx = x * 3 + dx;
						int ny = y * 3 + dy;

						if (f[m[ny][nx]]) w[m[ny][nx]] = true;
						else f[m[ny][nx]] = true;
					}

				for (int dx = 0; dx < 3; ++dx)
					for (int dy = 0; dy < 3; ++dy) {
						int nx = x * 3 + dx;
						int ny = y * 3 + dy;

						if (w[m[ny][nx]]) wa[ny][nx] = true;
					}
			}

		for (int y = 0; y < 9; ++y) {
			for (int x = 0; x < 9; ++x) {
				if (wa[y][x]) cout << "*";
				else cout << " ";

				cout << (m[y][x] + 1);
			}
			cout << endl;
		}

		bf = true;
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main() {
  string S;
  cin >> S;
  int a, b, c, d;
  a = S[0] - '0';
  b = S[1] - '0';
  c = S[2] - '0';
  d = S[3] - '0';
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int sum = a;
        char opt1 = '+';
        char opt2 = '+';
        char opt3 = '+';
        if (i == 1) {
          sum += b;
        } else {
          opt1 = '-';
          sum -= b;
        }

        if (j == 1) {
          sum += c;
        } else {
          opt2 = '-';
          sum -= c;
        }
        if (k == 1) {
          sum += d;
        } else {
          opt3 = '-';
          sum -= d;
        }
        //cout << sum << endl;
        if (sum == 7) {
          char shiki = S[0];
          cout << a << opt1 << b << opt2 << c << opt3 << d << "=7"<< endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let n = read::<usize>();
    let sum = (1..(n + 1)).fold(0, |acc, i| acc + i);
    let mut div = n;
    loop {
        if sum % div == 0 {
            if sum / div >= n {
                break;
            }
        }
        div -= 1;
    }

    let mut edge_num = 0;
    let mut edges = vec![];
    let mut used = vec![false; n + 1];
    for i in 1..div {
        let j = sum / div - i;
        for k in (i + 1)..(n + 1) {
            if k == j || used[k] {
                continue;
            }
            edges.push((i, k));
            edges.push((j, k));
            edge_num += 2;
        }
        used[i] = true;
        used[j] = true;
    }

    println!("{}", edge_num);
    for &(i, j) in edges.iter() {
        println!("{} {}", i, j);
    }
}

#[allow(dead_code)]
fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf.trim().parse().unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::with_capacity(100);
    stdin().read_line(&mut buf).unwrap();
    return buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::io::prelude::*;
    let stdin = stdin();
    let mut reader = BufReader::with_capacity(100 * 1024, stdin);
    let mut line = String::with_capacity(100);
    let mut matrix: Vec<Vec<T>> = Vec::new();

    while reader.read_line(&mut line).unwrap() > 0 {
        matrix.push(
            line.trim()
                .split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect(),
        );
        line.clear();
    }

    return matrix;
}

#[allow(dead_code)]
fn read_chars() -> Vec<char> {
    let stdin = stdin();
    let mut buf = String::new();
    let _bytes = stdin.read_line(&mut buf).unwrap();
    return buf.trim().chars().collect();
}


Measured memory_bytes: 4352
// D - Insertion
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);++i)

int main(){
	int _N; cin>>_N;//not used
	string S; cin>>S;

	int r = 0;//r = depth
	int l = 0;
	for(char s:S){
		if(s == '(') r++;
		else{
			r--;
			if(r < 0){
				r = 0;
				l++;
			}
		}
	}

	rp(i, l) S = "(" + S;
	rp(i, r) S = S + ")";
	cout<< S <<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int x;

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

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

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

  cin >> x;
  ll ans = lcm(x, 360);

  cout << ans / x << endl;
}


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

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

  int sum = A + B;
  int sub = A - B;
  int time = A * B;

  if (sum > sub){
    if (sum > time){
      cout << sum << endl;
      return 0;
    } else{
      cout << time << endl;
      return 0;
    }
  } else{
    if (sub > time){
      cout << sub << endl;
      return 0;
    } else{
      cout << time << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
int n,cnt[15],x[15][15],y[15][15],ans=0;
void check(int w)
{
	int num=0;
	REP(i,n)
		if(w>>i&1)
		{
			++num;
			REP(j,cnt[i])
				if((w>>x[i][j]&1)!=y[i][j])return;
		}
	ans=max(ans,num);
}
int main()
{
	cin>>n;
	REP(i,n)
	{
		cin>>cnt[i];
		REP(j,cnt[i])cin>>x[i][j]>>y[i][j],--x[i][j];
	}
	REP(i,1<<n)check(i);
	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);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[n - 1 - i] = sc.nextInt();
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; i++) {
            System.out.print(" " + a[i]);
        }
        System.out.println();
    }
}

Measured memory_bytes: 26280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define veci(x,n) vector<int> x((int) (n))
#define vecs(x,n) vector<string> x((int) (n))
#define vecbf(x,n) vector<bool> x((int) (n), false)

int main(){
  int n;
  cin >> n;
  veci(h,n);
  rep(i,n) cin >> h.at(i);
  int count = 0;
  bool flag = true;
  rep(i,n){
    for(int j=0;j<i;j++){
      flag = true;
      if(h.at(j) > h.at(i)){
        flag = false;
        break;
      }
    }
    if(flag) count++;
  }
  cout << count << endl;
}

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

int main() {
int N;
double ans;
cin >> N;

vector<double> v(N);
for (int i = 0; i < N; i++) {
  cin >> v.at(i);
}
sort(v.begin(), v.end());

ans = v.at(0) / pow(2, N - 1);
for (int i = 1; i < N; i++) {
 ans += v.at(i) / pow(2, N - i);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int m,n;
	cin >> n >> m;
	vector< vector<double> > d(n,vector<double>(n,0.0) );
	if(n == 0 && m == 0) break;
	REP(i,n)REP(j,n) cin >> d[i][j];
	double ans = 0.0;
	vector<double> a(n);
	double dp[2][101];
	REP(i,2)REP(j,101) dp[i][j] = 0;
	REP(i,101) dp[0][i] = 1;
	REP(i,m-1){
	    REP(j,101) dp[1][i] = 0;

	    REP(j,n){
		dp[1][j] = dp[0][0] * d[j][0];
		REP(k,n){
		    dp[1][j] = max(dp[1][j],dp[0][k] * d[j][k]);
		}
	    }
	    swap(dp[0],dp[1]);
	}
	REP(i,n) ans = max(dp[0][i],ans);
	int t = ans * 1000;
	t = t % 10;
//	if(t >= 5) ans += 0.01;
	printf("%.2f\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
using namespace std;
const int MOD = 1000000007;
long long fact[2005],ifact[2005];

long long power(long long a, long long  b)
{
	long long res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

long long nCr(int n, int r)
{
    return (fact[n]*ifact[r])%MOD*ifact[n-r]%MOD;
}

void solve()
{
    long long ans = 0;
    int N; cin >> N;
    if(N<=2){
        cout << 0 << endl;
        return;
    }

    fact[0]=1;
    for (int i = 0; i < N; ++i) fact[i+1]=fact[i]*(i+1)%MOD;
    ifact[N]=power(fact[N], MOD-2);
    for (int i = N-1; i >= 0; --i) ifact[i]=ifact[i+1]*(i+1)%MOD;

    int size = 1;
    while(N >= size*3){
        if(size==1){
            ans+=1; ++size; continue;
        }
        ans = (ans + nCr(N-2*size-1,size-1))%MOD;
        ++size;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int K;
    cin >> K;
    queue<long long> que;
    for(int i=1; i<=9; i++) que.push(i);
    while(true){
        K--;
        long long p = que.front();
        que.pop();
        if(K == 0){
            cout << p << endl;
            return 0;
        }
        long long a = p % 10;
        if(a != 0) que.push(10*p+a-1);
        que.push(10*p+a);
        if(a != 9) que.push(10*p+a+1);
    }
    return 0;
}



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

int main(){
    string st;
    cin >> st;
    int n = st.size();
    int f = 0;
    rep(i, (n-1)/2){
        if(st.at(i) != st.at(n-i-1)) f = 1;
    }
    rep(i, ((n-1)/2)/2){
        if(st.at(i) != st.at((n-1)/2-i-1)) f = 1;
    }
    for(int i=(n+3)/2-1; i<n; i++){
        if(st.at(i) != st.at(n-i-1)) f = 1;
    }
    if(f == 1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	string p = "AKIHABARA";

	string s;
	cin>>s;

	bool ok=false;
	rep(i,1<<4){
		string pp=p;
		int f=0;
		for (int j=0;j<pp.size();){
			if (pp[j] == 'A'){
				if (i >> f & 1){
					pp.erase(pp.begin()+j);
				}
				else{
					j++;
				}
				f++;
			}else j++;
		}
		if (s==pp)ok=true;

	}
	cout << (ok?"YES":"NO")<<endl;





	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  procon
//
//  Created by 坂井創一 on 2019/09/27.
//  Copyright © 2019 坂井創一. All rights reserved.
//
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,k,n) for(int i=k;i<(int)(n);i++)
#include <iostream>
#include <queue>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,m;
    priority_queue<int> que;
    cin >> n >> m;
    rep(i,n){
        int t;
        cin >> t;
        que.push(t);
    }
    rep(i,m){
        int t = que.top();
        que.pop();
        que.push(t/2);
    }
    long long sum = 0;
    rep(i,n){
        sum += que.top();
        que.pop();
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 892
/* DELAPAN.3gp */
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;

#ifdef DEBUG
	#define debug(...) printf(__VA_ARGS__)
	#define GetTime() fprintf(stderr,"Running time: %.3lf second\n",((double)clock())/CLOCKS_PER_SEC)
#else
	#define debug(...) 
	#define GetTime() 
#endif

//type definitions
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vint;

//abbreviations
#define A first
#define B second
#define MP make_pair
#define PB push_back

//macros
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n)-1; 0 <= i; --i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for (int i = (a); (b) <= i; --i)
#define FORIT(it,c) for (__typeof ((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define RESET(a,x) memset(a,x,sizeof(a))
#define EXIST(a,s) ((s).find(a) != (s).end())
#define MX(a,b) a = max((a),(b));
#define MN(a,b) a = min((a),(b));

inline void OPEN(const string &s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

/* -------------- end of DELAPAN.3gp's template -------------- */

int n, a[100100];

int main(){
	scanf("%d", &n);
	map<int, int> pos;
	FOR(i, 1, n) {
		scanf("%d", &a[i]);
		pos[a[i]] = i;
	}
	sort(a + 1, a + n + 1);
	int ans = 0;
	FOR(i, 1, n) {
		if ((pos[a[i]] - i) % 2 != 0) {
			ans++;
			// printf("NOT CORRECT: %d\n", a[i]);
		}
	}
	assert(ans % 2 == 0);
	printf("%d\n", ans / 2);
	
	return 0;
}


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

int main() {
  int a,b; cin >> a >> b;
  vector<int>v{1,2,1,3,1,3,1,1,3,1,3,1};
  if(v.at(a-1)==v.at(b-1)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  long long int X;
  cin>>X;
  for(long long int A=0; A<=200; A++){
    for(long long int B=-A; B<=A; B++){
      if((long long int)(pow(A,5))-(long long int)(pow(B,5))==X){
        cout<<A<<" "<<B<<endl;
        return 0;
      }
    }
  }
  return 0;
}


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

using namespace std ;

int main(){
    int n,m;
    int counter=0;

    cin>>n>>m;

    int a[n];
    for(int i=0;i<m;i++){
        cin>>a[i];
        counter+=a[i];
        if(counter>n){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<n-counter<<endl;

    

}

Measured memory_bytes: 3672
import math

times = [0]*5
for i in range(5):
    times[i] = int(input())

#1桁目が一番小さいものを判断する
mini = 10
idx = 9
for time in times:
    if time%10 < mini and time%10 > 0:
        mini = min(mini,time%10)
        idx = times.index(time)

total = 0
for i in range(5):
    if i == idx:
        total += times[i]
    else:
        total += math.ceil(times[i]/10)*10
print(total)


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n,a,b,c,d,i,x,y,z;
	cin>>n>>a>>b>>c>>d;
	for(i=1;i<=n;i++){
		x=a*i;
		if(n-x<=0){
			z=i;
			break;
		}
	}
	x=b*z;
	for(i=1;i<=n;i++){
		y=c*i;
		if(n-y<=0){
			z=i;
			break;
		}
	}
	y=d*z;
	if(x<y) cout<<x<<endl;
	else cout<<y<<endl;
	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ERR 1e-9
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<double>p;
	for(int i=0;i<n;i++)
	{
		double x;
		cin>>x;
		p.push_back(x);
	}
    vector<vector<double>>dp(n+1,vector<double>(n+1,0));
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
    	for(int j=0;j<=n;j++)
    	{
    		if(j==0)
    		{
    			dp[i][j]=(1-p[i-1])*dp[i-1][j];
    		}
    		else
    		{
    			dp[i][j]=((1-p[i-1])*dp[i-1][j])+(p[i-1]*dp[i-1][j-1]);
    		}
    	}
    }
    double prob_greater_than_n=0;
    int count=ceil(n/2);
    for(int i=count+1;i<=n;i++)
    {
    	prob_greater_than_n+=dp[n][i];
    }
    cout<<setprecision(9)<<prob_greater_than_n<<endl;
 	return 0;
}

Measured memory_bytes: 70784
import sys
stdin = sys.stdin
def na():
    return map(int,stdin.readline().split())
def ns():
    return stdin.readline().strip()
N, M = na()
a = []
b = []

for i in range(N):
    a.append(ns())
for i in range(M):
    b.append(ns())

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            if a[i+k][j:j+M] != b[k]:
                flag = False
                break
        if flag:
            print("Yes")
            sys.exit(0)
print("No")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int a[200], b[200], sum[200], n, i=0, j;
	while(scanf("%d %d", &a[i], &b[i])!=EOF) {
		sum[i]=a[i]+b[i];
		i++;
	}
	for(j=0;j<i;j++) {
		n=1;
		while(sum[j]>=10) {
			n++;
			sum[j]=sum[j]/10;
		}
		printf("%d\n",n);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int k;
	while(1){
		cin>>k;
		if(k==0) break;
		int sum=0;
		rep(i,0,k*(k-1)/2){
			int c;
			cin>>c;
			sum+=c;
		}
		o(sum/(k-1));
	}

}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define int long long
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define pp pair<int,int>
#define N 200007 // check
#define M
#define K 76
#define endl "\n"
using namespace std;

int n;

const int rg = 1 << 18;
const int sz = 1 << 19;

int tab[N];
int temp[N];
int tree[sz];

void clean() {
    //cout << "clean\n";
    for(int i = 0; i < sz; ++i) tree[i] = 0;
}

void add(int x, int val) {
    //cout << "nap " << x << endl;
    int temp = rg+x-1;
    while(temp != 0) {
        tree[temp] += val;
        temp/=2;
    }
}

void update(int x) {
    //cout << "dodaje " << x << endl;
    add(x+n+2, 1);
}

int sum2(int i, int start, int meta, int a, int b) {
    if(a <= start and  b >= meta) {
        return tree[i];
    }
    if(a > meta or b < start) return 0;
    int s = (start+meta)/2;
    return  sum2(i*2, start, s, a, b) + sum2(i*2+1, s+1, meta, a, b);
}

int sum(int a, int b) {
   // cout << "wynik z " << a << " " << b << endl;
    int t =  sum2(1,1,rg,a+n+2,b+n+2);
    /*cout << t << endl;*/ return t;
}

int numberOfLess(int t) {
    clean();
    for(int i = 0; i < n; ++i) {
        if(tab[i] < t) {
            temp[i] = -1;
        }
        if(tab[i] > t) {
            temp[i] = 1;
        }
        if(tab[i] == t) {
            temp[i] = -1;
        }
    }

    int licz = 0;
    int res = 0;

    update(0);

    for(int i = 0; i < n; ++i) {
        licz += temp[i];
        //cout << "licznik " << licz << endl;
        res += sum(max(-n-1-licz,-n-1), min(-licz-1,n));
        //cout << "__________________________\n";
        update(-licz);
    }
    return res;
}

int sorted[N];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> tab[i];
        sorted[i] = tab[i];
    }

    int nn = (n*(n-1)/2 + n);

    int ile = (nn&1)? nn/2+1 : nn/2+1;

    sort(sorted, sorted + n);

    int l = 0; int r = n-1;
    while(r - l > 4) {
        int s = (r+l)/2;
        if(numberOfLess(sorted[s]) >= ile) {
            r = s;
        } else {
            l = s;
        }
    }

    for(int i = l; i <= r; ++i) {
        if(numberOfLess(sorted[i]) >= ile) {
            cout << sorted[i] << endl; /*cout << "ans -------------- \n";*/ break;
        }
    }

    /*for(int i = 0; i < 1; ++i) {
        cout << "test " << i << " " << tab[i] << endl;
        cout << numberOfLess(tab[i]) << endl;
    }
    cout << "ile " << ile <<  " nn " << nn << " n " << n << endl;*/
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Read();
            var ans = int.Parse(N.Substring(0, 1));
            for (int i = 1; i < N.Length; i++)
            {
                var chk = int.Parse(N.Substring(i, 1));
                if (chk != 9)
                {
                    ans += (N.Length - i) * 9;
                    ans--;
                    break;
                }
                else
                {
                    ans += 9;
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int main () {
    int n,m,c;
    cin>>n>>m>>c;
    int b[m];
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++) {
            cin>>a[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=0;j<m;j++){
            sum+=a[i][j]*b[j];
        }

        if(sum+c>0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())

#AA = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
#S.index(AA)
AA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans=''
for i in range(len(S)):
    x = AA.find(S[i])
    y = (x + N) % 26
    ans += AA[y]
print(ans)

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

int main(){
  ll N, x;  cin >> N >> x;
  ll ans = 0;
  ll prv = 0;
  for(int i = 0; i < N; i++){
    ll a; cin >> a;
    if(prv + a > x){
      ans += prv + a - x;
      prv = x - prv;
    }else prv = a;
  }
  cout << ans << endl;
}

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

int main(){
  int day;
  cin >> day;

  switch((day+4)%7){
    case 0:
      cout << "sun\n";
      break;
    case 1:
      cout << "mon\n";
      break;
    case 2:
      cout << "tue\n";
      break;
    case 3:
      cout << "wed\n";
      break;
    case 4:
      cout << "thu\n";
      break;
    case 5:
      cout << "fri\n"; 
      break;
    case 6:
      cout << "sat\n";
      break;
  }

  return 0;
}



Measured memory_bytes: 3100
import numpy as np


N = int(input())
A = np.array(input().split(), np.int32)
B = np.array(input().split(), np.int32)
C = np.array(input().split(), np.int32)

A_diff = np.zeros(A.shape)
A_diff[1:] = np.diff(A, n=1)

res = 0

for i, diff_num in zip(A, A_diff):
    res += B[i-1]
    if diff_num == 1:
        res  += C[i-2]

print(res)


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

Measured memory_bytes: 2592
/**
 *    author:  Sanchit Sinha
 *    created: 26.09.2020 20:19:14       
**/
#include "bits/stdc++.h"
using namespace std; 

#define ll long long 
ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}

int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n;
        cin>>n;
        for(ll i=0;i<n;i++) cout<<"ACL";
        cout<<"\n";

        return 0;
}


Measured memory_bytes: 3652
import fractions
N,M = map(int,input().split())
A = list(map(int,input().split()))
t=1
while A:
 b=0
 for i in range(N):
  A[i]=int(A[i]/2)
  if A[i]%2==1:
   b+=1
 if b==N:
  break
 elif 0<b<N:
  t=0
  break
 else:
  t+=1
if t==0:
 print(0)
else:
 ans = A[0]
 for i in range(1, N):
  ans = ans * A[i] // fractions.gcd(ans, A[i])
 ans=min(ans,(M+1))
 c=int(M/(2**(t-1))/ans)
 d=int(M/(2**(t))/ans)
 print(c-d)

Measured memory_bytes: 16280
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define ALL(a) a.begin, a.end()

using namespace std;

int main(void) {

	int N;
	long kill = 0, sum = 0;

	cin >> N;

	vector<long> A(N + 1), B(N);

	REP(i, N + 1) cin >> A[i];
	REP(i, N) cin >> B[i];

	REP(i, N) {
		kill = min(A[i], B[i]);
		A[i] -= kill;
		B[i] -= kill;
		sum += kill;
		if (B[i] != 0) {
			kill = min(A[i+1], B[i]);
			A[i+1] -= kill;
			B[i] -= kill;
			sum += kill;
		}
	}

	cout << sum << "\n";

	return 0;
}

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

int main() {
	char num[1000];
	int i;
	int sum;

	while (scanf("%s", num), strcmp(num, "0") != 0) {
		sum = 0;

		for (i = 0;i < strlen(num);i++) {
			sum += num[i] - '0';
		}

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

Measured memory_bytes: 536
#include<cstdio>
#include<iostream>
using namespace std;
const long long mod=1e9+7;
long long inv[10010];
long long mul[10010];
long long ksm(long long x,long long p){
	long long ret=1;
	while(p){
		if(p&1) ret=ret*x%mod;
		x=x*x%mod;p/=2;
	}
	return ret;
}
long long get_inv(long long x){return ksm(x,mod-2);}
void pred(){
	long long s=1;
	for(int i=1;i<=10000;i++) s=s*i%mod,mul[i]=s;
	inv[10000]=get_inv(s);
	for(int i=9999;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
long long calc(long long n,long long m){return mul[n]*inv[m]%mod*inv[n-m]%mod;}
int a[200010],b[200010];
long long dp[4010][4010];
int main(){
	int n;
	scanf("%d",&n);
	pred();
	for(int i=1;i<=n;i++) scanf("%d%d",a+i,b+i);
	for(int i=1;i<=n;i++) dp[2000-a[i]][2000-b[i]]++;
	for(int i=1;i<=4000;i++) dp[0][i]+=dp[0][i-1],dp[i][0]+=dp[i-1][0];
	for(int i=1;i<=4000;i++)
		for(int j=1;j<=4000;j++)
			dp[i][j]=(dp[i][j]+dp[i-1][j])%mod+dp[i][j-1]%mod,dp[i][j]%=mod;
	long long ans=0;
	for(int i=1;i<=n;i++){
		ans=(ans+dp[a[i]+2000][b[i]+2000]%mod-calc(a[i]+b[i]+a[i]+b[i],a[i]+a[i])%mod)%mod;
		ans%=mod;
	}
	ans=(ans%mod+mod)%mod;
	printf("%lld",get_inv(2)%mod*ans%mod);
	return 0;
}

Measured memory_bytes: 127616
#include <bits/stdc++.h>
#define rep(I,N) for(int I=0;I<N;I++)
using ll=long long int;
using namespace std;
const int M=1000005;
int su=0;
int main(){
	ll n;
	cin>>n;
	vector<int> cnt(M);
	vector<int> a(n);
	rep(i,n){
		cin>>a[i];
	}
	for(int x : a){
		if(cnt[x]!=0){
			cnt[x]=2;
			continue;
		}
		for(int i=x;i<M;i=i+x){
			cnt[i]+=1;
		}
	}
	for(int x:a){
		if(cnt[x]==1)su+=1;
	}
	cout<<su;
}

Measured memory_bytes: 8008
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,k;
  cin>>n>>k;
  int w[n];
  for(int i=0;i<n;i++) cin>>w[i];
  int sum=0;
  for(int i=0;i<n;i++) sum+=w[i];
  int l=0,r=sum;
  while(l+1<r){
    int m=(l+r)/2;
    int t=0,tmp=0;
    bool f=0;
    for(int i=0;i<n;i++){
      f|=w[i]>m;
      if(tmp+w[i]>m){
	tmp=w[i];
	t++;
      }else tmp+=w[i];
    }
    if(tmp) t++;
    if(!f&&t<=k) r=m;
    else l=m;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3872
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2) for _ in range(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='#':
      exlarge[i+1][j+1]=1
 
for k in range(H+2):
  for l in range(W+2):
    if exlarge[k][l]==1 and exlarge[k][l-1]== exlarge[k][l+1]==exlarge[k-1][l]==exlarge[k+1][l]==0:
          ans='No'
 
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    vector<int> d(k);
    vector<vector<int>> a(k);

    for(int i=0; i<k; i++){
        cin >> d[i];
        for (int j=0; j<d[i]; j++){
            int tmp;
            cin >> tmp;
            a[i].push_back(tmp);
        }
    }

    vector<int> hum(n,0);

    for(auto i:a){
        for(auto j:i){
            hum[j-1]++;
        }
    }

    int sum=0;
    for(auto i:hum){
        if(i==0){
            sum++;
        }
    }

    cout << sum << endl;
    
    return 0;
}

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

using namespace std;
int _w;

int n, a[20], b[20], ans;

int check() {
	int x = 1;
	for( int i = 0; i < n; ++i )
		x = x * b[i] % 2;
	return !x;
}
void dfs( int i ) {
	if( i == n )
		return void(ans += check());
	b[i] = a[i] - 1, dfs(i+1);
	b[i] = a[i], dfs(i+1);
	b[i] = a[i] + 1, dfs(i+1);
}

int main() {
	_w = scanf( "%d", &n );
	for( int i = 0; i < n; ++i )
		_w = scanf( "%d", a+i );
	dfs(0);
	printf( "%d\n", ans );
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}
int N, Q;
Graph G;
vector<int> ten;
vector<int> res;
void dfs(int v, int pa, int c) {
   //  cout << v << "," << pa << "," << c << endl;
    res[v] = c + ten[v];
    for(auto e : G[v]) {
        if(e == pa) {
            continue;
        } else {
            dfs(e, v, res[v]);
        }
    }
}
int main() {
    cin >> N >> Q;
    G.assign(N, vector<int>());
    ten.assign(N, 0);
    res.assign(N, 0);
    rep(i, 0, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, 0, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        ten[p] += x;
    }

    dfs(0, -1, 0);
    rep(i, 0, N) {
        cout << res[i];
        if(i != N-1)
            cout << " ";
    }
    cout<<endl;
}

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

const int maxs = (1 << 16); 
const int mod = 1e9 + 7; 

int n, m; 
int a[20], cnt[maxs]; 
int f[20][maxs];
int fac[maxs + 5], ivf[maxs + 5]; 

int fpw(int x, int k, int p) {
    int ret = 1; 
    while (k) {
        if (k & 1) ret = 1ll * ret * x % p; 
        x = 1ll * x * x % p; 
        k >>= 1; 
    }
    return ret; 
}

int add(int x, int y) {
    return (x += y) >= mod ? x - mod : x; 
}

void work() {
    fac[0] = 1; 
    for (int i = 1; i <= maxs; i++) {
        fac[i] = 1ll * fac[i - 1] * i % mod; 
        cnt[i] = cnt[i >> 1] + (i & 1); 
    }
    ivf[maxs] = fpw(fac[maxs], mod - 2, mod); 
    for (int i = maxs - 1; i >= 0; i--) {
        ivf[i] = 1ll * ivf[i + 1] * (i + 1) % mod; 
    }
} 

int c(int n, int m) {
    return (n < m) ? 0 : 1ll * fac[n] * ivf[n - m] % mod * ivf[m] % mod; 
}

int main() {
    work();  
    std :: cin >> n >> m; 
    for (int i = 1; i <= m; i++) {
        std :: cin >> a[i]; 
    }    
    f[m + 1][0] = 1; 
    for (int i = m; i >= 1; i--) {
        for (int st = 0; st < (1 << n); st++) {
            f[i][st] = f[i + 1][st]; 
            for (int j = 0; j < n; j++) {
                if (st & (1 << j)) {
                    f[i][st] = add(f[i][st], 1ll * f[i + 1][st ^ (1 << j)] * c((1 << n) - 1 - (st ^ (1 << j)) - a[i] + 1, (1 << j) - 1) % mod * fac[1 << j] % mod); 
                }
            }
        }
    }
    int ans = 0; 
    for (int st = 0; st < (1 << n); st++) {
        ans = add(ans, 1ll * f[1][st] * ((cnt[st] & 1) ? mod - 1 : 1) % mod * fac[(1 << n) - 1 - st] % mod); 
    }
    ans = 1ll * ans * (1 << n) % mod; 
    std :: cout << ans << '\n'; 
    return 0; 
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	long long n, x, ai, last, ans = 0;
	cin >> n >> x;
	last = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> ai;
		if (ai + last > x)
		{
			long long minus = ai + last - x;
			ans += minus;
			last = ai - minus;
		} else
			last = ai;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include <queue>
#include <sstream>
using namespace std;

int main(void){
	int n;
	while(cin >> n){
		if(n == 0) break;
		int d[4] = {5, 3, 2, 4};
		int head = 1;
		int sum = 0;
		for(int i = 0; i < n; i++){
			string S;
			cin >> S;
			if(S == "South"){
				int b = d[0];
				int a = head;
				d[0] = 7-head;
				head = b;
				d[2] = a;
				sum += head;
			}else if(S == "North"){
				int b = d[2];
				int a = head;
				d[2] = 7-head;
				head = b;
				d[0] = a;
				sum += head;
			}else if(S == "West"){
				int b = d[1];
				int a = head;
				d[1] = 7-head;
				head = b;
				d[3] = a;
				sum += head;
			}else if(S == "East"){
				int b = d[3];
				int a = head;
				d[3] = 7-head;
				head = b;
				d[1] = a;
				sum += head;
			}else if(S == "Left"){
				int save[4];
				for(int j = 0; j < 4; j++)
					save[j] = d[j];
				for(int j = 0; j < 3; j++){
					d[j] = save[j+1];
				}
				d[3] = save[0];
				sum += head;
			}else if(S == "Right"){
				int save[4];
				for(int j = 0; j < 4; j++)
					save[j] = d[j];
				for(int j = 0; j < 3; j++){
					d[j+1] = save[j];
				}
				d[0] = save[3];
				sum += head;
			}
		}
		cout << sum+1 << endl;
	}

}

Measured memory_bytes: 1212
n = int(input())
a = list(map(int, input().split()))

alice = []
bob = []

for i in range(n):
    if not a:
        break
    max_num = max(a)
    a.remove(max_num)
    alice.append(max_num)
    if not a:
        break
    max_num = max(a)
    a.remove(max_num)
    bob.append(max_num)

print(sum(alice) - sum(bob))


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::vector<uint64_t> A(N);
  for(auto &&a: A) std::cin >> a;

  std::sort(A.rbegin(), A.rend());

  uint64_t max = A[0];
  uint32_t i = 1;
  for (; i <= (N - 2)/2; i++) max += A[i]*2;
  if(N%2) max += A[i];
  
  std::cout << max << std::endl;

  return 0;
}

Measured memory_bytes: 4820
C = input()
N = list(map(int,input().split()))

count = 0
a = 0
b = 0
for i in range(len(N)-1):
    if N[i+1] - N[i] > 0:
        b = 1
    elif N[i+1] - N[i] < 0:
        b = -1
    else:
        b = 0
        
    if a == 0:
        a = b  
    elif a == b:
        pass
    elif a == b * (-1):
        count += 1
        a = 0
    else:
        pass

print(count+1)
    

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 1e9+7;
using ll = long long;
struct mint {
  ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
 }
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
    return fac[a]/fac[b]/fac[a-b];
}

int a[2001];

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> b(n);
    rep(i,n) b[i]=i+1;
    int cnt = 0;
    rep(i,n) {
        if(a[i]!=b[i]) cnt++;
    }
    if(cnt<3) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 18596
#include<bits/stdc++.h>
using namespace std;
void read(int &x)
{
    x=0;
    int y=1;
    char c=getchar();
    while (c>'9'||c<'0')
    {
        if (c=='-')
            y=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
    x*=y;
}
const int N=1005,mod=1e9+7;
int b[N],z[N],cnt,n,ans,f[N];
int main()
{
	read(n);
	for (int i=2;i<=n;++i)
	{
		if (!b[i])
			z[++cnt]=i;
		for (int j=1;j<=cnt&&i*z[j]<=n;++j)
		{
			b[i*z[j]]=1;
			if (i%z[j]==0)
				break;
		}
	}
	for (int i=1;i<=n;++i)
	{
		int x=i;
		for (int j=1;j<=cnt;++j)
			while (x%z[j]==0)
			{
				x/=z[j];
				++f[j];
			}
	}
	ans=1;
	for (int i=1;i<=cnt;++i)
		ans=(long long)ans*(f[i]+1)%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, s = 196471;
    cin >> n;
    while (n--){
        int y, m, d;
        cin >> y >> m >> d;
        FOR(i,1,y-1){
            if (i % 3 == 0) d += 200;
            else d += 195;
        }
        FOR(i,1,m-1){
            if (y % 3 == 0 || i % 2 == 1) d += 20;
            else d += 19;
        }
        cout << s - d << endl;
    }


    return 0;
}

Measured memory_bytes: 3060
import sys

n = int(input())

list_input = [sys.stdin.readline()[:-1] for _ in range(n)]

print('AC x', list_input.count('AC'))
print('WA x', list_input.count('WA'))
print('TLE x', list_input.count('TLE'))
print('RE x', list_input.count('RE'))

Measured memory_bytes: 81156
sub main {
    chomp(my $x = <STDIN>);
    print solve($x);
}
main() unless caller;

sub solve {
    my ($x) = @_;
    my $amari = $x % 11;
    my $ans = int($x / 11) * 2;
    if($amari > 6){
        $ans += 2;
    }
    elsif($amari > 0){
        $ans += 1;
    }

    return $ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int x[3],y[3];
	for(int i=0;i<3;i++){
		cin>>x[i]>>y[i];
	}
	double a,b,c;
	a = sqrt( 1.0 * (x[1]-x[0]) * (x[1]-x[0]) + 1.0 * ( y[1]-y[0] ) * ( y[1]-y[0] ) );
	b = sqrt( 1.0 * (x[1]-x[2]) * (x[1]-x[2]) + 1.0 * ( y[1]-y[2] ) * ( y[1]-y[2] ) );
	c = sqrt( 1.0 * (x[2]-x[0]) * (x[2]-x[0]) + 1.0 * ( y[2]-y[0] ) * ( y[2]-y[0] ) );
	double md = (a+b+c)/2.0;
	double s = sqrt( md * (md-a) * (md-b) * (md-c) );
	double ir = ( 2.0 * s ) / ( a + b + c );
	double mx = max( a, max( b,c ) );
	double ans = 1.0 / ( 2.0/mx + 1.0/ir );
	cout<<setprecision(16)<<ans<<Endl;
	return 0;
}

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

typedef tuple<int,int,int> ti;

const int N = 100000; 
int arr[4][N]; 
int dp[N][4]; 
int n ; 



void solve()
{
       cin >> n ; 
       

       for(int i = 0 ; i < n ; i ++)
          for(int j = 0 ; j < 3 ; j ++)
             cin >> arr[j][i];


       
       for(int i = 0 ; i < n ; i ++)
       {   

       	   for(int j = 0 ; j < 3 ; j ++)
       	   {
               dp[i][j] = arr[j][i];
               int res = 0 ;

               for(int k = 0; k < 3 and i > 0 ; k ++) 
                  if( k!= j) res = max(dp[i-1][k],res);

               dp[i][j] += res; 
       	   }
       }


       
       cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}); 


}

int main()
{

	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	
	 int t = 1 ; 
	 for(int i = 0 ; i < t ; i ++)
	 {
         solve(); 
	 }

	return 0;
}

Measured memory_bytes: 6272
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int n,a[100000],mi = 10000000,ma = -1;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",a+i);
	for(int i=0;i<n;i++){
		mi = min(mi,a[i]);
		ma = max(ma,a[i]);
	}
	switch(ma-mi){
		case 0:{
			if(mi==n-1||(2*mi<=n&&mi>0)) printf("Yes\n");
			else printf("No\n");
			break;
		}
		case 1:{
			int x = 0;
			for(int i=0;i<n;i++) if(a[i]==mi) x++;
			if(2*(ma-x)<=n-x&&ma-x>0) printf("Yes\n");
			else printf("No\n");
			break;
		}
		default:{
			printf("No\n");
			break;
		}
	}
}


Measured memory_bytes: 512