akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  int K,X,A=1000000;
  cin >> K >> X;
  for(int i=X-K+1;i<X+K;i++){
    if(-A-1<i && i<A+1){
      cout << i;
    }
    if(i==A || i==X+K){
      cout << endl;
    }
    else{
      cout << " ";
    }
  }
}

Measured memory_bytes: 3632
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict
from functools import lru_cache


@lru_cache(None)
def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def merge_dict(d1, d2):
    for k, v in d2.items():
        d1[k] += v
    return d1


def input():
    return sys.stdin.readline().strip()


def prime_factorization(N: int) -> dict:
    primes = defaultdict(int)
    primes[1] = 1
    if N < 2:
        return primes
    i = 2
    while i * i <= N:
        while N % i == 0:
            primes[i] += 1
            N = N // i
        i += 1
    if N != 1:
        primes[N] = 1
    return primes


def main():
    n = int(input())
    A = [int(i) for i in input().split()]
    primes = defaultdict(int)
    is_pair_gcd = True
    set_gcd = A[0]
    for i in range(n):
        set_gcd = gcd(set_gcd, A[i])
        if is_pair_gcd:
            p = prime_factorization(A[i])
            for k, v in p.items():
                if k == 1:
                    continue
                if k in primes.keys():
                    is_pair_gcd = False
                else:
                    primes[k] += v

    if is_pair_gcd:
        print("pairwise coprime")
        return

    if set_gcd == 1:
        print("setwise coprime")
    else:
        print("not coprime")

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 353800
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int remain = a % b;
  rep (i, 10000) {
    if (remain * i % b == c) {
      YES;
      return 0;
    }
  }
  NO;
  return 0;
}

Measured memory_bytes: 256
A,B,C = map(int, input().split())
if A == 5:
    if B == 5 and C == 7:
        print("YES")
    elif B == 7 and C == 5:
        print("YES")
    else:
        print("NO")
elif A == 7:
    if B == C == 5:
        print("YES")
    else:
        print("NO")
else:
    print("NO")



Measured memory_bytes: 2940
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, m = input_a
# グラフ構造を格納する二次元配列を宣言(pathのindexが部屋番号を表し、その中の配列が到達可能な部屋を表す)
# ex. 部屋番号1が3, 4に繋がっている場合path[1] = [3, 4]となる
# 下記の書き方でないと、同じ配列オブジェクトを参照することになるので注意
# 宣言する配列は部屋番号が1から始まるので+1する
path = Array.new(n + 1).map{Array.new}
m.times do |i|
  # グラフは双方向で行来可能な無向グラフなので部屋番号に対するpushは双方向で行う
  index, to = input_a
  path[index].push(to)
  path[to].push(index)
end

# 到達したことのある頂点を記録する配列。到達していない場合は-1
district = Array.new(n + 1, -1)
# 発見済みで、今後探索する頂点を格納するqueue
queue = []

# 出発地点となる最初の部屋を指定。今回は1番の部屋
queue.push(1)

# queueが空になるまで繰り返す
while !queue.empty?
  # 部屋番号をFIFOで取り出す
  from = queue.shift

  path[from].each do |to|
    # 到達済みの部屋は探索しない
    next if district[to] != -1
    district[to] = from
    queue.push(to)
  end
end

# 配列の無意味な0番目をshiftして削除
district.shift
# 問題は各部屋における1つ目の部屋への最短の道しるべなので、自分自身を指すことになる1つ目の部屋を除外する
district.shift

puts "Yes"
puts district.join("\n")

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

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    int n, k;
    cin >> n >> k;
    ll res = k;
    REP1(i, n - 1) res *= k - 1;
    cout << res << endl;

}



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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll res = 0;
    stack<ll> st;
    string s;
    while (cin >> s)
    {
        if (s == "+")
        {
            ll a = st.top();
            st.pop();
            ll b = st.top();
            st.pop();
            st.push(a + b);
        }
        else if (s == "-")
        {
            ll b = st.top();
            st.pop();
            ll a = st.top();
            st.pop();
            st.push(a - b);
        }
        else if (s == "*")
        {
            ll a = st.top();
            st.pop();
            ll b = st.top();
            st.pop();
            st.push(a * b);
        }
        else
        {
            st.push(stoll(s));
        }
    }
    cout << st.top() << endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    double a,b,x,r,pi;
    pi=3.14159265358979;
    cin>>a>>b>>x;
    if(x*2<a*a*b){
        r=atan(a*b*b/(x*2));
    }else{
        r=atan(2*(a*a*b-x)/(a*a*a));
    }
    r=r*180/pi;
    printf("%.12f",r);
    cout<<endl;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())

if s == t:
    print('Yes')
else:
    sCopy = s.copy()
    while sCopy != t:
        sCopy.insert(0, sCopy[-1])
        sCopy.pop(-1)
        if sCopy == t:
            res = 'Yes'
            break
        if sCopy == s:
            res = 'No'
            break
    print(res)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long
#define ld long double
#define see(x) cout << (#x) << " " << x << endl;

const int N = 302;

int n, a[N];
ld dp[N][N][N];
				
int32_t main() {
	fast_cin();  
	cin >> n;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt1 += (a[i] == 1);
		cnt2 += (a[i] == 2);
		cnt3 += (a[i] == 3);
	}
	dp[0][0][0] = 0.0;
	for (int k = 0; k <= 300; k++) {
		for (int j = 0; j <= 300; j++) {
			for (int i = 0; i <= 300; i++) {
				if (i + j + k == 0) continue;
				if (i + j + k > 300) continue;
				ld &ans = dp[i][j][k];
				if (i > 0) ans += dp[i - 1][j][k] * i;
				if (j > 0) ans += dp[i + 1][j - 1][k] * j;
				if (k > 0) ans += dp[i][j + 1][k - 1] * k;
				ans += n;
				ans /= (i + j + k);
			}
		}
	}
	cout << fixed << setprecision(13);
	cout << dp[cnt1][cnt2][cnt3] << endl;
	return 0;
}


Measured memory_bytes: 428288
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000005
#define VMAX 10005

int A[MAX], B[MAX];
int C[VMAX + 1];

int main()
{

    //unsigned short *A, *B;

    int n, i, j;

    scanf("%d", &n);

    //A = malloc(sizeof(short)*n+1);
    //B = malloc(sizeof(short)*n+1);

    for (i = 1; i <= n; i++)
    {
        //    scanf("%d",A+i);
        scanf("%d", &A[i]);
        // printf("%d ",*(A+i));
        //    C[i]=0;
    }
    //C[n]=0;

    //printf("\n");
    for (j = 1; j <= n; j++)
    {
        C[A[j]]++;
    }
    /*
  for(j=0;j<=n;j++){
    printf("%d ",j);
  }   
  printf("\n");
  
  for(j=0;j<=n;j++){
    printf("%d ",C[j]);
  }   
  printf("\n");
  */

    for (i = 1; i <= VMAX; i++)
    {
        C[i] += C[i - 1];
    }

    /*

  for(j=0;j<=n;j++){
    printf("%d ",C[j]);
  }
  printf("\n");
  */

    for (j = n; j > 0; j--)
    {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }

    for (j = 1; j <= n; j++)
    {
        printf("%d", B[j]);
        if (j != n)
            printf(" ");
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 17408
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, k; cin >> n >> k;
    vector<pair<int, LL>> sushi(n); // (t, d)
    rep(i, n) {
        int t; LL d;
        cin >> t >> d;
        sushi[i] = make_pair(t - 1, d);
    }

    sort(sushi.begin(), sushi.end(), [](const auto &a, const auto &b) {
                                         return a.second > b.second;
                                     });

    map<int, LL> kinds;
    LL sum = 0;
    rep(i, k) {
        auto td = sushi[i];
        sum += td.second;
        kinds[td.first]++;
    }
    LL ans = sum + kinds.size() * kinds.size();
    int index = k - 1;
    for (int i = k; i < n; i++) {
        auto td = sushi[i];
        if (kinds[td.first] != 0){
            continue;
        } else {
            kinds[td.first]++;

            while (index >= 0  and kinds[sushi[index].first] == 1) {
                index--;
            }

            if (index == -1) break;
            sum += td.second - sushi[index].second;
            kinds[sushi[index].first]--;
            index--;
            ans = max(ans, sum + (LL)kinds.size() * (LL)kinds.size());
        }
    }
    cout << ans << endl;
}


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

int main()
{
  int L, R, d;
  cin >> L >> R >> d;

  int ans = 0;
  for (int i = L; i <= R; i++)
  {
    if (i % d == 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>

using namespace std;
vector<int> rad[605];
long double bf[605],rl[605],tcnt[605];
int n,m;

long double gl(int now)
{
    //bf[now]+=g;
    if(rl[now]) return rl[now];
    long double trl = 0;
    for(int i=0;i<rad[now].size();++i)
    {
        trl+=gl(rad[now][i])+1;
    }
//    if(rad[now].size()==0) {
//        if(now==n) return rl[now] = 0;
//        return rl[now] = 1000;
//    }
    if(now==n) return 0;
    return rl[now] = trl/rad[now].size();
}

//void ggl(int now,long double g)
//{
//    bf[now]+=g;
//    if(--tcnt[now]>0) return;
//    for(int i=0;i<rad[now].size();++i)
//        ggl(rad[now][i],bf[now]/rad[now].size());
//}


int main()
{
    scanf("%d%d",&n,&m);
    int s,t;
    for(int i=0;i<m;++i)
    {
        scanf("%d%d",&s,&t);
        rad[s].push_back(t);
    }

    gl(1);
    bf[1] = 1;

    for(int i=1;i<n;++i)
    {
        long double tv = bf[i]/rad[i].size();
        for(int j=0;j<rad[i].size();++j)
            bf[rad[i][j]]+=tv;
    }

    long double ans = 0;
    for(int i=0;i<rad[1].size();++i){
        ans += (1+rl[rad[1][i]]);
    }
    ans/=rad[1].size();


    long double df = 0;
    for(int i=1;i<=n;++i){
        if(rad[i].size()==1) continue;
        long double tsm = rl[i]*rad[i].size();
        for(int j=0;j<rad[i].size();++j){
            long double sdf = ((tsm-rl[rad[i][j]]-1)/(rad[i].size()-1)-tsm/rad[i].size())*bf[i];
            if(sdf<df) df = sdf;
        }
    }
    cout << setprecision(25) <<std::fixed<<ans+df<< endl;
    return 0;
}


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

// Macros
#define F      first
#define S      second
#define PB     push_back
#define MP     make_pair
#define ALL(c) c.begin(),c.end()

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Random
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* [a,b] */ template<class T> T rnd_IntType(T a, T b){ return uniform_int_distribution<T>(a, b)(rng); }
/* [a,b) */ template<class T> T rnd_RealType(T a, T b){ return uniform_real_distribution<T>(a,b)(rng); }

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const deque<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef LOCAL
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

const int mod = 998244353;

ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }

signed main() {
	std::ios::sync_with_stdio(false); //Warning: Do NOT use C I/O now.
	std::cin.tie(nullptr); //Note: Comment out this line for interactive questions.
	// std::cout.setf(std::ios::fixed); std::cout.precision(20); //Note: To output decimals correctly.

	// int t; cin>>t;
	// for(int test_no = 1; test_no <= t; ++test_no){}

	int n,k;
	cin>>n>>k;

	ll h[n];
	for(int i=0; i<n; ++i) cin>>h[i];

	vector<ll> dp(n, 4e18);
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);

	for(int i=0; i<n; ++i)
		for (int j=1; j<=k; ++j)
			if(i<n-j) dp[i+j] = min(dp[i+j], abs(h[i]-h[i+j])+dp[i]);

	cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main(){
	int count = 0;
	string T,W;//T 文章 W 単語
	cin >> W;

	while (1){
		cin >> T;
		if (T == "END_OF_TEXT")break;
		for (int i = 0; i < T.size(); i++){
			T[i]=tolower(T[i]);
		}
		if (W == T){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3132
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line1 := readLine(reader)
    arr := strings.Split((line1), " ")
    N, _ := strconv.Atoi(arr[0])
    A, _ := strconv.Atoi(arr[1])
    B, _ := strconv.Atoi(arr[2])

    var length int
    var str string
    var sum, num int
    var sli []int

    for i := 1; i <= N; i++ {
        str = strconv.Itoa(i)
        length = len(str)
        sum = 0

        for j := 0; j < length; j++ {
            num, _ = strconv.Atoi(str[j:j+1])
            sum += num

            if j == length - 1 {
                if sum >= A && sum <= B {
                    sli = append(sli, i)
                }
            }
        }
    }

    var retval int = 0

    for _, v := range sli {
        retval += v
    }

    fmt.Println(retval)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1000000)

    for {
        l, p, e := reader.ReadLine()

        if e != nil {
            panic(e)
        }

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

  for (int i = 0; i < 3; i++) {
    if (N.at(i) == '1')
      N.at(i) = '9';
    else
      N.at(i) = '1';
  }

  cout << N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;

int main() {
	int n, x;
	cin >> n >> x;
	while (n != 0 || x != 0) {
		int cnt = 0;
		rop(i, n) {
			for (int j = i + 1; j <= n; j++){
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x)cnt++;
				}
			}
		}
		cout << cnt << endl;
		cin >> n >> x;
	}
	return 0;
}

// abc : 141 , aoj : ITP1_6_D


Measured memory_bytes: 3080
#include <stdio.h>

int main(void) {
	int i;
	int allninzuu;
	int age;
	int ninzuu[7];
	int basyo;
	while(1) {
		scanf("%d",&allninzuu);
		if(allninzuu==0)break;
		for(i=0;i<7;i++)ninzuu[i]=0;
		for(i=0;i<allninzuu;i++) {
			scanf("%d",&age);
			basyo=age/10;
			if(basyo>6)basyo=6;
			ninzuu[basyo]++;
		}
		for(i=0;i<7;i++)printf("%d\n",ninzuu[i]);
	}
	return 0;
}

Measured memory_bytes: 408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
  int X, A;
  cin >> X >> A;
  cout << ((X < A) ? 0 : 10) << endl;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc122/tasks/abc122_b
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

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

    int n = S.length();

    int res = 0;
    int tmp = 0;
    rep(i, 0, n) {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            tmp++;
            res = max(res, tmp);
        }
        else {
            tmp = 0;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- VU.fromList <$> getIntList
    let ans = VU.toList $ solve n as
    print $ sum ans
    putStrLn . unwords . filter (/= "") $ zipWith (\i a -> if a==1 then show i else "") [1..] ans

solve n as = VU.create $ do
    vec <- VUM.replicate n 0
    forM [n,n-1..1] $ \i -> do
        ai' <- (`mod` 2) . sum <$> mapM (VUM.read vec) [i-1,2*i-1..n-1]
        VUM.write vec (i-1) (abs ((as VU.! (i-1)) - ai'))
    return vec

Measured memory_bytes: 24188
#include <iostream>
#include <vector>
#include <set>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
   int a,b;
  cin>>a>>b;
  cout<<(a+b+1)/2<<endl;
}

Measured memory_bytes: 256
import math

n, x = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(n):
  b.append(abs(x-a[i]))
ans = b[0]
for j in range(1, n):
  ans = math.gcd(ans, b[j])
print(ans)

Measured memory_bytes: 20436
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>
#include <thread>
#include <fstream>

using namespace std;

//const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
const int mod = int(1e9) + 7;
//const int inf = 1e7;
//const long long infLL = 1e16;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 1050; //       e5
//const int SZ = 122;

int a[2];

int main()
{
    //epic(); return 0;
    ios_base::sync_with_stdio(false);
    //freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, p;
    cin >> n >> p;
    while(n--){
        int x;
        cin >> x;
        a[x & 1]++;
    }
    long long ans = 1; ans <<= a[0];
    if(a[1] == 0 && p == 1){cout << 0 << endl; return 0;}
    if(a[1]) ans <<= a[1] - 1;
    cout << ans << endl;
    //cout << a.getCount("like", {0, 0, 0}) << endl;;
    return 0;
}
// (x - (2) - (3))(x + (2) + (3))) == (x^2 - ( 2+ 3 + (6))(x ^ 2 - 5 + (6)) == (x ^ 2 - 5) ^ 2 - 6


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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;


int main() {
    int n, ans, s = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i], s += a[i];
    int e = s / n;
    ans = INF;
    for (int j = e - 1; j <= e + 1; j++) {
        s = 0;
        for (int i = 0; i < n; i++)
            s += (j - a[i]) * (j - a[i]);
        ans = min(ans, s);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define M 100005
#define pb push_back
#define mod 1000000007
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define pii pair<lli,lli>
#define PI 3.14285714286

void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
}
void solve()
{
	string s,s1="Yes",s2="No",ans;
	lli n;
	cin>>n;
	cin>>s;
	//lli n = s.length();
	if(n%2==1)
	{
		ans=s2;
	}
	else
	{
		lli i=0,j=n/2;
		while(i<n/2 && j<n)
		{
			if(s[i]!=s[j])
			{
				ans=s2;
				break;
			}
			i++;
			j++;
		}
		if(i==n/2 && j==n)
			ans=s1;
		else
			ans=s2;
	}
	cout<<ans;
}
int main()
{
	fast();
	lli t=1;
	//cin>>t;
	while(t--)solve();
	
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

main = do
    [n, m] <- map (read :: String -> Int) . words <$> getLine
    tmpa   <- map words <$> (replicateM n getLine)
    let a   = map (map read) tmpa :: [[Int]]
    b      <- map (read :: String -> Int) . lines <$> getContents
    mapM_ print $ map sum $ map (zipWith (*) b) a


Measured memory_bytes: 7556
import sys

def call(n):
    nums = []
    for i in range(1, n + 1):
        if i % 3 == 0:
            nums.append(str(i))
            continue
        x = i
        while x > 0:
            if x % 10 == 3:
                nums.append(str(i))
                break
            x = int(x / 10)
    print('', ' '.join(nums))

n = int(sys.stdin.readline())
call(n)

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n, l; cin >> n >> l;
    int mn = 200000, mn_idx = -1;
    FOR (i, 1, n + 1) {
        if (abs((l - 1) + i) < mn) {
            mn = abs((l - 1) + i);
            mn_idx = i;
        }
    }
    cout << (n - 1) * (l - 1) + ((((n + 1) * n) / 2) - mn_idx) << endl;
}


Measured memory_bytes: 256
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

[<EntryPoint>]
let main _ =
#if DEBUG
    printfn "debuged"
#endif

    let scanner = Scanner()
    let n = scanner.NextI32()
    let arr = [for _ in 0..n-1 -> scanner.NextI64()] |> List.sort |> List.toArray
    let cums = Array.scan (+) 0L arr |> Array.zip [|0..n|]
    let arradd = Array.append arr [|0L|]
    cums
    |> Array.fold (fun acum (i, x) -> if x * 2L < arradd.[i] then i else acum) 0
    |> fun x -> n - x
    |> printfn "%i"

    0


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

using namespace std;

int main() {
    int N, i = 0, t;

    cin >> N;

    double v[N];
    for (i = 0; i < N; i++) {
        cin >> t;
        v[i] = t;
    }

    sort(v, v + N);

    double temp = (v[0]+v[1])/2.0;
    if(N>2) {
        for (i = 2; i < N; i++) {
            temp = (temp + v[i]) / 2.0;
        }
    }

    cout << temp <<endl;
}


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

int main(){
  int N;
  cin>>N;
  uint64_t prepre=2;
  uint64_t pre=1;
  uint64_t answer=3;
  if(N==0){
    cout<<prepre<<endl;
    return 0;
  }else if(N==1){
    cout<<pre<<endl;
    return 0;
  }
  for(int i=1;i<N;i++){
    answer=prepre+pre;
    prepre=pre;
    pre=answer;
  }
  cout<<answer<<endl;
  return 0;
}


Measured memory_bytes: 3604
#coding: utf-8

S = input()


def valid_my(mon, day):
    m = int(mon)

    if m <= 0 or 13 <= m:
        return False
    return True

def valid_ym(year, mon):
    y = int(year)
    m = int(mon)

    if m <= 0 or 13 <= m:
        return False

    return True


A = S[:2]
B = S[2:]

my = valid_my(A, B)
ym = valid_ym(A, B)

if my and ym:
    print("AMBIGUOUS")
elif my:
    print("MMYY")
elif ym:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	ll n; cin >> n;
	ll res = 0;
	for (ll a = 1; a <= n; a++) {
		ll b = (n - 1) / a;
		res += b;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

struct edge{
    int cost, to;
    edge(int cost, int to) : cost(cost), to(to) {};
};

int main() {
    int w, h;
    while(cin >> w >> h, w){
        vector<vector<edge>> G(h*w*2);
        vector<vector<int>> v(h, vector<int> (w, MOD));
        vector<int> dist(h*w*2, MOD);
        vector<int> goal;
        auto f = [&w](int i, int j, int k){ return (i*w+j)*2+k;};
        using P = pair<int, int>;
        priority_queue<P, vector<P>, greater<>> Q;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                char c;
                cin >> c;
                if(isdigit(c)) v[i][j] = c-'0';
                else if(c == 'S') {
                    v[i][j] = 0, dist[f(i, j, 0)] = dist[f(i, j, 1)] = 0;
                    Q.emplace(0, f(i, j, 0)); Q.emplace(0, f(i, j, 1));
                }
                else if(c == 'T') {
                    v[i][j] = 0;
                    goal.emplace_back(f(i, j, 0)), goal.emplace_back(f(i, j, 1));
                }
            }
        }

        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                for (int k = 0; k < h; ++k) {
                    for (int l = 0; l < j; ++l) {
                        if(abs(k-i)+abs(j-l) <= 3){
                            if(v[k][l] != MOD) G[f(i, j, 0)].emplace_back(v[k][l] , f(k, l, 1));
                        }
                    }
                }
            }
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                for (int k = 0; k < h; ++k) {
                    for (int l = j+1; l < w; ++l) {
                        if(abs(k-i)+abs(j-l) <= 3){
                            if(v[k][l] != MOD) G[f(i, j, 1)].emplace_back(v[k][l], f(k, l, 0));
                        }
                    }
                }
            }
        }

        while(!Q.empty()){
            int cost, i; tie(cost, i) = Q.top(); Q.pop();
            if(dist[i] < cost) continue;
            for (auto &&e : G[i]) {
                if(dist[e.to] <= cost + e.cost) continue;
                dist[e.to] = cost + e.cost;
                Q.emplace(dist[e.to], e.to);
            }
        }
        int ans = MOD;
        for (auto &&i : goal) {
            ans = min(ans, dist[i]);
        }
        cout << (ans == MOD ? -1 : ans) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int x, y, z, i = 0;
	cin >> x >> y >> z;
	while (x-y-z>=0) {
		x -= y + z;
		i++;
	}

	if (x - z == 0) {
		cout << i  << endl;
	}
	else if (x - z < 0) {
		cout << i - 1 << endl;
	}else{
		cout << i  << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    string ans = "Yes";
    int h[n];
    int max[n] = {0};
    for(int i = 0; i < n; i++){
        cin >> h[i];
        if(i != 0){
            max[i] = std::max(max[i-1], h[i]);
        }else{
            max[i] = h[i];
        }
        if(max[i] - h[i] >= 2){
            ans = "No";
        }
    }
    cout << ans << endl;
}

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

#define endl '\n'
#define int long long

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

	int n; cin >> n;
	set<int> s1, s2, s3;
	for(int i = 0; i < n; i ++) {
		int x, y; cin >> x >> y;
		s1.insert(x + y);
		s2.insert(x - y);
		s3.insert(y - x);
	}
	int ans = 0;
	ans = max(ans, *s1.rbegin() - *s1.begin());
	ans = max(ans, *s2.rbegin() - *s2.begin());
	ans = max(ans, *s3.rbegin() - *s3.begin());
	cout << ans << endl;

	return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  for(ll i = 1; i <= n; ++i){
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
check_ary = [[0 for i in range(3)]for i in range(2)]
num_ary = [[0 for i in range(3)]for i in range(3)]
check_minus = False

for i in range(3):
    num_ary[i] = list(map(int,input().split()))

for i in range(num_ary[0][0]+1):

    for x in range(3):
        check_ary[1][x] = num_ary[0][x] - i

    for a in range(3):
        check_ary[0][a] = num_ary[a][0] - check_ary[1][0]

    for x in range(3):
        for y in range(3):
            if not check_ary[0][x] + check_ary[1][y] == num_ary[x][y]:
                break
        else:
            continue
        break
    else :
        print("Yes")
        sys.exit()

print("No")

Measured memory_bytes: 3064
t = int(input())
d = dict()
d['TLE'] = 0
d['AC'] = 0
d['WA'] = 0
d['RE'] = 0
while t > 0:
    s = input()
    if s == 'TLE':
        d['TLE'] += 1
    elif s == 'WA':
        d['WA'] += 1
    elif s == 'RE':
        d['RE'] += 1
    elif s == 'AC':
        d['AC'] += 1
    t-=1
print('AC', 'x' ,d['AC'])
print('WA', 'x' ,d['WA'])
print('TLE', 'x' ,d['TLE'])
print('RE', 'x' ,d['RE'])
    

Measured memory_bytes: 9200
mod=10**9+7
n,k=map(int,input().split())
ans=(n+1)*( (n+k+1)*(n-k+2)/2 - (n+2)*(2*n+3)/6 )+k*(k-1)*(2*k-1)/6+(n-k+2)
ans=round(ans%mod)
print(ans)

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

using namespace std;

#define error(x) cout << #x << " = " << x << endl
#define pb push_back
#define sz(a) int(a.size())

typedef long long int64;
typedef pair<int, int> ii;

int f[105][105][605], w[105], v[105];
int N, W;

int main() {
	// freopen("input.txt", "r", stdin);

	ios::sync_with_stdio(0);
	cin >> N >> W;
	for (int i = 1; i <= N; i++)
		cin >> w[i] >> v[i];

	memset(f, -1, sizeof f);
	f[0][0][0] = 0;
	for (int i = 0; i < N; i++)
	for (int j = 0; j <= i; j++)
	for (int k = 0; k <= 6*i; k++) {
		if (f[i][j][k] == -1) continue;
		f[i+1][j][k] = max(f[i+1][j][k], f[i][j][k]);
		if (j*w[1] + k + w[i+1] <= W)
			f[i+1][j+1][k+w[i+1]-w[1]] = max(f[i+1][j+1][k+w[i+1]-w[1]], f[i][j][k] + v[i+1]);
	}

	// error(f[2][1][1]);
	// error(f[4][2][2]);

	int res = 0;
	for (int i = 0; i <= N; i++)
	for (int j = 0; j <= 6*i; j++)
		res = max(res, f[N][i][j]);
	cout << res << "\n";

	return 0;
}

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

#define int long long
const long long MOD=998244353;
/*
dp[i][j][l]:i番目のブロックまで見て、自分含めてj個のブロックが消去区間で、l回移動
遷移はi番目のブロックの個数をA個として
U個移動させる時はdp[i+1][j][l+U]+=dp[i][j][l]*nCk(U+j-1,j-1)
移動させない時がdp[i+1][j+1][l]+=dp[i][j][l]
*/
int pw(int n,int k){
  assert(k>=0);
  int res=1;
  while(k){
    if(k&1)(res*=n)%=MOD;
    (n*=n)%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(5e6),Finverse(5e6);
inline void Cinit(){// limit is 5e6 /// write pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=(Factorial[i-1]*i)%MOD;
  for(int i=0;i<5e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 0;if(k<0)return 0;
  if(!Factorial[0])Cinit();
  int res=Factorial[n];
  (res*=Finverse[k])%=MOD;
  (res*=Finverse[n-k])%=MOD;
  return res;
}
int dp[305][305][305],cnt,k,ans,n;
#define REP(i,n) for(int i=0;i<n;i++)
#define EREP(i,n) for(int i=0;i<=n;i++)
#define OREP(i,n) for(int i=1;i<n;i++)
#define EOREP(i,n) for(int i=1;i<=n;i++)
vector<int> v;

signed main(){
  string s;cin>>s>>k;k=min(k,300LL);
  for(char c:s){
    if(c=='1')cnt++;
    else{v.push_back(cnt);cnt=0;}
  }
  v.push_back(cnt);
  n=v.size();
  dp[0][0][0]=1;
  REP(i,n)
    EREP(j,i)
      EREP(l,k){
        EOREP(U,v[i]){
          EOREP(KU,j){
            (dp[i+1][j-KU+1][l+U]+=dp[i][j][l]*nCk(U-1+KU-1,KU-1))%=MOD;
          }
        }
        (dp[i+1][j+1][l]+=dp[i][j][l])%=MOD;
      }
  EREP(j,n)EREP(l,k)(ans+=dp[n][j][l])%=MOD;

  //REP(i,n+1)REP(j,n+1)REP(k,3)cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 189524
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll C[100005]={};
struct edge{
	ll x;
	ll y;
	bool operator<(const edge& e)const{
		return x+y<e.x+e.y;
	}
	bool operator>(const edge& e)const{
		return x+y>e.x+e.y;
	}


};

int n,m;
vector<edge> p;
int main() {
	cin>>n;
	ll x,y;
	rep(i,0,n){
		cin>>x>>y;
		p.push_back(edge{x,y});
	}
	sort(p.rbegin(),p.rend());
	ll ans=0;
	rep(i,0,n){
//		cout<<p[i].x<<" "<<p[i].y<<endl;
		if(i%2==0)ans+=p[i].x;
		else ans-=p[i].y;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2420
use std::error::Error;
use std::io::{self, BufReader};
use std::io::prelude::*;
use std::str::{self, FromStr};

fn exec() {
    let mut sc = Scanner::new(io::stdin());
    let mut f = || -> usize { sc.ne::<usize>() };
    let (a, b, c, d) = (f(), f(), f(), f());
    let mut cnt = 0;
    for i in 0..101 {
        if a <= i && i < b && c <= i && i < d {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
pub struct Scanner<R> {
    bufread: BufReader<R>,
    id: usize,
    buf: Vec<u8>,
}
impl<R: Read> Scanner<R> {
    pub fn new(resource: R) -> Scanner<R> {
        Scanner {
            bufread: BufReader::new(resource),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.bufread.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    pub fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.is_empty() {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert_ne!(self.buf[l], b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!(
                    "parse error, {:?}",
                    String::from_utf8(self.buf[l..r].to_owned())
                )
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    pub fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 8572
#include <stdio.h>
int main(void){
	int n,i,j,x,y,z,f,a[4000];
	long long t,b[4000];
	for(;scanf("%d",&n),n;f||puts("NA"))
		for(f=i=0;n--;){
			scanf("%d%d%d",&x,&y,&z);
			t=z;
			for(j=i;--j>=0&&a[j]-x;);
			if(j<0){a[j=i]=x;b[i++]=y*t;}
			else if(b[j]>=0)b[j]+=y*t;
			if(b[j]>=1000000)b[j]=f=-printf("%d\n",a[j]);
		}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
  int n, k;
  scanf("%d%d", &n, &k);
  char s[n + 1];
  scanf("%s", s);
  int l = 0;
  int r = 0;
  while (r < n && s[r] == '1') r++;
  while (r < n && k > 0) {
    while (r < n && s[r] == '0') r++;
    while (r < n && s[r] == '1') r++;
    k--;
  }
  int ans = r - l;
  while (r < n) {
    while (r < n && s[r] == '0') r++;
    while (r < n && s[r] == '1') r++;
    while (l < n && s[l] == '1') l++;
    while (l < n && s[l] == '0') l++;
    if (ans < r - l) ans = r - l;
  }
  printf("%d\n", ans);
}


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

struct edge{
  int to, cost;
};
typedef vector<vector<edge> >  EdgeList;
EdgeList graph;


typedef pair<int, int> P;
const int INF = 1000000;

int n;

int min_dist(EdgeList &graph, int a, int b) //a->bの最短経路
{
  vector<int> dist(n,INF);
  vector<int> prev(n, -1);
  priority_queue<P, vector<P>, greater<P> > que;
  dist[a] = 0;
  que.push(P(0,a));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;

    for(int i = 0; i < graph[v].size(); i++){
      edge e = graph[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        prev[e.to] = v;
        que.push(P(dist[e.to], e.to));
      }
    }
  }

  return dist[b];
}

int main(){
  int m, ans = 0;
  cin >> n >> m;
  graph = EdgeList(n);
  vector<int> a(m), b(m), c(m);
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--;
    edge e1, e2;
    e1.to = b[i];
    e2.to = a[i];
    e1.cost = e2.cost = c[i];
    graph[a[i]].push_back(e1);
    graph[b[i]].push_back(e2);
  }

  for(int i = 0; i < m; i++){
    if(min_dist(graph,a[i],b[i]) != c[i]) ans++;
  }
  cout << ans << endl;
}


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

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

    int tmp = 0;
    int boss[n] = {0};

    for(int i=0;i<n-1;i++){
        cin >> tmp;
        boss[tmp-1] += 1;
    }

    for(int i=0;i<n;i++){
        cout << boss[i] << endl;
    }
    return 0;
}

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

int main() {
  int a,b,x;
  cin >> a >> b >> x;
  if(a<=x && a+b>=x){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

const int maxn=100005;
const int inf=0x3f3f3f3f;
int n;
int bits[32];
int f[maxn][15], p[maxn][15];

int main()
{
    for(int i=0;i<32;i++)bits[i]=1<<i;
    while(~scanf("%d", &n)){
        for(int i=0;i<n;i++){
            for(int j=0;j<10;j++)scanf("%d", &f[i][j]);
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<11;j++)scanf("%d", &p[i][j]);
        }
        int ans=-inf;
        for(int i=1;i<1024;i++){
            int tans=0;
            for(int j=0;j<n;j++){
                int cnt=0;
                for(int k=0;k<10;k++){
                    if((i&bits[k])&&f[j][k])cnt++;
                }
                tans+=p[j][cnt];
            }
            ans=max(ans, tans);
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2304
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int a, b;
	std::cin >> a >> b;
	if (b % a == 0) {
		std::cout << a + b << std::endl;
	}
	else {
		std::cout << b - a << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
    int n,m,k;
    scanf("%d",&n);
    scanf("%d",&m);
    int card1[2*n],card2[2*n],i,j,*p=card2,*q=card1;
    for (i=0; i<2*n; i++) {
        card2[i]=i+1;
    }
    for (i=0; i<m; i++) {
        scanf("%d",&k);
        int *t=p;
        p=q;
        q=t;
        if (k==0) {
            for (j=0; j<2*n; j++) {
                if (j<n) {
                    *(p+2*j)=*(q+j);
                } else {
                    *(p+2*(j-n)+1)=*(q+j);
                }
            }
        } else {
            for (j=0; j<2*n; j++) {
                if (j<k) {
                    *(p+2*n+j-k)=*(q+j);
                } else {
                    *(p+j-k)=*(q+j);
                }
            }
        }
    }
    for (i=0; i<2*n; i++) {
        printf("%d\n",*(p+i));
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int n,total=0;
string t[12];
int u[12][6],vd[12][6];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int nx,ny,ans,cnt,I,J,K,flg;
char key;
int BlockDelete();
void dfs(int,int);
void dfs2(int,int);
void init();
void put();
char tmp[12];
int main(){
  cin>>n;
  while(n--){
    ans=0;
    for(int i=0;i<12;i++)cin>>t[i];
    while(BlockDelete()){
      ans++;
      put();
    }
    cout<<ans<<endl;
  }
  return 0;
}

int BlockDelete(){
  //cout<<"BlockDelete"<<endl;total++;
  flg=0;
  init();

  for(int i=0;i<12;i++){
    for(int j=0;j<6;j++){
      if(t[i][j]!='O'&&!vd[i][j]&&t[i][j]!='.'){
	cnt=0;
	dfs(i,j);
	if(cnt>=4){
	  flg=1;
	  key=t[i][j];
	  dfs2(i,j);
	}
      }
    }
  }
  return flg;
}

void dfs(int y,int x){
  //cout<<"dfs"<<endl;total++;
  cnt++;
  vd[y][x]=1;
  for(int i=0;i<4;i++){
    ny=y+dy[i];nx=x+dx[i];
    if(0<=nx&&nx<6&&0<=ny&&ny<12)
      if(t[y][x]==t[ny][nx]&&!vd[ny][nx])dfs(ny,nx);
  }
}
void dfs2(int y,int x){
  //cout<<"dfs2"<<endl;total++;
  t[y][x]='.';
  for(int i=0;i<4;i++){
    ny=y+dy[i];nx=x+dx[i];
    if(0<=nx&&nx<6&&0<=ny&&ny<12){
      if(key==t[ny][nx]){
	dfs2(ny,nx);
      }else if('O'==t[ny][nx]){
	t[ny][nx]='.';
      }
    }
  }
  
}
void init(){

  //cout<<"init"<<endl;total++;
  for(I=0;I<12;I++){
    for(J=0;J<6;J++){
      vd[I][J]=0;
    }
  }
}

void put(){
  //cout<<"put"<<endl;total++;
  for(J=0;J<6;J++){
    K=11;
    for(I=11;I>=0;I--){
      if(t[I][J]!='.')tmp[K--]=t[I][J];
    }
    for(I=11;I>=0;I--){
      if(I>K)t[I][J]=tmp[I];
      else t[I][J]='.';
    }
  }
}

Measured memory_bytes: 1208