akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#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 // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int d[3];
int main(){
  IOS();
  cin>>d[0]>>d[1]>>d[2];
  sort(d,d+3);
  pary(d,d+3);
  int ans = 0;
  if( (d[2]-d[1])%2 == (d[2]-d[0])%2 ){
    if( (d[2]-d[1])&1 ) ans = (2*d[2]-d[1]-d[0]-2)/2+1;
    else ans = (2*d[2]-d[1]-d[0])/2;
  }
  else{
    if( (d[2]-d[1])%2 == 0 ) d[1]++,d[2]++;
    else d[0]++,d[2]++;
    ans += (2*d[2]-d[1]-d[0])/2+1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(){
  while(1){
    string s; cin >> s;
    if(s=="0")break;
    int ans=0;
    for(int i=0; i<s.size(); i++){
      ans += stoi(s.substr(i,1));
    }
    cout <<ans <<endl;
  }
}

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

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n, m;
    cin >> n >> m;

    //カウント用のvector、0で初期化
    vi cnt(m, 0);

    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int a;
            cin >> a;
            a--;  //わざと配列に合わせる

            //カウント
            cnt[a]++;
        }
    }

    int ans = 0;
    rep(i, m) {
        //カウントとnが一致すればansをインクリメント
        if (cnt[i] == n) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mpi = mp::cpp_int;
using mpf = mp::number<mp::cpp_dec_float<1024>>;

///////////////////////////////////////////////////////////////
// mod https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
///////////////////////////////////////////////////////////////
// ll MOD = 1000000007;
//
// ll mod(long long val) {
//     long long res = val % MOD;
//     if (res < 0) res += MOD;
//     return res;
// }
//
// ll modinv(ll a) {
//     ll b = MOD, u = 1, v = 0;
//     while (b) {
//         ll t = a / b;
//         a -= t * b; swap(a, b);
//         u -= t * v; swap(u, v);
//     }
//     u %= MOD;
//     if (u < 0) u += MOD;
//     return u;
// }
//
// const int MAX = -1;
// ll fac[MAX], finv[MAX], inv[MAX];
// void com_init() {  // initialize nCk table with O(N)
//     fac[0] = fac[1] = 1;
//     finv[0] = finv[1] = 1;
//     inv[1] = 1;
//     for (int i = 2; i < MAX; i++){
//         fac[i] = fac[i - 1] * i % MOD;
//         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
//         finv[i] = finv[i - 1] * inv[i] % MOD;
//     }
// }
// ll com(int n, int k){  // nCk
//     if (n < k) return 0;
//     if (n < 0 || k < 0) return 0;
//     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
// }

int main() {
    string s;
    cin >> s;
    map<int, ll> m;
    m[0]++;
    int n = s.size();
    int p = 1;
    int x = 0;
    for (int l = 0; l < n; ++l) {
        int d = (int)(s[n-l-1] - '0');
        d %= 2019;
        p %= 2019;
        x %= 2019;
        x = p * d + x;
        x %= 2019;
        m[x]++;
        p *= 10;
    }
    int ans = 0;
    for (const auto &kv: m) {
        int k = kv.second;
        if (k == 0) continue;
        ans += k * (k - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3672
import sys

N, X = input().split()
N = int(N)
X = int(X)
L = input().split()
L = map(int, L)
L_list = list(L)

count = 1
D = 0
for k in L_list:
    D = D + k
    count = count + 1
    if D > X:
        print(count - 1)
        sys.exit()

print(N + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() {
  vector <int> O (6);
  cin >> O[0] >> O[1] >> O[2] >> O[3] >> O[4] >> O[5];
  int p=0,q=0,r=0,s=0;
   for (int i = 0; i<6 ; i++ ) {
     if (O[i] == 1) {
       p++;
     }
     if (O[i] == 2) {
       q++;
     }
     if (O[i] == 3) {
       r++;
     }
     if (O[i] == 4) {
       s++;
     }
   }
  if (p>2||q>2||r>2||s>2) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    abc = [None] * N
    for i in range(N):
        abc[i] = tuple(map(int, input().split()))

    dp = [[0, 0, 0] for _ in range(N + 1)]
    for i, (a, b, c) in enumerate(abc):
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a
        dp[i + 1][1] = max(dp[i][2], dp[i][0]) + b
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c

    ans = max(dp[-1])
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

string s;

bool is_palindrome(string s, int i, int j)
{
    while (i < j)
    {
        if (s[i] != s[j])
            return false;
        i++;
        j--;
    }

    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    cin >> s;


    if (is_palindrome(s, 0, s.length() - 1) && is_palindrome(s, 0, (s.length() - 1) / 2 - 1) && is_palindrome(s, (s.length() + 3) / 2 - 1, s.length() - 1))
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	a = a - c;
	cout << a / (b + c) << endl;
    return 0;
}



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

int main(){
    int N ;
    cin >> N;
    if(N == 100000 || N == 10000 || N == 1000 || N == 100 || N == 10)
        cout << "10" << endl;
    else
        cout << N /100000 + (N % 100000) / 10000 + (N % 10000) /1000 +
                 (N % 1000) / 100  + (N % 100) / 10 + 
                 ((((N%100000)%10000)%1000)%100)%10 << endl;
}

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

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

ll choose(int n,int a){
  ll x,y; x=y=1;
  rep(i,a){
    x*=n-i;
    y*=i+1;
  }
  return x/y;
}

int main(){
    int n; cin >> n;
    vector<int> qu(n+1,0); vector<int> a(n);
    rep(i,n){
        int aa; cin >> aa;
        a[i]=aa;
        qu[aa]++;
    }
    ll al=0;
    rep(i,n){
        if(qu[i+1]==0 || qu[i+1]==1) continue;
        al+=choose(qu[i+1],2);
    }

    rep(i,n){
        ll di;
        if(qu[a[i]]==0 || qu[a[i]]==1){
            cout << al << endl;
            continue;
        }
        di=choose(qu[a[i]],2)-choose(qu[a[i]]-1,2);
        cout << al-di << endl;
    }

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, it) for(auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

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

	int n;
	cin >> n;
	if(n % 1000 == 0)
		cout << 0 << endl;
	else
		cout << 1000 - n % 1000 << endl;
}

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



int main()
{
	char a[10];
	scanf("%s",a + 1);
	if(a[3] == a[4] && a[5] == a[6])
	{
		printf("Yes\n");
	}
	else
		printf("No\n");
}

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

using namespace std;

int main() {
  int N, T, X;
  cin >> N >> T >> X;
  int tmp = (N / T) + (N % T == 0 ? 0 : 1);
  cout << (long long)tmp * X << endl;
  return 0;
}
  

Measured memory_bytes: 3600
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1335
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int main(void)
{
    int n, k, s;
    while (cin >> n >> k >> s, n || k || s)
    {
        int ans = 0;
        for (int bit = 0; bit < (1 << n); ++bit)
        {
            int check = 0;
            int sum = 0;
            for (int i = 0; i < n; ++i)
            {
                if (1 & (bit >> i))
                {
                    check++;
                    sum += i + 1;
                }
            }
            if (check != k)
                continue;
            if (sum == s)
                ans++;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3000
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
bool kaibun(string s){
    for(int i=0;i<s.size();i++)
        if(s[i]!=s[s.size()-1-i])
            return false;
    return true;
}
signed main(){
    string s;
    cin>>s;
    cout<<(kaibun(s)&&kaibun(s.substr(0,s.size()/2))&&kaibun(s.substr(s.size()/2+1,s.size()/2))?"Yes":"No")<<endl;
}


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

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		int a;
		scanf("%d", &a);
		if(a%2==0 && a%3!=0 && a%5!=0){
			puts("DENIED");
			return 0;
		}
	}
	puts("APPROVED");
}



Measured memory_bytes: 128
#include <iostream>

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

using namespace std;

int main()
{
	int is5 = 0;
	int is7 = 0;
	int n;

	rep(i, 3){
		cin >> n;
		if (n == 5)
			is5++;
		else if (n == 7)
			is7++;
	}

	if ((is5 == 2) && (is7 == 1))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    set_a = set()
    set_b = set()

    for i in range(m):
        a, b = list(map(int, input().split()))

        if a == 1:
            set_b.add(b)
        elif b == n:
            set_a.add(a)

    if set_a & set_b:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


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

const int MAX_N = 110000;

int dp[MAX_N];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < MAX_N; ++i) dp[i] = N;
    dp[0] = 0;
    for (int n = 1; n <= N; ++n) {
        for (int pow6 = 1; pow6 <= n; pow6 *= 6) {
            dp[n] = min(dp[n], dp[n - pow6] + 1);
        }
        for (int pow9 = 1; pow9 <= n; pow9 *= 9) {
            dp[n] = min(dp[n], dp[n - pow9] + 1);
        }
    }

    cout << dp[N] << endl;
}

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

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      mut s: chars,
      mut k: usize,
    }
    const NUM: u8 = 26;
    let n = s.len();
    for i in 0..n {
        let c = (s[i] as u8) - 'a' as u8;
        if c == 0 {
            continue;
        }
        let req = (NUM - c) as usize;
        if k >= req {
            s[i] = 'a';
            k -= req;
        }
    }
    if k > 0 {
        let c = ((s[n-1] as u8) - 'a' as u8 + (k%NUM as usize) as u8) % NUM;
        s[n-1] = (c + 'a' as u8) as char;
    }
    let ans = s.into_iter().collect::<String>();
    puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int i = s;i < e; i++)
#define FOE(i, s, e) for (int i = s;i <= e; i++)
#define FOD(i, s, e) for (int i = s;i >= e; i--)
#define pb push_back
#define LL long long
#define x first
#define y second
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define SET(a, e) memset(a, e, sizeof(a))

int a, b, c, na, nb, nc, ans;

int main () {
	
	scanf("%d%d%d", &a, &b, &c);
	
	while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		ans++;
		if (ans > 100000) return 0 * printf("-1\n");
		na = b / 2 + c / 2;
		nb = a / 2 + c / 2;
		nc = a / 2 + b / 2;
		
		a = na;
		b = nb;
		c = nc;
	}
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x

int main() {

  int N;
  int Even, Odd;
  double ans;

  cin >> N;

  Even = N / 2;
  if( N % 2 != 0 ){
    Odd = Even + 1;
  } else {
    Odd = Even;
  }

  ans = (double)Odd / (double)N;

  cout << ans << endl;

}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<double,double>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<P> a(n);
    rep(i,n) cin>>a[i].first>>a[i].second;
    vector<int> p(n);
    rep(i,n) p[i]=i;
    double sum=0.0;
    double cnt=0.0;
    do{
        rep(i,n-1){
            double x1=a[p[i]].first,y1=a[p[i]].second,x2=a[p[i+1]].first,y2=a[p[i+1]].second;
            sum +=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }
        cnt ++;
    } while (next_permutation(all(p)));
    double ans =sum/cnt;
    cout<<ans<<endl;
}

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

int main()
{
    int a, b;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    while (op != '?')
    {
        switch (op)
        {
        case '+':
            printf("%d\n", a + b);
            break;
        case '-':
            printf("%d\n", a - b);
            break;
        case '*':
            printf("%d\n", a * b);
            break;
        case '/':
            printf("%d\n", a / b);
            break;
        }
        scanf("%d %c %d", &a, &op, &b);
    }
    return 0;
}


Measured memory_bytes: 2044
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    #print("i: "+str(i)+"  j: "+str(j))
    #print(max(l[i], l[j])-min(l[i], l[j]))
    #print(l[i]+l[j])
    #print(list(filter(lambda x: max(l[i], l[j])-min(l[i], l[j])<x<l[i]+l[j], l[j+1:])))
    #temp1 = bisect_left(l[j+1:], l[j]-l[i])
    #temp2 = bisect_left(l[j+1:], l[j]+l[i])
    #print(temp1)
    #print(temp2)
    ans += bisect_left(l[j+1:], l[j]+l[i])
    
print(ans)

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

int main(){
    long N, M, C;
    cin >> N >> M >> C;
    vector<long> B(M);
    for(auto& i : B) cin >> i;
    
    long ans(0), c,  a;
    for(int i = 0; i < N; ++i){
        c = C;
        for(auto i : B){
            cin >> a;
            c += a * i;
        }
        ans += c > 0;
    }
    cout << ans << endl;
    
    return 0;
}


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

#define ll long long

int main()
{
	ll n;
	cin >> n;

	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		if(i%3 != 0 && i%5!=0)
			sum+=i;
	}

	cout<< sum << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll M, D;
    cin >> M >> D;
    
    ll ans = 0;
    for(int i =1 ; i <= M; i++){
        for(int d = 1; d <= D; d++){
            ll a = d/10;
            ll b = d%10;
            if(a < 2 or b < 2) continue;
            if(a*b == i){
                ans ++;
            }
        }
    }
    cout << ans  << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	ll N,t,u=0;
	cin >> N;
	t=N;
	for(;;){
		u=u+t%10;
		t=t/10;
		if(t==0)break;
	}
	if(N%u==0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}


int main(){
    ll N; cin >> N;
    vector<ll> A(N); rep(i,N) cin >> A[i];
    ll t = 1, ct = 0;
    rep(i,N) if(A[i] == t) ct++, t++;
    
    if(ct == N){
        bool flag = true;
        rep(i,N) if(A[i] != i + 1) flag = false;
        if(flag) print(0);
        else print(-1);
    }
    else if(ct == 0) print(-1);
    else print(N-ct);
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    String[] d = new String[k];
    for(int i = 0;i<k;i++){
      d[i] = sc.next();
    }
    int now = n;
    sousa: while(true){
      String nows = String.valueOf(now);
      for(int i = 0;i<k;i++){
        if(nows.contains(d[i])){
          now++;
          continue sousa;
        }
      }
      break;
    }
    System.out.println(now);
  }
}


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

int main(){
    int K, X; cin >> K >> X;
    int r, l;
    if(X + K - 1 > 1000000){
        r = 1000000;
    }else{
        r = X + K - 1;
    }

    if(X - K + 1 < -1000000){
        l = -1000000;
    }else{
        l = X - K + 1;
    }

    for(int i = l; i <= r; i++){
        cout << i << " ";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <fstream>

int main(int argc, char *argv[]){
	//	std::ifstream datafile(argv[1]); //input datafile
	std::string str;
	int mt_height[10] = {}; //height of mountain
	int ans[3] = {}; // top 3 height of mountain. 0 -> no.1 1 -> no.2 2 -> no.3

	// if(datafile.fail()){
	// 	std::cout << "error : can't open this file." << std::endl;
	// 	exit(1);
	// }

	//input 10 height of mountain
	for(size_t i = 0; i < 10; i++){
		std::getline(std::cin, str);
		sscanf(str.c_str(), "%d", &mt_height[i]);

		if((mt_height[i] < 0) || (mt_height[i] > 10000)){
			std::cout << "error : out of constraints" << std::endl;
			exit(1);
		}
	}

	//select top 3 height of mountain and sort ans[]
	for(size_t i = 0; i < 10; i++){
		if(ans[0] < mt_height[i]){
			ans[2] = ans[1];
			ans[1] = ans[0];
			ans[0] = mt_height[i];
		}else if(ans[1] < mt_height[i]){
			ans[2] = ans[1];
			ans[1] = mt_height[i];
		}else if(ans[2] < mt_height[i]){
			ans[2] = mt_height[i];
		}
	}

	//output ans[]
	for(size_t i = 0; i < 3; i++){
		std::cout << ans[i] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3216
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++)
      par[i] = i;
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x)
      return x;
    return par[x] = root(par[x]); // 根の付替
  }

  void unite(int x, int y) { // xとyの木を併合
    if(same(x, y))
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    par[root(x)] = root(y); // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
struct Town {
  int x;
  int y;
  int idx;
};

struct Route {
  int a;
  int b;
  int cost;
};

int main() {
  int N;
  cin >> N;
  vector<Town> towns(N);
  for(int i = 0; i < N; ++i) {
    cin >> towns[i].x >> towns[i].y;
    towns[i].idx = i;
  }
  vector<Route> routes;
  sort(towns.begin(), towns.end(), [](const auto& a, const auto& b) { return a.x < b.x; });
  for(int i = 0; i < N - 1; ++i) {
    routes.push_back({towns[i].idx, towns[i + 1].idx, abs(towns[i].x - towns[i + 1].x)});
  }
  sort(towns.begin(), towns.end(), [](const auto& a, const auto& b) { return a.y < b.y; });
  for(int i = 0; i < N - 1; ++i) {
    routes.push_back({towns[i].idx, towns[i + 1].idx, abs(towns[i].y - towns[i + 1].y)});
  }

  sort(routes.begin(), routes.end(), [](const auto& a, const auto& b) { return a.cost < b.cost; });
  /*
  for(auto& r : routes) {
    cout << r.a << " - " << r.b << " : " << r.cost << endl;
  }
  */
  UnionFind uf(N);
  long long totalCost = 0;
  for(auto& r : routes) {
    if(!uf.same(r.a, r.b)) {
      totalCost += r.cost;
      uf.unite(r.a, r.b);
    }
  }
  cout << totalCost << endl;
  return 0;
}

Measured memory_bytes: 6132
N,M=map(int,input().split())
*A,=map(int,input().split())
A=sorted(A)

while M:
    A[-1]//=2
    M-=1
    i=-2
    while M and (-N<=i and A[i]>=A[-1]):
        A[i]//=2
        M-=1
        i-=1
    A.sort()

print(sum(A))

Measured memory_bytes: 19952
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            int D = in.nextInt();

            int AB = A + B;
            int CD = C + D;
            System.out.println(AB == CD ? "Balanced" : AB > CD ? "Left" : "Right");
        }
    }
}


Measured memory_bytes: 26984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
   int n;cin>>n;
   while(n>=0){
       if(n%4==0){cout<<"Yes";return 0;}
       n-=7;
   }
    cout<<"No";
}


Measured memory_bytes: 256
// C - Lamps

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[200001];
int B[200001];

int main() {
	int N, K;
	cin >> N >> K;

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

	for (int i=0; i<K; i++) {
		for (int j=0; j<N; j++) {
			int l = max(0, j - A[j]);
			int r = min(N, j + A[j] + 1);
			B[l]++;
			B[r]--;
		}

		for (int k=1; k<N; k++) {
			B[k] = B[k-1] + B[k];
		}

		bool all_max = true;
		for (int j=0; j<N; j++) {
			A[j] = B[j];
			B[j] = 0;
			if (A[j] != N) all_max = false;
		}

		if (all_max) break;
	}

	for (int i=0; i<N; i++) {
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 5192
import numpy as np

N = int(input())
h = np.array(list(map(int, input().split())))


def f(H):
  if len(H) == 1:
    return H[0]
  elif len(H) == 0:
    return 0
  else:
    idx = np.argmin(H)
    min_h = H[idx]
    Hl = H[:idx] - min_h
    Hr = H[idx+1:] - min_h
    res = f(Hl) + f(Hr) + min_h
    return res

print(f(h))

Measured memory_bytes: 12504
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int gcd(int x, int y) {
	if(y == 0) return x;
	return gcd(y, x % y);
}

signed main(){
	int N, M;
	string S, T;
	cin >> N >> M >> S >> T;
	int g = gcd(N, M), l = N * M / g;

	if(S[0] != T[0]) {
		cout << -1 << endl;
		return 0;
	}
	if(N > M) {
		swap(N, M);
		swap(S, T);
	}
	int a = l / N, b = l / M;
	for(int i = 0; i < N; ++i) {
		if(a * i % b == 0) {
			if(a * i / b < M && S[i] != T[a * i / b]) {
				cout << -1 << endl;
				return 0;
			}
		}
	}

	cout << l << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

using vec = std::vector<int>;
using Graph = std::vector<vec>;

class BipartiteMatching {
private:
    Graph g;
    std::vector<int> match;
    std::vector<bool> used;

    void init(int V)
    {
        g.resize(V);
        match.resize(V);
        used.resize(V);
    }

    bool dfs(int v)
    {
        used[v] = true;
        for (int u : g[v]) {
            int w = match[u];
            if (w < 0 || (!used[w] && dfs(w))) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

public:
    BipartiteMatching(int V) {
        init(V);
    }

    void add_edge(int u, int v)
    {
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    int bipartite_matching()
    {
        int match_count = 0;
        std::fill(match.begin(), match.end(), -1);
        for (int v = 0; v < (int)g.size(); v++)
            if (match[v] < 0) {
                std::fill(used.begin(), used.end(), false);
                if (dfs(v))
                    match_count++;
            }

        return match_count;
    }
};

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> a(N), b(N), c(N), d(N);
    for (int i = 0; i < N; i++)
        std::cin >> a[i] >> b[i];

    for (int i = 0; i < N; i++)
        std::cin >> c[i] >> d[i];

    BipartiteMatching bm(2 * N);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if (a[i] < c[j] && b[i] < d[j])
                bm.add_edge(i, N + j);

    std::cout << bm.bipartite_matching() << std::endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#define LEN 10001

using namespace std;

int main(void){
	int N;
    int count;
    bool prime[LEN] = {0};
    prime[0] = 1;
    prime[1] = 1;
    for(int i = 2; i*i < LEN; i++){
        for(int j = i*2; j < LEN; j += i){
            prime[j] = 1;
        }
    }
    while(cin >> N){
        count = 0;
        for(int i = 1; i <= N; i++){
            if((!prime[i]) && (!prime[N-i+1])) count++;
        }
        cout << count << endl;
	}
	return 0;
}

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

namespace kakomon
{
    class Program
    {
        static void Main(string[] args)
        {
            sumitb2019_c();
        }

        static void sumitb2019_c()
        {
            // C - 100 to 105
            long x = long.Parse(Console.ReadLine());
            long min_pcs = (long)(x / 105);
            long max_pcs = (long)(x / 100);
            bool succ = false;
            for (long k = min_pcs; k <= max_pcs; k++)
            {
                long rest = x - k * 100;
                if (rest <= k * 5)
                {
                    succ = true;
                    break;
                }
            }
            if (succ) Console.WriteLine(1);
            else Console.WriteLine(0);
        }
    }
}

Measured memory_bytes: 13140
import Foundation

let input = readLine()!.componentsSeparatedByString(" ")
let N = Int(input[0])!
let M = Int(input[1])!

var cnt = Array(count: M, repeatedValue: 0)

for _ in 0 ..< N {
    let input = readLine()!.componentsSeparatedByString(" ")
    let K = Int(input[0])!
    for i in 0 ..< K {
        let A = Int(input[i + 1])! - 1
        cnt[A] += 1
    }
}

var ans = 0
for i in 0 ..< M {
    if cnt[i] == N {
        ans += 1
    }
}

print(ans)

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

int main() {
  int N, M, i, j;
  cin >> N >> M;
  vector<int> vec(N);
  vector<int> vec2;
  vec2.insert(vec2.begin()+0, -1);
  int z = 1;
  for(i = 0; i < N; i++){
    int a;
    cin >> a;
    vec[i] = a;
  }
  for(i = 0; i < M; i++){
    int b, c;
    cin >> b >> c;
    if(vec[b-1] < vec[c-1]){
      for(j = 0; j < z; j++){
        if(vec2[j] == b){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, b);
        z++;
      }
    }else if(vec[b-1] > vec[c-1]){
      for(j = 0; j < z; j++){
        if(vec2[j] == c){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, c);
        z++;
      }
    }else{
      for(j = 0; j < z; j++){
        if(vec2[j] == b){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, b);
        z++;
      }
      for(j = 0; j < z; j++){
        if(vec2[j] == c){
          break;
        }
      }
      if(j == z){
        vec2.insert(vec2.begin()+0, c);
        z++;
      }
    }
  }
  
  cout << N - z + 1 << endl;
}


Measured memory_bytes: 3992
#include <iostream>
#include <string>

using namespace std;

int main(){
	string S;
	cin >> S;
	int len = S.size();
	string ans = "AC";
	if (S[0] != 'A')
		ans = "WA";
	int count = 0;
	for (int i = 1; i < len; i++) {
		if (isupper(S[i])) {
			if (i == 1 or i == (len - 1) or S[i] != 'C') {
				ans = "WA";
			}
			count++;
		}
	}
	if (count != 1)
		ans = "WA";
	cout << ans << endl;
}

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

int main(void)
{
    int n, l, x = 0, count = 0;
    cin >> n;
    if(n>=3 && n<=10)
    {
        for(int i=1; i<=n; i++)
        {
            cin >> l;

            if(l > x)
                x = l;

            count+=l;
        }
        count-=x;
        if(x >= count)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }

}


Measured memory_bytes: 256
import java.lang.Math;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        double m=0;
        double[] si = new double[1001];
        int i,n;
        double z=0;
        while(true){
            n = s.nextInt();
            if(n==0)break;
            for(i=0;i<n;i++){
                si[i]=s.nextInt();
                m+=si[i];
            }
            m/=(double)n;
            for(i=0;i<n;i++)z+=(si[i]-m)*(si[i]-m);
            z/=(double)n;
            System.out.println(Math.sqrt(z));
            m=0;
            z=0;

        }
        
    }
}


Measured memory_bytes: 31268
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
int main(void){
    // Your code here!
 ll a,b,c,d;
 cin >> a >> b >> c >> d;
 cout << max(max(a*c,a*d),max(b*c,b*d));
 return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			System.out.println(N * N * N);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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


int main(){
  int N;
  cin >> N;
  vector<int> M;
  vector<int> P;
  vector<int> Z;
  for(int ii=0; ii<N; ii++){
    int a;
    cin >> a;
    if(a==0){
      Z.push_back(a);
    }else if(a<0){
      M.push_back(a);
    }else{
      P.push_back(a);
    }
  }
  sort(M.begin(), M.end());
  sort(P.begin(), P.end());
  if(Z.size() != 0){
    int ans = 0;
    for(auto& m : M){
      ans -= m;
    }
    for(auto& p : P){
      ans += p;
    }
    cout << ans << endl;
    for(int ii=0; ii<Z.size()-1; ii++){
      cout << 0 << " " << 0 << endl;
    }
    int tmp = 0;
    if(P.size() > 0){
      for(int ii=0; ii<P.size()-1; ii++){
        cout << tmp << " " << P[ii] << endl;
        tmp = tmp - P[ii];
      }
      cout << P[P.size()-1] << " " << tmp << endl;
      tmp = P[P.size()-1] - tmp;
    }
    for(auto& m : M){
      cout << tmp << " " << m << endl;
      tmp = tmp - m;
    }
  }else if(P.size() == 0){
    int ans = 0;
    for(auto& m : M){
      ans -= m;
    }
    ans += M[M.size()-1] * 2;
    cout << ans << endl;
    cout << M[M.size()-1] << " " << M[M.size()-2] << endl;
    int tmp = M[M.size()-1] - M[M.size()-2];
    for(int ii=M.size()-3; ii>=0; ii--){
      cout << tmp << " " << M[ii] << endl;
      tmp = tmp - M[ii];
    }
  }else if(M.size() == 0){
    int ans = 0;
    for(auto& p : P){
      ans += p;
    }
    ans -= P[0] * 2;
    cout << ans << endl;
    cout << P[0] << " " << P[1] << endl;
    int tmp = P[0] - P[1];
    for(int ii=2; ii<P.size()-1; ii++){
      cout << tmp << " " << P[ii] << endl;
      tmp = tmp - P[ii];
    }
    cout << P[P.size()-1] << " " << tmp << endl;
  }else{
    int ans = 0;
    for(auto& m : M){
      ans -= m;
    }
    for(auto& p : P){
      ans += p;
    }
    cout << ans << endl;
    int tmp = M[0];
    for(int ii=0; ii<P.size()-1; ii++){
      cout << tmp << " " << P[ii] << endl;
      tmp = tmp - P[ii];
    }
    cout << P[P.size()-1] << " " << tmp << endl;
    tmp = P[P.size()-1] - tmp;
    for(int ii=1; ii<M.size(); ii++){
      cout << tmp << " " << M[ii] << endl;
      tmp = tmp - M[ii];
    }
  }
  return 0;
}


Measured memory_bytes: 2424
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

int n;
int w[1000];
int k[1000];
int u[1000];

int main(){
	scanf("%d", &n);
	rep(i, n){
		scanf("%d", &w[i]);
	}

	vector<int> v(w, w + n);
	sort(v.begin(), v.end());
	rep(i, n){
		k[i] = lower_bound(v.begin(), v.end(), w[i]) - v.begin();
	}

	int x = *min_element(w, w + n);
	int ans = 0;
	rep(i, n){
		if(u[i]){
			continue;
		}
		int c = 1;
		int s = w[i];
		int m = w[i];
		u[i] = true;
		int j = k[i];
		while(!u[j]){
			++c;
			s += w[j];
			m = min(m, w[j]);
			u[j] = true;
			j = k[j];
		}
		ans += min(s + m * (c - 2), (s - m + x) + x * (c - 2) + 2 * (m + x));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2848
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int x = sc.nextInt();

        int[] primes = new int[101000];

        for (int i = 2; i < 101000; i++) {
            if (isPrime(i)) {
                primes[i] = i;
            } else {
                primes[i] = Integer.MAX_VALUE;
            }
        }

        System.out.println(IntStream.of(Arrays.copyOfRange(primes, x, primes.length)).min().getAsInt());
    }

    public static boolean isPrime(int n) {
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 27220
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

int main()
{
	int n;
	while(scanf("%d", &n) != EOF){
		printf("3C%02d\n", (n+38)%39+1);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;
using uset = unordered_set<int>;

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b;
    rep(i,N) cin >> a[i];
    b = a;
    sort(all(b));
    int ans = 0;
    int cnt = 0;
    rep(i,N) cnt += (a[i] == b[i]);
    if(cnt == N){
        cout << 0 << endl;
        return 0;
    }

    int Q;
    cin >> Q;
    
    rep(i,Q){
        int x, y;
        cin >> x >> y;
        x--, y--;
        swap(a[x], a[y]);
        if(a[y] == b[x] && a[x] != b[x]) cnt--;
        if(a[x] == b[y] && a[y] != b[y]) cnt--;
        if(a[y] != b[x] && a[x] == b[x]) cnt++;
        if(a[x] != b[y] && a[y] == b[y]) cnt++;
        ans++;

        if(cnt == N) break;
    }

    if(a != b) ans = -1;

    cout << ans << endl;
}



Measured memory_bytes: 5208
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;

    sort(s.begin(), s.end());

    if (s == "abc")
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string s;
int main()
{
	cin>>s;
	int len=s.size();
	if(len%2==1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	//cout<<s<<endl;
	for(int i=0;i<len/2;i++)
	{
		if((s[i]=='p'&&s[len-i-1]=='q')||(s[i]=='q'&&s[len-i-1]=='p')||(s[i]=='d'&&s[len-i-1]=='b')||(s[i]=='b'&&s[len-i-1]=='d'))
		{
			continue;
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	} 
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll w[1005],s[1005],v[1005],dp[1005][20005],n;
pll a[1005];
ll f(ll i,ll ww)
{
	if(ww<0||i==n)
		return 0;
	if(dp[i][ww]!=-1)
		return dp[i][ww];
	dp[i][ww]=max(f(i+1,ww),(ww-w[a[i].S]>=0?v[a[i].S]+f(i+1,min(s[a[i].S],ww-w[a[i].S])):0));
	return dp[i][ww];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    rep(i,0,n)
    {
    	cin>>w[i]>>s[i]>>v[i];
    	a[i]={w[i]+s[i],i};
    }
    sort(a,a+n,greater<pll>());
    cout<<f(0,20004);
}


Measured memory_bytes: 157440