akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
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;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> pricenum(n);
    rep(i,n){
        ll price,maxnum;
        cin>>price>>maxnum;
        pricenum[i]=make_pair(price,maxnum);
    }
    sort(pricenum.begin(),pricenum.end());
    ll num=0,i=0,ans=0;
    while(num<m){
       if(num+pricenum[i].second<=m){
           ans+=pricenum[i].first*pricenum[i].second;
           num+=pricenum[i].second;
           i++;
       }
       else{
           ans+=pricenum[i].first*(m-num);
           num=m;
           i++;
       }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main(void) {
    int yen500, yen100, yen50, price;
    int count = 0;
    cin >> yen500 >> yen100 >> yen50 >> price;

    for (int y500 = 0; y500 <= yen500; y500++) {
        for (int y100 = 0; y100 <= yen100; y100++) {
            for (int y50 = 0; y50 <= yen50; y50++) {
                int sum = 500 * y500 + 100 * y100 + 50 * y50;
                if (sum == price) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    _ = int(input())
    www = tuple(map(int, input().split()))

    min = 200
    t = - sum(www)
    for w in www:
        t += 2 * w
        if abs(t) < min:
            min = abs(t)
    print(min)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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 int MAX = 1010;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    for (int left = 0; left < 101; left++)
    {
        for (int right = 0; right < 101; right++)
        {
            string l_str(left, '(');
            string r_str(right, ')');
            string str = l_str + s + r_str;
            int cnt = 0;
            for (char cc : str)
            {
                if (cc == '(')
                {
                    ++cnt;
                }
                else
                {
                    --cnt;
                    if (cnt < 0)
                    {
                        break;
                    }
                }
            }
            if (cnt == 0)
            {
                cout << str << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3556
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


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

	int N, A, B;
	cin >> N >> A >> B;
	if (abs(A - B) % 2) {
		cout << "Borys" << endl;
	}
	else {
		cout << "Alice" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
Q = int(input())
Qa = Q//100
Qb = Q%100
if 1 <= Qa <= 12:
    if Qb >12:
        print("MMYY")
    elif 1 <=Qb <= 12:
        print("AMBIGUOUS")
    elif Qb == 0:
        print("MMYY")

elif Qa > 12:
    if 1 <=Qb <=12 :
        print("YYMM")
    elif Qb >12:
        print("NA")
    elif Qb == 0:
        print("NA")

elif Qa ==0:
    if(1<= Qb <=12):
        print("YYMM")

    elif(Qb ==0):
        print("NA")

    elif(Qb >12):
        print("NA")




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

int main() {
    char a;
    std::cin >> a;

    if (('a' <= a) && (a <= 'z')) {
        std::cout << 'a' << std::endl;
    } else {
        std::cout << 'A' << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll n;
    cin >> n;
    set<string> s;
    for (ll i = 0; i < n; ++i) {
        string a;
        cin >> a;
        s.insert(a);
    }
    // for (auto b : s) cerr << b << endl;
    cout << s.size() << endl;
}


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

using namespace std;
using llint = long long;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

int n, a, b, c, d;
string s;

int main() {
    // Input
    cin >> n >> a >> b >> c >> d >> s;
    --a; --b; --c; --d;

    // Solve
    bool flag1 = true;

    for (int i = a; i <= max(c,d)-1; ++i) {
        if (s.at(i)=='#' && s.at(i+1)=='#')
        {
            flag1 = false;
        }
    }

    bool flag2 = false;

    for (int i = b; i <= d-2; ++i) {
        if (s.at(i)=='.' && s.at(i+1)=='.' && s.at(i+2)=='.')
        {
            flag2 = true;
        }
    }

    bool flag3 = true;
    s.at(d) = '#';
    for (int i = a; i <= c-1; ++i) {
        if (s.at(i)=='#' && s.at(i+1)=='#')
        {
            flag3 = false;
        }
    }

    bool flag4 = true;
    s.at(d) = '.';
    s.at(b) = '#';
    for (int i = a; i <= c-1; ++i) {
        if (s.at(i)=='#' && s.at(i+1)=='#')
        {
            flag4 = false;
        }
    }

    // Output
    if (c < d)
    {
        if (flag1)
        {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (flag1 && (flag2 || flag3 || flag4))
        {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int M, K;
  cin >> M >> K;
  if ((1 << M) <= K) {
    cout << -1 << endl;
  } else if (M == 0) {
    cout << "0 0" << endl;
  } else if (M == 1) {
    if (K == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
  } else {
    rep(i, 1 << M) {
      if (i != K) cout << i << " ";
    }
    cout << K << " ";
    for (int i = (1 << M) - 1; i >= 0; --i) {
      if (i != K) cout << i << " ";
    }
    cout << K << endl;
  }
  return 0;
}

Measured memory_bytes: 3656
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<usize> = get_vec();
    let mut es : Vec<i32> = vec!(0; v[0]);
    for i in 0..v[1] {
        let ee : Vec<usize> = get_vec();
        es[ee[0]-1] += 1;
        es[ee[1]-1] += 1;
    }
    for e in es {
        println!("{}", e);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main()
{
    int n,i=1;
    cin>>n;
    ll a=2,b=1,c=0;
    if(n==1)cout<<b<<endl;
    else{
    while(i++<n)
    {
        c = a+b;
        a=b,b=c;
    }
    cout<<c<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
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 PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int cnt5;

int main() {
    int n;
    cin >> n;
    vector<int> v;
    PUSH(n,v);
    
    int m;
    cin >> m;
    REP(i,m) {
        int j;
        cin >> j;
        if (binary_search(ALL(v), j)) cnt5++;
    }

    cout << cnt5 << endl;
    
    return 0;
}

Measured memory_bytes: 1672
#include <cstdio>
#define max(a,b) ((a>b)?a:b)
int n,a[2][102],ans=0,t;
int main(){
	scanf("%d",&n);
	for(int i=0;i<2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	a[0][0]=0;
	for(int i=1;i<=n;i++)
		a[0][i]+=a[0][i-1];
	t=0;
	for(int i=n;i>0;i--){
		t+=a[1][i];
		ans=max(ans,t+a[0][i]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
char s[N];
void solve() {
	scanf("%s", s);
	int l = strlen(s);
	for (int i = 0; i < l; i++) {
		if (i+1 < l && s[i] == s[i+1]) {
			printf("%d %d\n", i+1, i+2);
			return;
		}
		if (i+2 < l && s[i] == s[i+2]) {
			printf("%d %d\n", i+1, i+3);
			return;
		}
	}
	puts("-1 -1");
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s;
    vector<int> k(M);
    vector<int> p(M);
    s.push_back(vector<int>());
    REP(i, M)
    {
        cin >> k[i];
        s.push_back(vector<int>());
        REP(j, k[i])
        {
            int p;
            cin >> p;
            p--;
            s[i].push_back(p);
        }
    }
    REP(i, M)
    {
        cin >> p[i];
    }
    int count = 0;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        vector<int> st(N);
        REP(i, N)
        {
            st[i] = (bit & (1 << i)) ? 1 : 0;
        }
        bool flg = true;
        REP(i, M)
        {
            int tmp = 0;
            REP(j, k[i])
            {
                // cout << s[i][j] << "\n";
                tmp += st[s[i][j]];
            }
            if (tmp % 2 != p[i])
            {
                flg = false;
                break;
            }
        }
        if (flg)
            count++;
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
template <typename F,typename T>
struct SegTree{
  // 二項演算merge,単位元identify
  T identity;
  F merge; 
  int size;
  vector<T> dat;
  
  // 二項演算fと単位元idを渡して宣言する
  SegTree(F f,T id):merge(f),identity(id){}

  // データの要素の数nを渡して初期化、sizeはnより大きい2の冪乗
  void init(int n){
    size = 1;
    while(size<=n) size *= 2;
    dat.resize(size*2-1,identity);
  }

  // 配列を渡して0(n)で初期化
  void build(vector<T> vec){
    rep(i,vec.size()) dat[size-1+i] = vec[i];
    dfs(0);
  }
  
  T dfs(int k){
    if(k>=size-1) return dat[k];
    else return dat[k] = merge(dfs(2*k+1),dfs(2*k+2));
  }

  // index kの要素をaに変更
  void update(int k,T a){
    k += size - 1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  // 区間[a,b)に対するクエリに答える。(k,l,r)=(0,0,size)
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return identity;
    
    if(a<=l&&r<=b) return dat[k]; 
    else return merge(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<size){
      rep(i,num){
	if(dat[i+index]==identity) cout << "e ";
	else cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
  }
  
};

vector<int> compress(vector<int> a) {
  int n = a.size();
  vector<int> vals;
  rep(i,n) vals.push_back(a[i]);

  sort(vals.begin(), vals.end());
  vals.erase(unique(vals.begin(), vals.end()), vals.end());

  vector<int> res;
  rep(i,n) {
    int id = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
    res.push_back(id);
  }

  return res;
}

ll LIS(vector<int> h, vector<ll> a) {
  int n = h.size();
  h = compress(h);
  
  auto f = [&](ll a, ll b) { return max(a, b); };
  ll id = 0;
  SegTree<decltype(f), ll> seg(f, id);
  seg.init(n);
  ll res = 0;
  rep(i,n) {
    ll x = seg.query(0, h[i], 0, 0, seg.size);
    seg.update(h[i], x+a[i]);
    chmax(res, x+a[i]);
  }
  return res;

}

int main()
{
  int n;cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  cout << LIS(h, a) << "\n";
  
  return 0;
}


Measured memory_bytes: 9168
#include<stdio.h>

int n, A[21];

//从输入值M中减去所选元素的递归函数
int solve(int i, int m) {
	if ( m == 0 ) return 1;
	if ( i >= n) return 0;
	int res = (solve(i + 1, m) || solve(i + 1, m - A[i]));
	return res;
} 

int main() {
	int q, M, i;
	scanf("%d", &n);
	for(int i = 0; i < n; i++ ) scanf("%d", &A[i]);
	scanf("%d", &q);
	for ( int i = 0; i < q; i++ ) {
		scanf("%d", &M);
		if ( solve(0, M) == 1 ) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2612
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner SC = new Scanner(System.in);
String S = SC.next();
char[] Array = S.toCharArray();
for(int i = 0; i < S.length(); i++) {
	if(i % 2 == 0) {
		System.out.print(Array[i]);
	}
}
System.out.println();
	}

}

Measured memory_bytes: 47756
using System;
using System.Linq;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = getIntParam();

            Console.WriteLine(X >= 30 ? "Yes" : "No");
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


Measured memory_bytes: 27456
#include<bits/stdc++.h>
using namespace std;
int main() {
  string S, T;
  int res = 0, loops, temp = 0;
  cin >> S >> T;
  if(S == T) {
    cout << 0 << endl;
    return 0;
  }
  res = T.size();
  loops = S.size() - T.size() + 1;
  for(int i = 0; i < loops; i++) {
    for(int j = 0; j < T.size(); j++) {
      if(S[i+j] != T[j]) temp++;
    }
    res = min(temp, res);
    temp = 0;
  }
  cout << res << endl;
}
    

Measured memory_bytes: 3588
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = 1
for x in a:
    if x%2==0:
        res *= 2
print(3**n-res)

Measured memory_bytes: 10440
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string s;
	int n; cin >> n;
	while (n--) {
		char c; cin >> c;
		if (c != '-') s.push_back(c);
	}
	n = s.length();
	int u = 0;
	vector<int> dp(n + 1);
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'D')
			for (int j = 0; j <= n; j++)
				dp[j] = (ll)dp[j] * (u - j) % MOD;
		for (int j = n - 1; j >= 0; j--)
			dp[j + 1] = (dp[j + 1] + (ll)dp[j] * (u - j)) % MOD;
		if (s[i] == 'U') u++;
	}
	cout << dp[u] << endl;
}

Measured memory_bytes: 1204
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if (n == 0 && m == 0) break;
			int[] a = new int[n];
			int[] b = new int[m];
			int sumA = 0;
			int sumB = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				sumA += a[i];
			}
			for (int i = 0; i < m; i++) {
				b[i] = sc.nextInt();
				sumB += b[i];
			}
			int resA = 1000;
			int resB = 1000;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (sumA - a[i] + b[j] == sumB - b[j] + a[i] && resA + resB > a[i] + b[j]) {
						resA = a[i]; resB = b[j];
					}
				}
			}
			if (resA == 1000 && resB == 1000) {
				System.out.println(-1);
			} else {
				System.out.println(resA + " " + resB);
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define int long long

string divide[4] = {"dream", "dreamer", "erase", "eraser"};
bool dp[100010];

signed main(){

    string s; cin >> s;

    dp[0] = 1;
    for(int i = 0; i < s.size(); i++){
        if(!dp[i]) continue;
        
        for(string t : divide){
            if(s.substr(i, t.size()) == t){
                dp[i + t.size()] = 1;
            }
        }
    }

    cout << (dp[s.size()] ? "YES" : "NO") << endl;
    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll N;
    cin >> N;
    int H[N];
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    H[0]--;
    bool isok = true;
    for(int i = 1; i < N; i++) {
        if(H[i] < H[i - 1]) {
            isok = false;
            break;
        }
        if(H[i] > H[i - 1])
            H[i]--;
    }
    cout << (isok ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
#define CEIL(d,n) (((d)+(n)-1)/(n))
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
LL N, M, S;
LL A[50];
inline bool ok(LL x) {
  if(M < S-x) return false;
  LL s = 0;
  for(auto i=0; i<N; ++i) s += max(0ll, CEIL(A[i]+x+1-N, N+1));
  return s <= x;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    if(ok(m)) h = m;
    else      l = m;
  }
  for(auto x=max(0ll,h-N*N); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    break;
  }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;

int main() {
    cin >> n >> m;
    li al = 0;
    li ar = n - 1;
    rep(i, m) {
        li l, r;
        cin >> l >> r;
        l--;
        r--;
        al = max(al, l);
        ar = min(ar, r);
    }
    cout << max(0ll, ar - al + 1) << endl;


    return 0;
}

Measured memory_bytes: 256
object Main extends App {

  val Array(n, m) = io.StdIn.readLine.split(" ").map(_.toInt)
  val c = io.StdIn.readLine.split(" ").map(_.toInt)

  val ans = {
    val dp: Array[Int] = Array.fill[Int](n + 1)(Int.MaxValue)
    dp(0) = 0

    for {
      i <- 0 until m
      j <- c(i) to n
    } dp(j) = math.min(dp(j), dp(j - c(i)) + 1)

    dp(n)
  }

  println(ans)
}


Measured memory_bytes: 45120
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(long long i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(ll i=(n)-1;i>=0;--i)
#define iFr(i,n) for(ll i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n,m,l,r,ll,rr,z,o;
  o=0;
  l=0;
  cin>>n>>m;
  r=n+1;
  fr(i,n){
    cin>>ll>>rr;
    l=max(l,ll);
    r=min(r,rr);
  }
  z=r-l+1;
  z=max(o,z);
  cout<<z;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  int count = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(a != i+1) count++;
  }
  cout << (count <= 2 ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int A = GetInt();
		int B = GetInt();

		int res = 0;
		int num = 1;
		while(num < B)
		{
			num = num - 1 + A;
			res++;
		}
		
		Console.WriteLine(res);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


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

int main() {
  int a;
  cin >> a;
  char op;
  cin >> op;
  int b;
  cin >> b;
  
  if (op == '+') {
    cout << a + b << endl;
  } else if (op == '-') {
    cout << a - b << endl;
  }
  
}

Measured memory_bytes: 256
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15), sINF = ll(1e9);

struct seg{
    ll a, b, l, r;
};

ll cal(seg &s, ll x)
{
    return s.a * x + s.b;
}

ll h[MAXn], dp[MAXn];

int main()
{
    IOS();
    ll n, C;
    cin>>n;
    cin>>C;
    REP1(i,n)cin>>h[i];
    deque<seg> dq;
    dp[1] = 0;
    dq.push_back(seg({-2 * h[1], h[1] * h[1], -sINF, sINF}));
    for(int i = 2;i <= n;i ++)
    {
        while(SZ(dq) && dq.front().r < h[i])dq.pop_front();
        dp[i] = cal(dq[0], h[i]) + C + h[i] * h[i];
        seg s({-2 * h[i], h[i] * h[i] + dp[i], -sINF, sINF});
        while(SZ(dq))
        {
            if(cal(dq.back(), dq.back().l) >= cal(s, dq.back().l))s.l = dq.back().l, dq.pop_back();
            else
            {
                dq.back().r = (dq.back().b - s.b) / (s.a - dq.back().a);
                s.l = dq.back().r + 1;
                break;
            }
        }
        dq.push_back(s);
    }
    cout<<dp[n]<<endl;
    
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    long n[4];
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    long p[4] = {n[0] * n[2], n[1] * n[2], n[0] * n[3], n[1] * n[3]};
    sort(p, p+4);

    cout << p[3] << endl;

}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

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

	int d, t, s; cin >> d >> t >> s;

	if(d <= t*s){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
	

	return 0;
}


Measured memory_bytes: 3648
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    
    wildcard = 0
    color = [0] * 8
    for a in A:
        if a < 400:
            color[0] = 1
        elif a < 800:
            color[1] = 1
        elif a < 1200:
            color[2] = 1
        elif a < 1600:
            color[3] = 1
        elif a < 2000:
            color[4] = 1
        elif a < 2400:
            color[5] = 1
        elif a < 2800:
            color[6] = 1
        elif a < 3200:
            color[7] = 1
        else:
            wildcard += 1

    nc = sum(color)
    print(max(1, nc), nc + wildcard)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}



// TODO: write
int main() {   
  ll n;cin>>n;
  ll a,b;cin>>a>>b;
  ll ab = a+b;
  ll ans = (n/ab)*a + min(n%ab,a);
  print(ans);
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

ll m = 1e9+7;
struct mint {
	typedef long long ll;
	ll x;
	mint(ll x=0): x(x%m) {}
	mint operator-() const { return mint(m-x); }
	mint operator+(const mint o) const { return mint(x+o.x); }
	mint operator-(const mint o) const { return mint(x-o.x+m); }
	mint operator*(const mint o) const { return mint(x*o.x); }
	mint& operator+=(const mint o) { x = (x+o.x)%m; return *this; }
	mint& operator-=(const mint o) { x = (x-o.x+m)%m; return *this; }
	mint& operator*=(const mint o) { x = x*o.x%m; return *this; }
	bool operator==(const mint o) const { return x==o.x; }
	bool operator!=(const mint o) const { return x!=o.x; }
	template<typename T> mint& operator=(const T o) { x = o%m; return *this; }
	template<typename T> mint operator+(const T o) const { return mint(x+o); }
	template<typename T> mint operator-(const T o) const { return mint(x-((ll)o)%m+m); }
	template<typename T> mint operator*(const T o) const { return mint(x*o); }
	template<typename T> mint& operator+=(const T o) { x = (x+(ll)o%m)%m; return *this; }
	template<typename T> mint& operator-=(const T o) { x = (x-((ll)o)%m+m)%m; return *this; }
	template<typename T> mint& operator*=(const T o) { x = x*((ll)o%m)%m; return *this; }
	template<typename T> bool operator==(const T o) const { return x==o%m; }
	template<typename T> bool operator!=(const T o) const { return x!=o%m; }

	mint pow(ll k) const {
		if(k==0) return mint(1);
		if(k%2) return pow(k-1)*x;
		mint z = pow(k/2);
		return z*z;
	}

	mint inv() const { return pow(m-2); }
};

mint dp[5001][5001];

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int K = S.size();

	dp[0][0] = 1;
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			if(j>0){
				dp[i+1][j-1] += dp[i][j];
			} else {
				dp[i+1][j] += dp[i][j];
			}
			dp[i+1][j+1] += dp[i][j]*2;
		}
	}
	debug(dp[N][K], mint(2).pow(K).inv());
	cout << (dp[N][K] * mint(2).pow(K).inv()).x << endl;

	return 0;
}


Measured memory_bytes: 195712
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
  int ans_w = 100 * a, ans_s = 0;
  double conc = 0;
  for (int i = 0; 100 * a * i <= f; ++i) {
    for (int j = 0; 100 * (a * i + b * j) <= f; ++j) {
      if (i == 0 && j == 0) continue;
      int water = 100 * (a * i + b * j);
      for (int k = 0; c * k <= f - water; ++k) {
        for (int l = 0; d * l <= f - water - c * k; ++l) {
          int sugar = c * k + d * l;
          if ((double)sugar / water <= e / 100.0) {
            if ((double)sugar / (water + sugar) > conc) {
              ans_s = sugar; ans_w = water;
              conc = (double)sugar / (water + sugar);
            }
          }
        }
      }
    }
  }
  cout << ans_w + ans_s << " " << ans_s << '\n';
  return 0;
}


Measured memory_bytes: 256
import copy

n, k =  map(int,input().split())
s = ['R'] + list(input()) + ['L']

cnt = 0
for i in range(1,n+1):
    if s[i] == 'L' and s[i-1] == 'L':
        cnt += 1
    if s[i] == 'R' and s[i+1] == 'R':
        cnt += 1
# print(cnt)
while k > 0 and cnt < n-1:
    if n- 1 - cnt > 1:
        cnt += 2
    elif n- 1 - cnt > 0:
        cnt += 1
    k -= 1
print(cnt)


Measured memory_bytes: 10416
#include <stdio.h>
#include <math.h>

int main(void){
    int a;
    scanf("%d", &a);
    int c[1000001];
    int m = 1;
    do {
        c[a] = 1;
        if(a % 2 == 0)  a /= 2;
        else            a = 3 * a + 1;
        //printf("%d\n", a);
        m++;
    } while(c[a] != 1);

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

    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
for i in range(1000):
    str_i = str(i)
    if len(str_i) == N and all(int(str_i[s-1])==c for s, c in SC):
        print(i)
        exit()
print(-1)


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

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

int ctoi(char c){
  return c - '0';
}

int main(){
  string s,t;
  cin >> s >> t;
  I to;
  to=0;
  if (s.at(0) == t.at(0)){ to++;}
  if (s.at(1) == t.at(1)){ to++;}
  if (s.at(2) == t.at(2)){ to++;}
  cout << to << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
  
operator = sys.stdin.read().split()
      
top = 1
bottom = 6
south = 2
north = 5
east = 3
west = 4
sum = 1
  
for var in operator[1:]:
    if var == "North":
        north,top,south,bottom = top,south,bottom,north
        sum += top
    elif var == "South":
        south,top,north,bottom = top,north,bottom,south
        sum += top
    elif var == "West":
        west,top,east,bottom = top,east,bottom,west
        sum += top
    elif var == "East":
        east,top,west,bottom = top,west,bottom,east
        sum += top
    elif var == "Right":
        south,east,north,west = east,north,west,south
        sum += top
    elif var == "Left":
        south,west,north,east = west,north,east,south
        sum += top
    else:
        print sum
        top = 1
        bottom = 6
        south = 2
        north = 5
        east = 3
        west = 4
        sum = 1

Measured memory_bytes: 4856
S = input()
ans1 = 0
ans2 = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "1":
            ans1 += 1
    else:
        if S[i] == "0":
            ans1 += 1
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "0":
            ans2 += 1
    else:
        if S[i] == "1":
            ans2 += 1
print(min(ans1, ans2))


Measured memory_bytes: 3188
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(void){
  int H, W;
  cin >> H >> W;
  char C[H][W];
  rep(i, H)
    rep(j, W)
    cin >> C[i][j];
  //入力終了

  rep(i, H){
    //各i行目に対して，W列分の表示を2回行う
    rep(j, 2){
      rep(k, W)
	cout << C[i][k] ;
      cout << endl;
    }
  }
  

  return 0;
}


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

int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  long long aq=a/x, bq=b/x;
  if(a%x==0) cout << bq-aq+1;
  else cout << bq-aq;
}

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

//#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 21;

bool a[N][N];
int dp[1 << N];

int32_t main(){

    sync;

    int n; cin >> n;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];
    dp[0] = 1;
    for(int mask = 1; mask < (1 << n); mask++) {
    	int man = __builtin_popcount(mask) - 1;
    	for(int i = 0; i < n; i++) if (a[man][i] && (mask & (1 << i))) dp[mask] = (dp[mask] + dp[mask ^ (1 << i)]) % MOD;
    }
	cout << dp[(1 << n) - 1] << endl;

    return 0;
}

Measured memory_bytes: 8448
r,c = map(int,input().split())
s_r = [0 for i in range(r)]
s_c = [0 for i in range(c)]
ls = []
for i in range(r):
    ls.append(list(map(int,input().split())))
for i in range(r):
    for j in range(c):
        s_r[i] += ls[i][j]
        s_c[j] += ls[i][j]
    ls[i].append(s_r[i])
    print(*ls[i])
k = sum(s_r)
s_c.append(k)
print(*s_c)


Measured memory_bytes: 6228
#include <iostream>

int main() {
	std::uint16_t a, b, c;
	std::cin >> a >> b >> c;

	if (a + b < a + c) {
		if (a + b < b + c) {
			std::cout << a + b << std::endl;
		} else {
			std::cout << b + c << std::endl;
		}
	} else if (a + c < b + c) {
		std::cout << a + c << std::endl;
	} else {
		std::cout << b + c << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int edge[111][111];
#define rep(i,s,t) for(int i=s;i<t;i++)
#define pii pair<int,int>
int main()
{
    int n;scanf("%d",&n);
    vector<pii> res;
    int tmp=n/2*2;
    rep(i,1,tmp+1)edge[i][i]=edge[i][tmp-i+1]=1;
    rep(i,1,n+1)rep(j,i+1,n+1)if(!edge[i][j])
        res.emplace_back(i,j);
    printf("%d\n",res.size());
    for(pii p:res)printf("%d %d\n",p.first,p.second);
}

Measured memory_bytes: 384
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N, K;  cin >> N >> K;
    string S; cin >> S;

    string t = S;
    t[K - 1] = t[K - 1] - 'A' + 'a';

    string ans = t;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  const int n = getInt();
  const int x = getInt();
  const int m = getInt();

  vector<int> l(m);
  vector<int> r(m);
  vector<int> s(m);

  REP(i,m){
    l[i] = getInt() - 1;
    r[i] = getInt() - 1;
    s[i] = getInt();
  }

  vector<int> buff(n, 0);
  pair<int, vector<int> > ans = make_pair(-1, vector<int>());
  while(true){
    vector<int> ps(n);
    bool ok = true;
    REP(i,n) ps[i] = (i == 0 ? 0 : ps[i - 1]) + buff[i];
    REP(i,m){
      int t = ps[r[i]];
      if(l[i] != 0) t -= ps[l[i] - 1];
      if(s[i] != t) ok = false;
    }

    if(ok) ans = max(ans, make_pair(accumulate(buff.begin(), buff.end(), 0), buff));

    buff[0]++;
    REP(i,n) if(buff[i] == x + 1){
      if(i == n - 1) goto end;
      buff[i] = 0;
      buff[i + 1]++;
    }
  }
 end:;

  if(ans.first == -1) printf("%d\n", -1);
  else{
    printf("%d", ans.second[0]);
    REP(i,n - 1) printf(" %d", ans.second[i + 1]);
    puts("");
  }

  return 0;
}

Measured memory_bytes: 1064
#include<iostream>
using namespace std ;
int main () {
int z,x,k,m,y;
cin>>k;
z=k/2;
m=z*z;
x=(k+1)/2;
y=x*(x-1);
if(k%2==0){
      cout<<m;
  }
else { 
      cout<<y;
}
return 0;
}

Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int M=1<<7;
const int N=505;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
double f[N][M],Ans;
int n,t,C,Sta,a[N];
double Pow(double x,int y){
	double ans=1,tot=x;
	while(y){
		if(y&1)ans=ans*tot;
		tot=tot*tot;
		y>>=1;
	}
	return ans;
}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();C=read();
	for(int i=0;i<n;i++)a[i]=read();
	sort(a,a+n);Sta=(1<<(n-1))-1;
	do{
		memset(f,0,sizeof(f));
		f[a[n-1]*n][0]=1;
		for(int i=0;i<=n*C;i++){
			for(int j=i;j<=n*C;j++){
				for(int S=0;S<=Sta;S++){
					if(i%n&&!((S>>(i%n-1))&1)){
						int k=min(n*C,max(j,i+a[i%n-1]*n));
						f[k][S|(1<<(i%n-1))]+=f[j][S];
					}
				}
			}
		}
		Ans+=f[n*C][Sta];t++;
	}while(next_permutation(a,a+n-1));
	printf("%.15lf",Ans/t/Pow(C,n-1));
	return 0;
}

Measured memory_bytes: 4240
#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring> 
#include <algorithm>
using namespace std;
#include <queue> 
#define ll long long
ll sum=0;
int num[200005]={};
int main()
{
	int N;
	int m=0;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>num[i];
	}
	sort(num,num+N);
	for(int i=N-1;i>0;i--)
	{
		if(i==N-1)
		{
			sum+=num[N-1];
			m++;
		}
		else
		{
			for(int j=0;j<2;j++)
			{
				sum+=num[i];m++;
				if(m==N-1)
				{
					break;
				}
			}
		}
		if(m==N-1)
		{
			break;
		}				
	}
	printf("%lld",sum);
	return 0;
	
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
const ll SIZE = 26;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   ll n; cin >> n;
   string s;
   while (n!=0)
   {
      n -= 1;
      s.push_back(char(n%SIZE + 'a'));
      n /= SIZE;
   }
   reverse(s.begin(), s.end());
   cout << s << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ll> l(n), r(n);
    rep(i, n) cin >> l[i] >> r[i];
    
    ll sum = 0;
    rep(i, n) sum += r[i] - l[i] + 1;
    put(sum)

    return 0;
}

Measured memory_bytes: 3612