akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations

N = int(input())
k = 1
while k**2 - k < 2*N: k += 1
if k**2 - k != 2*N: print('No')
else:
    print('Yes')
    print(k)
    sets = [[] for _ in range(k)]
    n = 1
    for i, j in combinations(range(k), 2):
        sets[i].append(n)
        sets[j].append(n)
        n += 1
    for S in sets: print(len(S), *S)

Measured memory_bytes: 9416
extern crate core;

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

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

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

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

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

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

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

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

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    (1..n)
        .map(|x| (x, n - x))
        .map(|(a, b)| f(a) + f(b))
        .min()
        .unwrap()
        .to_string()
}

fn f(n: i64) -> i64 {
    n.to_string()
        .chars()
        .map(|x| x.to_string().parse::<i64>().unwrap())
        .sum()
}

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

tests! {
    test1: "15" => "6",
    test2: "100000" => "10",
}


Measured memory_bytes: 4352
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (unsigned long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (unsigned long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
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; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    string s;
    cin >> s;

    int planA = 0, planB = 0;
    REP(i, s.size()) {
        int si = s[i] - '0';
        if (si == i % 2) {
            planB++;
        } else {
            planA++;
        }
    }

    cout << min(planA, planB) << endl;
    
}

Measured memory_bytes: 512
int a[300002], g[300002];

#define gc() getchar()
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

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

int main()
{
	int i, N, Q, x, y, t, xx, yy;
	int cnt;

	N = in();
	for (i = 1; i <= N; i++) g[i] = a[i] = in();
	qsort(g+1, N, sizeof(int), cmp);
	for (cnt = 0, i = 1; i <= N; i++) {
		if (g[i] != a[i]) cnt++;
	}
	if (cnt == 0) {
		puts("0");
		return 0;
	}
	Q = in();
	for (i = 1; i <= Q; i++) {
		x = in(), y = in();
		xx = a[x], yy = a[y];
		t = a[x], a[x] = a[y], a[y] = t;
		if (xx == g[x] && a[x] != g[x]) cnt++;
		else if (xx != g[x] && a[x] == g[x]) cnt--;
		if (yy == g[y] && a[y] != g[y]) cnt++;
		else if (yy != g[y] && a[y] == g[y]) cnt--;
		if (cnt == 0) {
			printf("%d\n", i);
			break;
		}
	}
	if (cnt) puts("-1");
	return 0;
}


Measured memory_bytes: 5012
#include<stdio.h>
int main(void){
    int h, w, counth, countw;
    while(1){
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) break;
        for(counth = 0; counth < h; counth ++){
            for(countw = 0; countw < w; countw ++){
                for(;(0 < counth && counth < h- 1) && (0 <countw && countw < w -1 );countw++){
                    printf(".");
                }
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
/**
 *  author: mahfuzz
 *  created: 10.04.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << #x << ':' << x << "\n"
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
  
    
    int n, r; cin >> n >> r;
    
    if(n >= 10){
        cout << r << "\n";
    }else{
        cout << r + (100 *(10 - n)) << "\n";
    }
        
    return 0;
}



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

int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int d_ab = abs(b - a);
	int d_ac = abs(c - a);
	int d_bc = abs(c - b);
	
	
	if (d_ac <= d) {
		cout << "Yes" << endl;
		return 0;
	}

	if ((d_ab <= d) && (d_bc <= d)) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}

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

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

    int a[n];
    int b[n];
    int c[n];
    int point = 0;
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    for (int i=0; i<n; ++i){
        cin >> b[i];
        point+=b[i];
    }
    for (int i=0; i<n-1; ++i){
        cin >> c[i];
    }

    int pre_now = a[0]-1;
    int now;
    for (int i=0; i<n; ++i){
        now = a[i]-1;
        if (now - pre_now==1){
            point+=c[pre_now];
        }
        pre_now = now;
    }
    cout << point << endl;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    robots = []
    for i in range(n):
        x, l = map(int, input().split())
        robots.append((x - l, x + l))
    robots = sorted(robots, key=lambda x: x[1])
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(robots[i][1])
        else:
            if robots[i][0] >= ans[-1]:
                ans.append(robots[i][1])
    print(len(ans))


Measured memory_bytes: 19016
#include <bits/stdc++.h>
using i64 = int_fast64_t;
using namespace std;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

vector<vector<int>> calcNext(const std::string& s) {
    int n = (int)s.size();
    vector<vector<int>> res(n + 1, vector<int>(10, n));
    for(int i = n - 1; i >= 0; --i) {
        for(int j = 0; j < 10; ++j) res[i][j] = res[i + 1][j];
        res[i][s[i] - '0'] = i;
    }
    return res;
}

void solve() {
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    auto dict = calcNext(S);
    int cnt = 0;
    for(int n = 0; n < 1000; n++) {
        int i = n / 100;
        int j = (n - i * 100) / 10;
        int k = n % 10;
        int ii = N, jj = N, kk = N;
        ii = dict[0][i];
        if(ii < N)
            jj = dict[ii + 1][j];
        if(jj < N)
            kk = dict[jj + 1][k];
        if(kk < N)
            cnt++;
    }
    cout << cnt << endl;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

int main(){
    int N, t, x, y, sum;
    bool can = true;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> t >> x >> y;
        sum = abs(x) + abs(y);
        if((sum + t)%2 == 1 or sum > t) can = false;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    int v[110];
    
    int A = 0, B = 0, AB = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(v[i] <= a) A++;
        else if(a + 1 <= v[i] && v[i] <= b) AB++;
        else B++;
    }
    
    cout << min({A, B, AB});
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define em emplace
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = 1<<30;
constexpr ll LINF = 1LL<<58;
constexpr int mod = 1000000007;

int dp[3030][3030];

int main(){
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if(s[i] == t[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            chmax(dp[i + 1][j + 1], max(dp[i + 1][j] , dp[i][j + 1]));
        }
    }
    string ans = "";
    int i = s.size(), j = t.size();
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i - 1][j]) i--;
        else if(dp[i][j] == dp[i][j - 1]) j--;
        else {
            i--; j--;
            ans += s[i];
        }
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define endl '\n'

long long n, a[200005], l[200005],r[200005], pos[200005], ans = 0;
stack <int> st,stt;

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

    cin>>n;

    for (int i = 1;i<=n; i++) {
		cin>>a[i];
		pos[a[i]] = i;
    }
    for (int i = 1; i<=n; i++) {
        while (!st.empty() && a[st.top()]>=a[i]) {
            st.pop();
        }
        if (st.empty()) {
            l[i] = 0;
        }
        else {
            l[i] = st.top();
        }
        st.push(i);
    }
    for (int i = n; i>=1; i--) {
        while (!stt.empty() && a[stt.top()]>=a[i]) {
            stt.pop();
        }
        if (stt.empty()) {
            r[i] = n+1;
        }
        else {
            r[i] = stt.top();
        }
        stt.push(i);
    }
    for (int i = 1; i<=n; i++) {
		ans+=(r[i] - i)*(i - l[i])*a[i];
    }
    cout<<ans;


    return 0;
}



Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int n=s.size(),x=0,a=0,b,y,ans[200001]={0};
    rep(i,n+1){
        if(i<n&&x==0&&s[i+1]=='L') x++,y=i;
        if(i==n||x==1&&s[i+1]=='R'){
            b=i-(i==n);
            for(int j=a;j<=b;j++){
                if(j%2) ans[y+(y+1)%2]++;
                else ans[y+y%2]++;
            }
            a=i+1;
            x=0;
        }
    }
    rep(i,n) cout<<ans[i]<<" ";
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<string> name(n);
    vector<int> ncount(5);
    rep(i, n) cin >> name[i];
    sort(name.begin(), name.end());
    rep(i, n) {
        switch(name[i][0]) {
            case 'M':
                ncount[0] += 1;
                break;
            case 'A':
                ncount[1] += 1;
                break;
            case 'R':
                ncount[2] += 1;
                break;
            case 'C':
                ncount[3] += 1;
                break;
            case 'H':
                ncount[4] += 1;
                break;
        }
    }

    ll ans = 0;
    for(int i = 0; i < 1 << 5; i++) {
        int cnt = 0;
        ll ansi = 1;
        for(int j = 0; j < 5; j++) {
            if(i & (1 << j)) {
                ansi *= (ll)ncount[j];
                cnt += 1;
            }
        }
        if(cnt == 3) ans += ansi;
    }

    cout << ans << endl;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (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 INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
	int N, D;
	cin >> N >> D;
	vector<vector<int>> v(N, vector<int>(D));
	REP(i, N) REP(j, D) cin >> v[i][j];
	int ans = 0;
	int i;
	for(i = 0; i < N-1; i++){
		for(int j = i+1; j <= N-1; j++){
		double tmp = 0;
		int k = 0;
		while(k < D){
			tmp += pow(abs(v[i][k] - v[j][k]), 2.0);
			k++;
		}
		tmp = sqrt(tmp);
		if(ceil(tmp) == floor(tmp)) ans++;
		//cout << tmp << endl;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int a,b,c,d,i=0;
	cin>>a>>b>>c>>d;
	while(a>0 && c>0) {
		if(~i&1) c-=b;
		else a-=d;
		++i;
	}
	cout<<(a>0 ? "Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3132
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int d;
	cin >> d;
	puts(d >= 30 ? "Yes" : "No");
	return 0;
}


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

int main(){
    string s;
    getline(cin, s);

    int n = s.length();
    string ans = "";
    for(int i=0; i<n; i++){
        if(i+4 < n && s.substr(i, 5) == "apple"){
            ans += "peach";
            i += 4;
        }else if(i+4 < n && s.substr(i, 5) == "peach"){
            ans += "apple";
            i += 4;
        }else{
            ans += s[i];
        }
    }
    cout << ans << endl;
    return 0;
}



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

#define mp(x, y) make_pair((x), (y))

typedef long long ll;

int n, m;
int d[100005];

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=0; i<m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		d[a]++;
		d[b]++;
	}
	for(int i=1; i<=n; i++) {
		if(d[i]%2) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");

	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n,m; cin >> n >> m; ll left = 1; ll right = n;
  
  for(ll i=0; i < n; i++){
    ll x,y; cin >> x >> y;
    left = max(left,x); right = min(right,y);
  }
  
  cout << max(right - left + 1 ,ll(0))<< endl;
}

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  vector<vector<int>> grid(H, vector<int>(W, 0));
  queue<pair<int, int>> que;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') que.push(make_pair(i, j));
    }
  }
  while (!que.empty()) {
    auto q = que.front();
    que.pop();
    int y = q.first, x = q.second;
    for (int k = 0; k < 4; k++) {
      int ny = y + dy[k], nx = x + dx[k];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if (S[ny][nx] == '#' || grid[ny][nx] != 0) continue;
      grid[ny][nx] = grid[y][x] + 1;
      que.push(make_pair(ny, nx));
    }
  }
  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      res = max(res, grid[i][j]);
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 13456
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

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

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a) * b);
}

xy_t projection(const line &l, const xy_t &p){
	double t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
	return l.first + t * (l.first - l.second);
}

bool intersectSP(const line &l, const xy_t &p){
	return abs(l.first- p) + abs(l.second - p) - abs(l.first - l.second) < EPS;
}

double distanceSP(line s, xy_t p){
	const xy_t r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s.first - p), abs(s.second - p));
}

xy_t center[200];
double r[200];

int main(){
	int n, m;
	double wx, wy, tx, ty, sx, sy;
	while(cin >> n && n){
		rep(i, n){
			cin>> wx >> wy >> r[i];
			center[i] = xy_t(wx, wy);
		}
		cin >> m;
		rep(i, m){
			cin >> tx >> ty >> sx >> sy;
			line ls = line(xy_t(tx, ty), xy_t(sx, sy));
			bool ok = true;
			rep(j, n){
				if(distanceSP(ls, center[j]) < r[j] + EPS &&
					max(abs(center[j] - ls.first), abs(center[j] - ls.second)) > r[j] - EPS){
						//cout << center[j] << " " << distanceSP(ls, center[j]) << endl;
						ok = false;
				}
			}
			if(!ok) cout << "Safe" << endl;
			else cout << "Danger" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
# 貪欲+山登り(日付だけランダム)
import time
import random

d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = []
L = [-1 for j in range(26)]
for i in range(d):
    max_diff = -10**7
    arg_max = 0
    for j in range(26):
        memo = L[j]
        L[j] = i
        diff = S[i][j] - sum([C[k] * (i - L[k]) for k in range(26)])
        if diff > max_diff:
            max_diff = diff
            arg_max = j
        L[j] = memo
    T.append(arg_max)
    L[arg_max] = i


def calc_score(T):
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    return score


score = calc_score(T)
start = time.time()
while True:
    now = time.time()
    if now - start > 1.8:
        break
    i = random.choice(range(d))
    arg_max = 0
    max_diff = 0
    for j in range(26):
        memo = T[i]
        T[i] = j
        new_score = calc_score(T)
        if new_score - score > max_diff:
            max_diff = new_score - score
            arg_max = j
        T[i] = memo
    if max_diff > 0:
        T[i] = arg_max
        score += max_diff

for t in T:
    print(t + 1)


Measured memory_bytes: 85664
#include <iostream>
#include <vector>
#include <algorithm>
#include<string>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a>b&&a>>c){
    cout << b*c << endl;
  }
  else if(b>a&&b>c){
    cout << a*c << endl;
  }
  else if(c>a&&c>b){
    cout << (a*b)/2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> pair;
bool seen[505][505];

//dpTable
//bool dp[100050];

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    int cnt = 0;
    rep (i,N) {
        cin >> p.at(i);
        if (i + 1 != p.at(i)) cnt++;
    }
    if (cnt == 0 || cnt == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
char x; cin >> x;
if('A' <= x && x <= 'Z') cout << 'A';
else cout << 'a';
}

Measured memory_bytes: 3564
import collections
from operator import itemgetter
N = int(input())
SP = []
for i in range(N):
    s,p = input().split()
    SP.append([0,0])
    SP[i][0] = s
    SP[i][1] = int(p)
SP_new = sorted(SP)
t = 0
for i in range(N):
    if t > 0:
        t -= 1
        continue
    s = SP_new[i][0]
    t = 0
    for j in range(i+1, N):
        if s == SP_new[j][0]:
            t += 1
        else:
            break
    SP_new_new = SP_new[i:i+t+1]
    SP_new_new.sort(key = itemgetter(1))
    for k in range(1,len(SP_new_new)+1):
        u = SP_new_new[-k]
        print(SP.index(u)+1)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 0; i <= n;++i)
  {
    if(i%3!=0&&i%5!=0)
      sum += i;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define base 950527
#define base2 1777771
#define N 1001
using namespace std;
typedef unsigned long long ull;
ull A[N][N],tmp[N][N],ans;
int w,h,p,a[N][N],b[N][N];

void Reverse(){for(int i=0;i<p;i++)reverse(b[i],b[i]+p);}

void rol_90(){
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++) tmp[p-j-1][i]=b[i][j];
  
  for(int i=0;i<p;i++)
    for(int j=0;j<p;j++) b[i][j]=tmp[i][j];
}

ull ctoi(char ch){
  if('A'<=ch&&ch<='Z') return ch-'A';
  if('a'<=ch&&ch<='z') return 26+ch-'a';
  if(isdigit(ch)) return 52+ch-'0';
  if(ch=='+') return 62;
  return 63;
}

void in(int y,int tmp[1001][1001]){
  string str[1001];
  for(int i=0;i<y;i++) cin>>str[i];
  
  for(int i=0;i<y;i++)
    for(int j=0;j<str[i].size();j++)
      for(int k=0;k<6;k++)tmp[i][6*j+5-k]=(ctoi(str[i][j])>>k)&1;
}

set <ull> S;
void roll_hs(){
  ull target=0;
  for(int i=0;i<p;i++){
    ull k=0;
    for(int j=0;j<p;j++)k=k*base+b[i][j];
    target=target*base2+k; 
  }
  
  if(S.count(target))return;
  S.insert(target);
  
  for(int i=0;i<h;i++){
    ull k=0,l=1;
    for(int j=0;j<w;j++){
      k=k*base+a[i][j];
      if(j-p>=0) k-=l*a[i][j-p];
      else l*=base;
      A[i][j]=k;
    }
  }

  for(int j=p-1;j<w;j++){
    ull k=0,l=1;
    for(int i=0;i<h;i++){
      k=k*base2+A[i][j];
      if(i-p>=0) k-=l*A[i-p][j];
      else l*=base2;
      if(target==k&&i>=p-1)ans++;
    }
  }
}

int main(){
  while(1){
    cin>>w>>h>>p;
    if(!w&&!h&&!p)break;
    in(h,a),in(p,b);
    
    ans=0,S.clear();
    for(int i=0;i<4;i++){
      rol_90(),roll_hs(); 
      Reverse(),roll_hs(),Reverse();
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 19232
#include <bits/stdc++.h>
#include <tuple>
#include <iterator>
using namespace std;
using ll = long long;

int main()
{
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
  {
    int t;
    cin >> t;
  }
  cout << (n + k - 3) / (k - 1) << endl;

  return 0;
}


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

typedef struct node{
 int num;
 struct node *left;
 struct node *right;
}node;


node * makenode(int x){

 node *new=malloc(sizeof(node));
 new->right=NULL;
 new->left=NULL;
 new->num=x;

return new;
}


int main(){
 int n,i,x;
 char com[13];
 node *front=NULL;
 node *rear=NULL;
 node *new;
 node **p;
 node *q;

 scanf("%d",&n);

 for(i=0;i<n;i++){
  scanf("%s",com);

  if(com[0]=='i'){
    scanf("%d",&x);
    new=makenode(x);
    new->right=front;
    if(front!=NULL)front->left=new;
    else rear=new;
    front=new;
  }

  else if(strcmp(com,"deleteFirst")==0){
    front=front->right;
    if(front!=NULL){
       free(front->left);
       front->left=NULL;
    }
    else rear=NULL;
  }

  else if(strcmp(com,"deleteLast")==0){
    rear=rear->left;
    if(rear==NULL)front=NULL;
    else {
     free(rear->right);
     rear->right=NULL;
    }
  }

  else if(strcmp(com,"delete")==0){
    scanf("%d",&x);
    p=&front;
    while((*p)!=NULL && (*p)->num != x)p=&((*p)->right);
    if((*p)!=NULL){
     if((*p)->right == NULL){
        rear=rear->left;
        free((*p));
        (*p)=NULL;
     }
     else {
        (*p)->right->left=(*p)->left;
        (*p)=(*p)->right;
     }
    }
  }

 }

 q=front;
 while(q!=NULL){
  if(q==rear)printf("%d\n",q->num);
  else printf("%d ",q->num);
  q=q->right;
 }

return 0;
}


Measured memory_bytes: 32944
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long[][] comb = new long[100][100];
		for (int i = 0; i < 100; i++) {
		    for (int j = 0; j <= i; j++) {
		        if (j == 0 || j == i) {
		            comb[i][j] = 1;
		        } else {
		            comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; 
		        }
		    }
		}
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 1; i <= n; i++) {
		    int x = i;
		    for (int j = 2; j <= Math.sqrt(x); j++) {
		        while (x % j == 0) {
		            if (map.containsKey(j)) {
		                map.put(j, map.get(j) + 1);
		            } else {
		                map.put(j, 1);
		            }
		            x /= j;
		        }
		    }
		    if (x != 1) {
		        if (map.containsKey(x)) {
		            map.put(x, map.get(x) + 1);
		        } else {
		            map.put(x, 1);
		        }
		    }
		}
		int over75 = 0;
		int over25 = 0;
		int over15 = 0;
		int over5 = 0;
		int over3 = 0;
		for (int x : map.values()) {
		    int y = x + 1;
		    if (y >= 75) {
		        over75++;
		        over25++;
		        over15++;
		        over5++;
		        over3++;
		    } else if (y >= 25) {
		        over25++;
		        over15++;
		        over5++;
		        over3++;
		    } else if (y >= 15) {
		        over15++;
		        over5++;
		        over3++;
		    } else if (y >= 5) {
		        over5++;
		        over3++;
		    } else if (y >= 3) {
		        over3++;
		    }
		}
		long total = 0;
		total += comb[over75][1];
		total += comb[over25][1] * comb[Math.max(over3 - 1, 0)][1];
		total += comb[over15][1] * comb[Math.max(over5 - 1, 0)][1];
		total += comb[over5][2] * comb[Math.max(over3 - 2, 0)][1];
		System.out.println(total);
    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int l, r, L, R;
    cin >> L >> R;
    l = L % 2019;
    r = R % 2019;
    int mini = 2020000;

    bool ch = false;

    //    if(l==0 || r==0)
    //    {
    //
    //        cout << 0 << endl;
    //        return 0;
    //    }
    for (int i = L;i<=R;i++)
    {
        if(i%2019==0)
        {
            cout << 0 << endl;
            return 0;
        }

    }

        if (l == r)
        {

            cout << 0 << endl;
            return 0;
        }
    if (l < r)
    {
        for (int i = l; i <= r; i++)
        {

            for (int j = i; j <= r; j++)
            {
                if (j != i)
                {
                    //                    cout << "i: " << i<< "j: " << j << endl;
                    int temp = (i * j) % 2019;
                    mini = min(mini, temp);
                    //                    cout << "mini: " << mini <<endl;
                    if (mini == 0)
                    {

                        ch = true;
                        break;
                    }
                }
            }
            if (ch)
            {

                break;
            }
        }
    }
    else
    {

        for (int i = l; i >= r; i--)
        {

            for (int j = i; j >= r; j--)
            {
                if (j != i)
                {
                    int temp = (i * j) % 2019;
                    mini = min(mini, temp);
                    if (mini == 0)
                    {

                        ch = true;
                        break;
                    }
                }
            }
            if (ch)
            {

                break;
            }
        }
    }

    cout << mini << endl;
}

Measured memory_bytes: 256
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
sumls=[0 for _ in range(N-K+1)]
sumls[0]=sum(ls[:K])
for i in range(N-K):
  sumls[i+1]=sumls[i]+ls[K+i]-ls[i]
x=max(sumls)
print((x+K)/2.0)

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


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

    if(a%3==0 || b%3==0 || (a+b)%3==0)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int A = sc.nextInt();
        int[] H = new int[N];
        double[] temperatures = new double[N];
        double diffMin = 1000000000;
        int index = 0;

        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }

        for (int i = 0; i < N; i++) {
            temperatures[i] = T - H[i] * 0.006;
            double diff = Math.abs(A - temperatures[i]);
            if (diff < diffMin) {
                diffMin = diff;
                index = i;
            }
        }

        System.out.println(index + 1);

    }

}


Measured memory_bytes: 24148
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    w,h,n = f()

    xmin = 0
    xmax = w

    ymin = 0
    ymax = h
    for i in range(n):
        x,y,a = f()
        if a== 1:
            xmin = max(xmin, x)
        if a == 2:
            xmax = min(xmax, x)
        
        if a== 3:
            ymin = max(ymin, y)
        if a == 4:
            ymax = min(ymax, y)


    print(max(xmax - xmin,0) * max(ymax - ymin,0))


solve()


Measured memory_bytes: 3064
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long ans = 0;

            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int[] A = new int[N];
            int counter = 0;

            for(int i=0;i<N;i++)
            {
                if (s[i].IndexOf('-') == 0)
                    counter++;

                A[i] = int.Parse(s[i].TrimStart('-'));
                ans += A[i];
            }

            if(counter %2 !=0)
            {
                Array.Sort(A);

                ans -= A[0] * 2;

            }


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


Measured memory_bytes: 29660
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;



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

  ll p;
  std::cin>>p;

  std::vector<ll> facto(p,1),facto_inv(p,1);

  rep(i,1,p)facto[i]=(facto[i-1]*i)%p;
  rep(i,0,p)facto_inv[i]=pow_mod(facto[i],p-2,p);

  std::vector<ll> ans(p,0);

  rep(i,0,p){
    ll a;
    std::cin>>a;
    if(a==1){
      ans[0]=(ans[0]+1)%p;
      ll powpow=1;
      for(ll j=p-1;j>=0;j--){
        ll temp=powpow;
        temp=(temp*facto[p-1])%p;
        temp=(temp*facto_inv[j])%p;
        temp=(temp*facto_inv[p-1-j])%p;

        ans[j]=(ans[j]+p-temp)%p;

        powpow=(powpow*(p-i))%p;
      }
    }
  }

  rep(i,0,p)std::cout<<ans[i]<<" ";
  std::cout<<"\n";

  return 0;
}

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

double xp,yp;

double length(double x1,double y1,double x2,double y2){
  double a,b,c;
  
  if(x2>x1){
    a=x2-x1;
  }
  else{
    a=x1-x2;
  }
  if(y2>y1){
    b=y2-y1;
  }
  else{
    b=y1-y2;
  }
  c=a*a+b*b;
  c=sqrt(c);
  return(c);
}

double radius(double a,double b,double c){
  double r,temp;
  double numerator,denominator;
  numerator=a*b*c;
  //  printf("num:%.4f\n",numerator);
  temp=(a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c);
  //  printf("temp:%.4f\n",temp);
  denominator=sqrt(temp);
  //  printf("den:%.4f\n",denominator);
  r=numerator/denominator;
  return(r);
}

coordinates(double x1,double y1,double x2,double y2,double x3,double y3){
  double x,y;
  double a1,b1,c1,a2,b2,c2;
  
  a1=2*(x2-x1);
  b1=2*(y2-y1);
  c1=(x1*x1)-(x2*x2)+(y1*y1)-(y2*y2);
  a2=2*(x3-x1);
  b2=2*(y3-y1);
  c2=(x1*x1)-(x3*x3)+(y1*y1)-(y3*y3);
 
  xp=((b1*c2)-(b2*c1))/((a1*b2)-(a2*b1));
  yp=((c1*a2)-(c2*a1))/((a1*b2)-(a2*b1));
}

int main(void){
  double x1,y1,x2,y2,x3,y3;
  double r;
  double a,b,c;
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
    //   printf("input : %.4f %.4f %.4f %.4f %.4f %.4f\n",x1,y1,x2,y2,x3,y3);
    a=length(x1,y1,x2,y2);
    b=length(x1,y1,x3,y3);
    c=length(x2,y2,x3,y3);
    //    printf("length : %.4f %.4f %.4f\n",a,b,c);
    r=radius(a,b,c);
    //    printf("r : %.3f\n",r);  //result
    coordinates(x1,y1,x2,y2,x3,y3);
    //    printf("x=%.3f y=%.3f\n",xp,yp);    
    printf("%.3f %.3f %.3f\n",xp,yp,r);
  }
  return(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> arr;
typedef vector<arr> matrix;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;

void lengthLCS(string x, string y, matrix &dp) {
	for (int i = 1; i <= x.size(); ++i) {
		for (int j = 1; j <= y.size(); ++j) {
			dp[i][j] = (x[i - 1] == y[j - 1]) ? (1 + dp[i - 1][j - 1]) : max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
}
string LCS(string x, string y, matrix dp) {
	int len = dp[x.size()][y.size()];
	int i = x.size();
	int j = y.size();
	string res(len, ' ');
	len = len - 1;
	while (i > 0 && j > 0) {
		if (x[i - 1] == y[j - 1]) {
			res[len] = x[i - 1];
			--i; --j; --len;
		}
		else {
			if (dp[i - 1][j] > dp[i][j - 1]) --i;
			else --j;
		}
	}
	return res;
}

int main() {
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
//#endif
	string x; string y;
	cin >> x >> y;
	matrix dp(x.size() + 1, arr(y.size() + 1, 0));
	lengthLCS(x, y, dp);

	cout << LCS(x, y, dp);
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
int inv(int n){
    return p(n, MOD-2);
}
vector<int> fact;
int nCr(int n, int r){
    // if(r == 0)  return 1;
    return m(m(m(fact[n])*m(inv(fact[r])))*m(inv(fact[n-r])));
}
signed main(){
    fast();
    string s;
    int k;
    cin >> k;
    cin >> s;
    int n = k+s.length();
    fact.resize(2000001);
    fact[0] = 1;
    for(int i=1; i<=2000000; i++){
        fact[i] = m(m(fact[i-1])*m(i));
    }
    int z = 26;
    int ans = p(z,n), f = 0;
    for(int i=0; i<s.length(); i++){
        f = m(m(nCr(n, i))*m(p(z-1, n-i)));
        ans = m(m(ans)-m(f));
    }
    // cout << f << endl;
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 20160
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
int a,b,c,k,g;
int main()
{
	cin>>a>>b>>c>>k;
	for(int i=0; i<=a; i++)
		for(int j=0; j<=b; j++)
			for(int s=0; s<=c; s++)
			{
				if(i*500+j*100+s*50==k)g++;
				if(i*500+j*100+s*50>k)break;
			}	
	cout<<g<<endl;
	return 0;
}


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

// auto mod int
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    mint ans = mint(2).pow(n);
    ans -= 1;
    ans -= choose(n, a); 
    ans -= choose(n, b); 
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := readInt()
	a := make([][]int, N)
	for i := 0; i < N; i++ {
		a[i] = make([]int, N-1)
		for j := 0; j < N-1; j++ {
			a[i][j] = readInt() - 1
		}
	}

	nextIndex := make([]int, N)
	nextQueue := make([]int, 0, N)
	for i := 0; i < N; i++ {
		nextQueue = append(nextQueue, i)
	}
	result := 0
	finished := 0

	for len(nextQueue) > 0 {
		result++
		queue := nextQueue
		nextQueue = nil
		booked := make([]bool, N)
		for i := 0; i < len(queue); i++ {
			player := queue[i]
			if booked[player] {
				continue
			}
			opponent := a[player][nextIndex[player]]
			if booked[opponent] {
				continue
			}
			if a[opponent][nextIndex[opponent]] != player {
				continue
			}
			booked[player] = true
			booked[opponent] = true
			nextIndex[player]++
			nextIndex[opponent]++
			if nextIndex[player] == N-1 {
				finished++
			} else {
				nextQueue = append(nextQueue, player)
			}
			if nextIndex[opponent] == N-1 {
				finished++
			} else {
				nextQueue = append(nextQueue, opponent)
			}
		}
	}
	if finished == N {
		fmt.Println(result)
	} else {
		fmt.Println(-1)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 19200
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
edges = [[] for _ in range(n)]
for a, b in ab:
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
reached = [False for i in range(n)]
def dfs(edge, r):
    if all(r):
        return 1
    ret = 0
    for e in edges[edge]:
        if r[e]:
            continue
        r[e] = True
        ret += dfs(e, r)
        r[e] = False
    return ret
reached[0] = True
print(dfs(0, reached))


Measured memory_bytes: 3064
#include <cstdio>

int main(void){
  int n=0;
  int m=0;
  scanf("%d",&n);
  while(n!=0){
    scanf("%d",&m);

    int fr=0;
    //0がo,1がi
    int rsf=0;
    //1で継続中
    char mz=0;
    int mzs=0;
    int ans=0;
    
    int y=0;
    for(y=0;y<m;y++){
      mz=getchar();
      if(rsf==0){
	if(mz=='I'){
	  rsf=1;
	  fr=1;
	}
      }
      else{
	if(fr==0){
	  if(mz=='I'){
	    mzs++;
	    fr=1;
	  }
	  else{
	    rsf=0;
	    if(mzs>=n){
	      ans+=mzs-n+1;
	    }
	    mzs=0;
	  }
	}
	else{
	  if(mz=='O'){
	    fr=0;
	  }
	  else{
	    if(mzs>=n){
	      ans+=mzs-n+1;
	    }
	    mzs=0;
	  }
	}
      }
    }
    if(mzs>=n){
      ans+=mzs-n+1;
    }
    mzs=0;
    
    printf("%d\n",ans);
    getchar();
    scanf("%d",&n);
  }
  return 0;
}

Measured memory_bytes: 1032
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int x = sc.nextInt();
        
        if (x % 1000 == 0) {
            System.out.println(0);
        } else {
            System.out.println(1000 - x % 1000);
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const ld PI = acos(-1);

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ld R;
	cin >> R;
	cout << fixed << setprecision(10) << 2 * PI * R << "\n";
	return 0;
}

Measured memory_bytes: 3808
package main
import (
	"fmt"
	"sort"
)
func main() {
	var i, n, k, temp int
	fmt.Scan(&n, &k)
	a:=make([]int, n)
	for i=0;i<n;i++{
		fmt.Scan(&a[i])
	}
	ans:=1000000001
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for i=0;i<n-k+1;i++{
		temp=a[i]-a[i+k-1]
		if temp<ans{
			ans=temp
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504