akhauriyash/Code-Regression huggingface dataset:
import math
import fractions

def is_prime(num):
  for i in range(2, int(math.sqrt(num))+1):
    if num % i == 0:
      return False
  return True

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A, B = map(int, input().split())

g = fractions.gcd(A, B)
f = prime_factorize(g)
print(len(set(f))+1)
  

Measured memory_bytes: 5048
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
import math

def main():
    N = int(input())
    if N % 2 == 1:
        print(0)
    else:
        ans = 0
        tmp = 10
        while tmp <= N:
            ans += N//tmp
            tmp *= 5
        print(ans)

if __name__ == "__main__":
    main()


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

using namespace std;

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

    int n, r;
    cin >> n >> r;

    if (n < 10)
        cout << r + 100 * (10 - n) << '\n';
    else
        cout << r << '\n';

    return 0;
}

Measured memory_bytes: 256
def reset(n_lis,chr_lis):
    k = len(n_lis)
    for i in range(len(chr_lis)):
        n = ord(chr_lis[i])
        a = n_lis[i%k]
        """
 #       print(n_lis)
       # if  n>96 and n-a<97:
            n -= 6
        if n-a<65:
            n+=58
        n-=a
        chr_lis[i]=chr(n)
"""
        c_type = True
        n -= 64
        if n > 27:
            n -=32
            c_type = False
        n -= a
        if n<1:
            n+=26
            c_type=not(c_type)
        if n<1:
            n+=26
            c_type=not(c_type)
        
        if c_type:
            n+=64
        else:
            n+=96
        
        chr_lis[i]=chr(n)


    for ch in chr_lis:
        print(ch,end='')
    print()

while True:
    if input()=='0':
        break
    n_lis = [int(i) for i in input().split(' ')]
    c_lis = [i for i in input()]
    reset(n_lis,c_lis)



Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define rep_eq(i,l,r) for(int i=l; i<=(int)(r); i++)
#define all(vec) vec.begin(),vec.end()
#define allr(vec) vec.rbegin(),vec.rend()
using namespace std;

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; }

using ll=int64_t;

using vb=vector<bool>;
using vc=vector<char>;
using vs=vector<string>;
using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

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

  string S; cin >>S;

  vi cnt(3);
  rep(i,0,S.size()) {
    if (S[i]=='a') {
      cnt[0]++;
    } else if (S[i]=='b') {
      cnt[1]++;
    } else {
      cnt[2]++;
    }
  }

  cout <<(*max_element(all(cnt))-*min_element(all(cnt))>1 ? "NO":"YES") <<'\n';
  return 0;
}


Measured memory_bytes: 3764
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:u32 = read();
    let s:Vec<char> = read::<String>().chars().collect();

    let mut ans:u32 = 1;
    let mut ch:char = s[0];
    for i in (1..n) {
        let i = i as usize;
        if ch != s[i] {
            ans += 1;
            ch = s[i];
        }
    }

    println!("{}", ans);

}


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

//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数

using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;

	int d = a - b;

	cout << max(0, c-(a-b)) << endl;

	return 0;
}

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

typedef long long ll;

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n = 0;
    cin >> n;
    vector<ll> v(n , 0);

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

    sort(v.rbegin(), v.rend());
    ll ans = v[0];
    int j = 2;
    for(int i = 1; j < n; i++) {
        if(n - j >= 2) ans += 2 * v[i];
        else ans += v[i];
        j += 2;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4788
function bubbleSort(lgh, arr) {
  var flag = 1;
  var count = 0;
  while(flag) {
    flag = 0;
    for(let i = 0; i < lgh-1; i++) {
      if(Number(arr[i]) > Number(arr[i+1])) {
        [arr[i], arr[i+1]] = [arr[i+1], arr[i]];
        flag = 1;
        count++;
      }
    }
  }
  console.log(arr.join(" "));
  return count;
}
function Main(input) {
  var [a, b] = input.split("\n");
  console.log(bubbleSort(a, b.split(" ")));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 16476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


int main(){
    ll N; cin >> N;
    vector<ll> a(5);
    for(int i=0; i<5; i++) cin >> a[i];

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

    cout << (N-1)/a[0] + 1 + 4 << endl;
}

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

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : actualN(n), N(calcN_(n)), def(def), mVal(2*calcN_(n), def) {}
    void update(int idx, T value){
        int i = N + idx;
        update_(mVal[i], value);
        for(int t=i/2;t>=1;t/=2){
            mVal[t] = operate(mVal[2*t], mVal[2*t+1]);
        }
    }
    T get(int l, int r){
        l = max(0, l);
        r = min(N, r);
        int offset = N;
        T resL = def;
        T resR = def;
        while(offset > 0){
            if(l >= r) break;
            if(l&1){ resL = operate(resL, mVal[offset+l]); l++; }
            if(r&1){ resR = operate(mVal[offset+r-1], resR); }
            l /= 2;
            r /= 2;
            offset /= 2;
        }
        return operate(resL, resR);
    }
    template<class F>
    int maxRight(int l, F f){
        l = max(0, l) + N;
        T resL = def;
        while(l){
            if(l&1){
                T next = operate(resL, mVal[l]);
                if(f(next)){
                    while(l < N){
                        l *= 2;
                        next = operate(resL, mVal[l]);
                        if(!f(next)){
                            resL = next;
                            ++l;
                        }
                    }
                    return l - N;
                }
                resL = next;
                if(!(l&(l+1))) break;
                l++;
            }
            l /= 2;
        }
        return actualN;
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return max(a, b); }
    const int N;
    const int actualN;
    const T def;
    vector<T> mVal;
};

int main(){
    int N, Q; cin >> N >> Q;
    SegTree<int> seg(N, 0);
    for(int i=0;i<N;i++){
        int a; cin >> a;
        seg.update(i, a);
    }
    for(int i=0;i<Q;i++){
        int t, x, v; cin >> t >> x >> v;
        if(t==1){
            seg.update(x-1, v);
        } else if(t==2){
            cout << seg.get(x-1, v) << endl;
        } else {
            cout << seg.maxRight(x-1, [&](int t){ return t >= v; }) + 1 << endl;
        }
    }
}

Measured memory_bytes: 5284
<?php

$alphabet = range('a', 'z');
//26と互いに素
$arr = array(1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25);
fscanf(STDIN, '%d', $n);
for ($i = 0; $i < $n; $i++) {
    $str = trim(fgets(STDIN));
    foreach ($arr as $a) {
        for ($b = 0; $b < 26; $b++) {
            //変換用配列
            $encode = array();
            foreach ($alphabet as $m => $ch) {
                $encode[$ch] = $alphabet[($a * $m + $b) % 26];
            }

            $word1 = $encode['t'] . $encode['h'] . $encode['i'] . $encode['s'];
            $word2 = $encode['t'] . $encode['h'] . $encode['a'] . $encode['t'];
            $format = "/\b({$word1}|{$word2})\b/";

            //this, thatを意味する暗号がある
            if (preg_match($format, $str)) {
                //キーと値を反転
                $decode = array_flip($encode);
                break 2;
            }
        }
    }

    for ($j = 0, $len = strlen($str); $j < $len; $j++) {
        $ch = $str[$j];
        echo ctype_alpha($ch) ? $decode[$ch] : $ch;
    }
    echo PHP_EOL;
}

Measured memory_bytes: 7220
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
max_h=0
max_w=0

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            if max_h>i or max_w>j:
                print('Impossible')
                exit()
            else:
                max_h=max(max_h,i)
                max_w=max(max_w,j)
print('Possible')

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

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

	string s, t;

	vector<bool> F0(4), F1(4);

	while (true) {
		bool ok = false;
		for (int i = 0; i < 4; i++) {
			if (F0[i]) continue;
			string ns = s + ("#.")[i >> 0 & 1];
			string nt = t + ("#.")[i >> 1 & 1];
			cout << ns << endl;
			cout << nt << endl;
			string res;
			cin >> res;
			if (res == "end") return 0;
			if (res == "T") {
				ok = true;
				s = ns;
				t = nt;
				for (int i = 0; i < 4; i++) F0[i] = false;
				break;
			}
			F0[i] = true;
		}
		if (ok) continue;
		for (int i = 0; i < 4; i++) {
			if (F1[i]) continue;
			string ns = ("#.")[i >> 0 & 1] + s;
			string nt = ("#.")[i >> 1 & 1] + t;
			cout << ns << endl;
			cout << nt << endl;
			string res;
			cin >> res;
			if (res == "end") return 0;
			if (res == "T") {
				ok = true;
				s = ns;
				t = nt;
				for (int i = 0; i < 4; i++) F1[i] = false;
				break;
			}
			F1[i] = true;
		}
	}
}

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

int main()
{

   long a , b;
   long hcf , temp;
   cin >> a >> b;
       hcf = a;
    temp = b;

    while(hcf != temp)
    {
        if(hcf > temp)
            hcf -= temp;
        else
            temp -= hcf;
    }
    long lcm = (a * b) / hcf;
    cout << lcm;
    return 0;

}


Measured memory_bytes: 256
def Triangle(a,b,c):
    if a**2 == b**2 +c**2 or b**2 == a**2+c**2 or c**2 == a**2+b**2:
        print("YES")
    else:
        print("NO")

N = int(input())
for i in range(N):
    a,b,c = map(int,input().split())
    Triangle(a,b,c)



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

using namespace std;
  
typedef pair<string, int> P;
  
bool compare(const string& s1, const string& s2){
  if(s1.size() < s2.size()) return true;
  else if(s1.size() > s2.size()) return false;
  else{
    if(s1 < s2) return true;
    else return false;
  }
}
 
int main(){
  map<string, int, bool(*)(const string&, const string&)> data(compare);
  vector<string> ans;
  int n;
  cin >> n;
   
  string s;
  int t;
  for(int i = 0 ; i < n ; i++){
    cin >> s >> t;
    data[s] += t;
  }    
  for(map<string, int>::iterator it = data.begin() ; it != data.end() ; it++){
    cout << it->first << ' ' << it->second << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void push(int);
int pop(void);

int top=0;
int stack[100];

int main(){
  int x,a,b;
  char s[100];

  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      x = pop() + pop();
      push(x);
    } else if(s[0] == '-'){
      a = pop();
      b = pop();
      x = b - a;
      push(x);
    } else if(s[0] == '*'){
      x = pop() * pop();
      push(x);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",stack[top]);

  return 0;
}

void push(int x){
  top++;
  stack[top] = x;
}

int pop(void){
  top--;
  return stack[top+1];
}



Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void)
{
	int n, sum = 0;
	cin >> n;
	vector<int> a(n);

	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	double d_ave = (double)sum/n;
	int ave = round(d_ave);

	int t_max = 0;

	for (int i = 0; i < n; i++)
	{
		t_max += (a[i]-ave)*(a[i]-ave);
	}

	cout << t_max << endl;

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

vvl memo(101,vl(101,-1));
ll COM(ll a,ll b){
    if(a<0||b<0){
        return 0;
    }
    if(memo[a][b]!=-1){
        return memo[a][b];
    }
    if(b==0){
        return 1;
    }
    return memo[a][b]=COM(a-1,b)+COM(a-1,b-1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,A,B;
    cin >> N >> A >> B;
    vl v(N);
    rep(i,N){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    ld res=0;
    rep(i,A){
        res+=v[i];
    }
    res/=A;
    cout << fixed << setprecision(10) << res << endl;
    ll mnx=A-1,mxx=A-1;
    while(mnx>=1&&v[mnx]==v[mnx-1]){
        mnx--;
    }
    while(mxx<N-1&&v[mxx]==v[mxx+1]){
        mxx++;
    }
    ll ans=0;
    if(v[0]==v[A-1]){
        FOR(i,A,min(B,mxx+1)+1){
            ans+=COM(mxx+1,i);
        }
        cout << ans << endl;
        return 0;
    }
    ans+=COM(mxx-mnx+1,A-mnx);
    cout << ans << '\n';
}

Measured memory_bytes: 4004
#include <iostream>
#include <algorithm>
#include <vector>


int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    int min = a;
    int max = a;
    if (b > max)
        max = b;
    if (c > max)
        max = c;
    if (b < min)
        min = b;
    if (c < min)
        min = c;
    int k = a + b + c - max - min;

    std::cout << abs(max - k) + abs(min -k);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,k,t,u,v,l;
  cin >> n >> k >> t >> u >> v >> l;
  int d[n+1];
  REP(i,n)
    cin >> d[i];
  d[n] = l;
  int have = 0;
  int now = 0;
  double acctime = 0;
  double res = 0;
  REP(i,n+1) {
    double dis = d[i] - now;
    while(dis > 0) {
      if (acctime > 0) {
        if (acctime * v > dis) {
          acctime -= dis / v;
          res += dis / v;
          dis = 0;
        } else {
          dis -= acctime * v;
          res += acctime;
          acctime = 0;
        }
      } else {
        if (have) {
          have--;
          acctime = t;
        } else {
          res += dis / u;
          dis = 0;
        }
      }
    }
    now = d[i];
    have++;
    if (have == k + 1) {
      have = k;
      acctime = t;
    }
//    cout << res << endl;
  }
  printf("%.12f\n", res);
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep3(i, k, n) for (int i = k; i < n; i++)
#define sz(s) (int)s.size()
#define F first
#define S second
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {
    for (auto &vi: vec) os << vi << " "; return os;
}
#define eb emplace_back
int pow(int a, int n) {
	int res = 1;
    while (n > 0) {
        if (n & 1) res *= a;
        a *= a;
        n >>= 1;
    }
	return res;
}

const int max_n = 10000000;
int reached[max_n];
int forbid[max_n];

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

    vector<int> a(1 << n);
    rep(i, 1 << n) cin >> a[i];

    rep(i, 1 << n) {
        if (a[i] == 0) continue;
        rep(j, n) {
            if (!(i & (1 << j))) {
                if (a[i | 1 << j] == 0) {
                    cout << -1 << '\n';
                    return 0;
                }
                a[i | 1 << j] = -1;
            }
        }
    }

    // rep(i, 1 << n) cout << a[i] << " "; cout << endl;
    int cnt = 0;
    rep(i, 1 << n) if (a[i] == 1) cnt++;
    cout << cnt << '\n';
    /*
    vector<vector<int>> alive(n + 1);
    vector<vector<int>> dead(n + 1);
    vector<int> a(1 << n);
    for (int i = 0; i < 1 << n; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) if (i >> j & 1) cnt++;
        cin >> a[i];
        if (a[i]) {
            dead[cnt].emplace_back(i);
        } else {
            alive[cnt].emplace_back(i);
        }
    }
    vector<int> res;
    for (int k = 1; k <= n; k++) {
        for (int x: alive[k]) {

        }
        for (int x: dead[k]) {

        }
    }
    return 0;
    */
}


Measured memory_bytes: 7040
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

typedef long long ll;
typedef pair<ll, ll> P;

ll hist[110000];
vector<P> sushi;
int main()
{
  ll N, K;
  cin >> N >> K;
  REP(i, N) {
    ll t, d; cin >> t >> d;
    sushi.PB(MP(d, t));
  }
  sort(ALL(sushi), greater<P>());

  ll sum = 0, x = 0;
  REP(i, K) {
    if (hist[sushi[i].SE] == 0) x++;
    hist[sushi[i].SE]++;
    sum += sushi[i].FI;
  }
  ll ans = sum + x*x;

  priority_queue<P, vector<P>, greater<P>> pq1;
  REP(i, K) pq1.push(sushi[i]); 

  priority_queue<P> pq2;
  for (int i = K; i < N; i++) pq2.push(sushi[i]);

  while (1) {
    if (pq2.empty()) break;
    P e2 = pq2.top(); pq2.pop();
    while (!pq2.empty() && hist[e2.SE] > 0) {
      e2 = pq2.top();
      pq2.pop();
    }
    if (hist[e2.SE] > 0) break;
    hist[e2.SE]++;

    if (pq1.empty()) break;
    P e1 = pq1.top(); pq1.pop();
    while (!pq1.empty() && hist[e1.SE] == 1) {
      e1 = pq1.top();
      pq1.pop();
    }
    if (hist[e1.SE] == 1) break;
    hist[e1.SE]--;

    sum = sum - e1.FI + e2.FI;
    x++;
    ans = max(ans, sum + x*x);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6256
#include <stdio.h>
int main(void) {
	int n, l, ap, gap, tap, ap0;
	ap = gap = ap0 = 0;
	scanf("%d%d",&n ,&l);
	tap = l;

	for (int i = 0; i < n; i++) {
		ap = l + i;
		gap += ap;
		if (ap == 0) {
			ap0 = 1;
		}
		if (tap < ap) {
			tap = ap;
		}
	}

	if (l >= 0) {
		printf("%d", gap - l);
	}
	else {
		if (ap0 == 1) {
			printf("%d", gap);
		}
		else {
			printf("%d", gap - tap);
		}
	}
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int T;
    scanf(" %d", &T);
    while(T--)
    {
        vector<int> n(9);
        vector<char> c(9);

        rep(i,9) scanf(" %d", &n[i]);
        rep(i,9) scanf(" %c", &c[i]);

        vector<int> x[3];
        rep(i,9)
        {
            if(c[i]=='R') x[0].pb(n[i]);
            if(c[i]=='G') x[1].pb(n[i]);
            if(c[i]=='B') x[2].pb(n[i]);
        }
        rep(i,3) sort(all(x[i]));

        int ans=1;

        rep(i,3)
        {
            if(x[i].size()%3!=0) ans=0;
        }

        if(ans)
        {
            rep(i,3)
            {
                if(x[i].size()==0) continue;

                int ct[10]={0};
                rep(j,x[i].size()) ct[x[i][j]]++;

                int now=1;
                while(ct[now]==0) ++now;

                rep(j,x[i].size()/3)
                {
                    if(ct[now]<3)
                    {
                        if(now<=7 && ct[now+1]>0 && ct[now+2]>0)
                        {
                            --ct[now];
                            --ct[now+1];
                            --ct[now+2];
                        }
                        else
                        {
                            ans=0;
                            break;
                        }
                    }
                    else
                    {
                        ct[now]-=3;
                    }

                    while(ct[now]==0) ++now;
                }

                if(ans==0) break;
            }
        }

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

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

#define MAX 100000
#define INF (INT32_MAX/2)

int N, K;
int h[MAX];

int dp[MAX + 100];

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

	for( int i = 0; i < N; i++ ) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for( int i = 0; i < N; i++ ) {
		for( int j = 1; j <= K; j++ ) {
			dp[i + j] = min( dp[i + j], dp[i] + abs( h[i] - h[i + j] ) );
		}
	}
	int ans = dp[N - 1];

	cout << ans << endl;

	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<tuple<string, int, int>> a;
  for(int i = 1; i <= N; i++){
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    a.push_back(tie(s, p, i));
  }
  
  sort(a.begin(), a.end());
  for(int i = 0; i < N; i++){
    string s;
    int p;
    int id;
    tie(s,p,id) = a[i];
    cout << id << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iM1 = int.Parse(sS[0]);
            int iD1 = int.Parse(sS[1]);
            sS = System.Console.ReadLine().Trim().Split(' ');
            int iM2 = int.Parse(sS[0]);
            int iD2 = int.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            if (iM1 != iM2) { iOut = 1; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
from collections import defaultdict
import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
U = 10 ** 5 + 1

N, K = map(int, input().split())
DT = []
for _ in range(N):
    t, d = map(int, input().split())
    DT.append((d, t))

DT.sort(reverse=True)
score = 0
kind = defaultdict(list)
used = [0] * (U + 1)
for d, t in DT[:K]:
    score += d
    used[t] += 1
    kind[t].append(d)

cnt = len(kind)
ans = score + (cnt * cnt)

cand = []  # 交換する可能性のあるやつ, 小さいやつから削除
for key, val in kind.items():
    val.sort(reverse=True)
    while len(val) > 1:
        heapq.heappush(cand, (val.pop(), key))


for d_in, t_in in DT[K:]:
    if not cand:
        break
    if used[t_in]:
        continue

    d_out, t_out = heapq.heappop(cand)
    used[t_in] += 1
    used[t_out] -= 1
    cnt += 1
    score = score - d_out + d_in
    ans = max(ans, score + (cnt * cnt))

print(ans)

Measured memory_bytes: 29844
#include<stdio.h>
#include<map>
#include<vector>

using namespace std;

int ar[100005];
map<int,vector<int>>ma;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    ma[-ar[i]].push_back(i);
    map<int,vector<int>>::iterator p = ma.upper_bound(-ar[i]);
    if (p != ma.end()) {
      ar[p->second[p->second.size() - 1]] = -1;
      p->second.pop_back();
      if (p->second.size() == 0) {
        ma.erase(p);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ar[i] != -1) ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 11392
k = int(input())

if k%7 == 0:
    k = k//7
k = k*9
ret = -1
if (k%2 == 0) or (k%5 ==0):
    print(-1)
else:
    for i in range(1,k+3):
        if pow(10,i,k) == 1:
            ret = i
            break
    print(ret)

Measured memory_bytes: 9188
#include<stdio.h>

 int count=0;
 int m=0;
 int G[1000001]={};

 int insertion(int A[],int n,int g){
         int i,j,tmp,v;
         for(i=g;i<=n-1;i++){
                 v=A[i];
                 j=i-g;

                 while(j>=0&&A[j]>v){
                        A[j+g]=A[j];
                        j-=g;
                        count++;
                        A[j+g]=v;
                        }
                 }
         }


 int shell(int A[],int n){
          int i;
          G[0]=1;
          for(m=1;3*G[m-1]+1<=n;m++){
                   G[m]=3*G[m-1]+1;
                   }
          for(i=m-1;i>=0;i--){
                   insertion(A,n,G[i]);
                   }
           }

 int main(){
     int i,j,n,A[1000001];
     scanf("%d",&n);
     for(i=0;i<n;i++){
            scanf("%d",&A[i]);
            }

     shell(A,n);

     printf("%d\n",m);
     for(i=m-1;i>=0;i--){
              printf("%d",G[i]);
              if(i==0)printf("\n");
              else printf(" ");
              }

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

     for(i=0;i<n;i++){
               printf("%d\n",A[i]);
               }
     return 0;
     }



     


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  ll h = 0, nn = 0, w = 0;
  for (ll i = 1; i <= 3500 && h == 0; ++i) {
    for (ll j = 1; j <= 3500 && h == 0; ++j) {
      ll l = lcm(n, lcm(i, j));
      ll m = 4ll * (l / n) - (l / i + l / j);
      if (m <= 0) {
        continue;
      }

      if (l % m != 0) {
        continue;
      }

      h = i;
      nn = j;
      w = l / m;
    }
  }

  cout << h << ' ' << nn << ' ' << w << '\n';
}

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

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

    int ans = 0;
    if (X == 1) ans = 1;

    for (int i = 2; i <= X; ++i) {
        for (int j = 2; j <= X; ++j) {
            int a = pow(i, j);
            if (a <= X) {
                ans = max(ans, a);
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int a[n-1];
	for(int i =0;i<n-1;i++)
		a[i] = abs(s[i]-s[i+1]);

	int cnt[3];
	memset(cnt,0,sizeof(cnt));
	for(int i =0;i<n-1;i++)
		cnt[a[i]]++;
	int to_check = 1;
	if(cnt[1]==0){
		to_check = 2;
		for(int i =0;i<n-1;i++)
			a[i]>>=1;
	}

	int res = 0;
	for(int i =0;i<n-1;i++){
		if(((n-2)&i) == i) // applying lucas theorem for mod 2
			res^=a[i];
	}
	// cout << res << to_check << endl;
	cout << (res%2)*to_check << endl;
}

Measured memory_bytes: 5252
#include <iostream>
#include<algorithm>
#include<map>

using namespace std;
 
int main(void){
	
	char S[3];
	int price=700;
	
	cin >> S[0] >> S[1] >> S[2];
	
	for(int i=0; i<3; i++){
		if(S[i] == 'o')
			price += 100;
	}
	
	cout << price;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

char map[2048][2048];
int d[2048][2048];
	
pair<int,int> ch[10];

int w,h,n;

const int INF = 999999999;

int solve(pair<int,int> s,pair<int,int> g){
	//printf("(%d,%d) -> (%d,%d)\n",s.first,s.second,g.first,g.second);
	
	for(int i=0;i<w;i++){
		for(int j=0;j<h;j++){
			d[i][j] = INF;
		}
	}
	pair<int,int> v[4] = {
		pair<int,int>(1,0),
		pair<int,int>(-1,0),
		pair<int,int>(0,1),
		pair<int,int>(0,-1)
	};
	
	
	queue< pair<int,int> > que;
	pair<int,int> p,pp;
	
	d[s.first][s.second] = 0;
	que.push(s);
	
	
	while(que.size() > 0){
		if(d[g.first][g.second] != INF){
			return d[g.first][g.second];
		}
		p = que.front();
		//printf("(%d,%d)\n",g.first,g.second);
		que.pop();
		for(int i=0;i<4;i++){
			pp.first = p.first + v[i].first;
			pp.second = p.second + v[i].second;
			if(pp.first < 0 || pp.first >= w || pp.second < 0 || pp.second >= h){continue;}
			if(map[pp.first][pp.second] != 'X' && d[pp.first][pp.second] == INF){
				d[pp.first][pp.second] = d[p.first][p.second] + 1;
				que.push(pp);
			}
		}
	}
	
	return -1;
}

int main(){
	char c;
	scanf("%d %d %d",&h,&w,&n);
	//printf("%dx%d %d\n",w,h,n);
	for(int j=0;j<h;j++){
		for(int i=0;i<w;i++){
			while(scanf("%c",&c) && c == '\n');
			map[i][j] = c;
			if('1' <= c && c <= '9'){
				ch[c - '1' + 1] = pair<int,int>(i,j);
			}
			if('S' == c){
				ch[0] = pair<int,int>(i,j);
			}
		}
	}
	
	int ans = 0;
	int ss;
	for(int i = 0;i < n;i++){
		pair<int,int> s,g;
		s = ch[i];
		g = ch[i + 1];
		//printf("(%d,%d) -> (%d,%d)\n",s.first,s.second,g.first,g.second);
		ss = solve(s,g);
		ans += ss;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 10000
H,W = map(int,input().split())

if H == 1 or W == 1:
    Ans=1
else:
    if H*W%2 == 0:#マス目の合計が偶数なら
        Ans=H*W/2
    else:#マス目の合計が奇数なら
        Ans=H*W//2+1

print(round(Ans))

Measured memory_bytes: 61780
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

using Graph = vector<vector<int>>;

typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;


map <string, int> m;
int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        string s;
        cin >> s;
        m[s] = m[s] + 1;
    }

    int m_max = 0;
    vector<string> res;

    for(auto t:m)
    {
        if(m_max < t.second)
        {
            m_max = t.second;
            res.clear();
            res.push_back(t.first);
        }
        else if(m_max == t.second)
        {
            res.push_back(t.first);
        }
    }
    for(auto t:res)
    {
        cout << t << endl;
    }

    return 0;
}

Measured memory_bytes: 26868
#include "bits/stdc++.h"
using namespace std; 

#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long 

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


int main(){
        IOS;
        ll d,t,s;
        cin>>d>>t>>s;
        if(s*t>=d) cout<<"Yes\n";
        else cout<<"No\n";
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

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

using namespace std;

int main() {
	int a, b, c, x, ans = 0;
	cin >> a >> b >> c >> x;

	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				int now = 500 * i + 100 * j + 50 * k;
				if (x == now)
					ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

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

const int MAXN = 8e3+1; //AREGLAAAAAAAAR!!!!
char a[MAXN],b[MAXN],c[MAXN];
int memo[MAXN][MAXN];
int ini,fin,N;

int dp(int pos,int x,int t){
	if(!t && pos==N && x==fin) return 1;
	if(t && pos==N && x==ini) return 1;
	if(pos>=N) return 0;
	if(memo[pos][x]!=-1) return memo[pos][x];
	int good=2;
	if(a[pos]=='F'){
		int pf=N;
		FOR(i,pos,N){
			if(a[i]=='T'){
				pf=i;
				break;
			}
		}
		good=dp(pf,x+pf-pos,t) || dp(pf,x-pf+pos,t);
	}else{
		int pf=N-1;
		FOR(i,pos+1,N){
			if(a[i]=='T'){
				pf=i;
				break;
			}
		}
		good=dp(pf+1,x,t);
	}
	return memo[pos][x]=good;
}

int main(){
	scanf("%s",a);
	N=strlen(a);
	rii(ini,fin);
	int p1=N,p2=N-1;
	FOR(i,0,N){
		if(a[i]=='T'){
			p1=i;
			p2=i;
			break;
		}
	}
	memset(memo,-1,sizeof(memo));
	int ans=dp(p1,p1,1);
	memset(memo,-1,sizeof(memo));
	if(ans && dp(p2+1,0,0)) printf("Yes\n");
	else printf("No\n");
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	sort(ALL(ret));
	return ret;
}

ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}

ll gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	while(ll r=(a%b)){
		a = b;
		b = r;
	}
	return b;
}

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

vector<ll> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	vector<ll> P;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

vector<ll> prime_factor(ll n){
	ll sn = sqrt(n)+1;
	auto prime_list = enum_prime(sn);
	vector<ll> res;
	for(int i=0,ei=prime_list.size();i<ei;i++){
		ll v = prime_list[i];
		if(v*v>n) break;
		while(!(n%v)){
			n /= v;
			res.push_back(v);
		}
	}
	if(n>1){
		res.push_back(n);
	}

	return res;
}

ll EulerPhiFunction(ll n){
	auto p=prime_factor(n);
	p.erase(unique(ALL(p)),p.end());
	for(auto& x:p){
		n = n*(x-1LL)/x;
	}
	return n;
}

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

	while(true){
		ll a,b,c,x,y,z;
		cin>>a>>x>>b>>y>>c>>z;
		if(!a) break;

		ll ar,br,cr;
		auto D = enum_div(EulerPhiFunction(x));
		for(auto& p:D){
			if(powermod(a,p,x)==1LL){
				ar = p;
				break;
			}
		}
		D = enum_div(EulerPhiFunction(y));
		for(auto& p:D){
			if(powermod(b,p,y)==1LL){
				br = p;
				break;
			}
		}
		D = enum_div(EulerPhiFunction(z));
		for(auto& p:D){
			if(powermod(c,p,z)==1LL){
				cr = p;
				break;
			}
		}
		out(lcm(lcm(ar,br),cr));
	}

	return 0;
}



Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            String str = scanner.next();
            int length = str.length();
            if (str.charAt(0) == '0') break;
            int sum = 0;
            for (int i = 0; i < length; i++) {
               sum += str.charAt(i) - '0';
            }
            System.out.println(sum);
        }
        scanner.close();
    }
}



Measured memory_bytes: 26008
#include <bits/stdc++.h>
 
 
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
 
signed main() {
    FAST_IO;
 
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
 
    int dp[n][3]; // dp[i][j] : i represents the day and j represents the activity
    				         // j is 0 for activity A, 1 for activity B and 2 for activity C
 
  	// Set the base values
    dp[0][0] = a[0]; // If you swim in the sea in sea on the first day, you cannot get more than a[0] points.
    dp[0][1] = b[0]; // If you catch bugs in the mountains on the first day, you cannot get more than b[0] points.
    dp[0][2] = c[0]; // If you do homework at home on the first day, you cannot get more than c[0] points.
 
    // i represents what day it is (0 based indexing)
    for (int i = 1; i < n; i++) { 
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]); // If we do activity A today, we have to have done activities B or C on the previous day.
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]); // If we do activity B today, we have to have done activities A or C on the previous day.
        dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]); // If we do activity C today, we have to have done activities A or B on the previous day.
    }
 
  	// Our answer is the maximum of all the points gained by doing activity A, B, or C on the last day.
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); 
    return 0;
}

Measured memory_bytes: 5996
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        a: i32,
        b: i32,
        c: i32,
        d: i32,
        e: i32,
        k: i32,
    }
    let mut ans = "Yay!";
    let vec = vec![a,b,c,d,e];
    for i in 0..5 {
        for j in 0..5 {
            if i==j {
                continue;
            }
            if (vec[i] - vec[j]).abs() > k {
                ans = ":(";
                break;
            }
        }
    }
    ans.into()
}

// Test Code

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
r"1
2
4
8
9
15
" => "Yay!",
r"15
18
26
35
36
18
" => ":("
}


Measured memory_bytes: 4352
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define inf 1e18
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main(){
	int n;
	cin >> n;
	ll sum = 0;
	rep(i, n) {
		int p;
		cin >> p;
		sum += p;
	}
	cout << sum - n << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
	"unicode/utf8"
)

func main() {
	var n int
	var s string

	fmt.Scan(&n, &s)

	r := strings.Count(s, "R")
	g := strings.Count(s, "G")
	b := strings.Count(s, "B")
	lenS := utf8.RuneCountInString(s)

	var exclude int
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			k := j + j - i
			if k >= lenS {
				continue
			}
			if s[i] != s[j] && s[i] != s[k] && s[j] != s[k] {
				exclude++
			}
		}
	}

	fmt.Println(r*g*b - exclude)
}


Measured memory_bytes: 1892
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	int n, student[1000];
	double a = 0,standard=0;

	//生徒数
	cin >> n;

	//生徒数が0以外で実行
	while (n != 0) {

		for (int i = 0; i < n; i++) {
			//点数入力
			cin >> student[i];
			//平均点
			standard += student[i];
		}

		//平均点s
		standard /= n;
		
		for (int i = 0; i < n; i++) {
			a += powl(student[i] - standard, 2);
		}
		a /= n;
		a = sqrtl(a);

		//偏差出力
		cout << fixed << setprecision(8) << a << endl;
		
		//初期化
		a = 0, standard = 0;

		//もう一度生徒数入力
		cin >> n;
	}


	return 0;
}


Measured memory_bytes: 3264
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int max = 0;
        for (int i = 0;i < S.length()-T.length()+1 ; i++){
             int cnt = 0;
            String test = S.substring(i,i+T.length());
            for (int ind = 0; ind<T.length();ind++){
                if (test.charAt(ind)==T.charAt(ind)){
                    cnt++;
                }
            }
            if (max<cnt){
                max=cnt;
            }
        }
        System.out.println(T.length()-max);
    }
}

Measured memory_bytes: 36920
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint cal(){
	lint k,a,b;
	cin>>k>>a>>b;
	if(a+1>=b) return k+1;
	if(k<=a-1) return k+1;
	k-=a-1;
	return a+(k/2)*(b-a)+k%2;
}
int main()
{
	cout<<cal()<<endl;
}


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

using namespace std;

const int maxn = 310;
const int mod = 998244353;

int n;
char S[maxn];
bool ok[maxn][maxn][maxn];
int dp[maxn][maxn], ndp[maxn][maxn]; // cnt of 0 not in "lcs"

int mo(int x) {
	return (x >= mod) ? (x - mod) : x;
}

int main() {
	scanf("%s", S+1);
	n = int (strlen(S + 1));
	ok[0][0][0] = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= i-j; k++) {
				if (ok[i][j][k]) {
					{
						// use S[i+1]
						ok[i+1][j][k] = true;
						if (j && S[i+1] == '1') ok[i+1][j-1][k+1] = true;
						if (k && S[i+1] == '0') ok[i+1][j+1][k-1] = true;
					}
					if (i + 2 <= n) {
						// use S[i+1] && S[i+2]
						if (S[i+1] == '0' || S[i+2] == '0') {
							ok[i+2][j+1][k] = true;
						}
						if (S[i+1] == '1' || S[i+2] == '1') {
							ok[i+2][j][k+1] = true;
						}
					}
				}
			}
		}
	}
	for (int i = 0; i <= n; i++) {
		for (int j = i; j >= 0; j--) {
			for (int k = i-j; k >= 0; k--) {
				if (!ok[i][j][k]) continue;
				if (j && k) ok[i][j-1][k-1] = true;
				if (j >= 2) ok[i][j-2][k] = true;
				if (k >= 2) ok[i][j][k-2] = true;
			}
		}
	}
	int ans = 0;
	dp[0][0] = 1;
	for (int len = 1; len <= n; len++) {
		for (int i = 0; i <= len; i++) {
			for (int j = 0; j <= len-i; j++) {
				ndp[i][j] = 0;
				// from i
				if (i != n) {
					if (S[n - i] == '0') {
						ndp[i][j] = mo(ndp[i][j] + dp[i][j]);
					} else if (j) {
						ndp[i][j] = mo(ndp[i][j] + dp[i][j-1]);
					}
				}
				// from i-1
				if (i) ndp[i][j] = mo(ndp[i][j] + dp[i-1][j]);
			}
		}
		for (int i = 0; i <= len; i++) {
			for (int j = 0; j <= len-i; j++) {
				dp[i][j] = ndp[i][j];
				if (ok[n-i][j][len-i-j]) {
					ans = mo(ans + dp[i][j]);
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, q, a[100005] = {}, b;
    cin >> n >> k >> q;
    for (int i = 0; i < q; i++) cin >> b, a[b]++;
    for (int i = 1; i <= n; i++) {
        if (q - a[i] < k) cout << "Yes\n";
        else cout << "No\n";
    }
}


Measured memory_bytes: 1024