akhauriyash/Code-Regression huggingface dataset:
use std::collections::{BTreeMap, BTreeSet};
use std::cmp::max;

fn readln() -> Vec<String> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().split_whitespace().map(|s| s.to_owned()).collect()
}

fn main() {
    let input: Vec<i64> = readln().iter().map(|s| s.parse().unwrap()).collect();
    let n = input[0];
    let mut x = input[1];
    let mut d = input[2];
    if d < 0 {
        x = -x;
        d = -d;
    }
    let x = x;
    let d = d;

    let mut ans = 0i64;
    if d == 0 {
        let mut set = BTreeSet::new();
        for i in 0..n + 1 {
            set.insert(x * i);
        }
        ans = set.len() as i64;
    } else {
        let mut map = BTreeMap::<_, Vec<(i64, i64)>>::new();
        for i in 0..n + 1 {
            let md = (i * x % d + d) % d;
            let min = (x * i - md) / d + i * (i - 1) / 2;
            let max = (x * i - md) / d + i * (2 * n - i - 1) / 2 + 1;
            map.entry(md).or_insert_with(&Vec::new).push((min, max));
        }

        for (_, v) in &mut map {
            v.sort();
            let mut maxend: i64 = i64::min_value();
            for &(f, t) in &*v {
                let u = max(maxend, f);
                maxend = max(maxend, t);
                ans += maxend - u;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 37116
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 99999999;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int flag = 0;

void myMin(int num[], int length);

int main() {
	int N;
	int T, A;
	int H[1008];
	int absT[1008];
	scanf("%d%d%d", &N,&T,&A);
	for (int i = 0; i < N; i++) {
		scanf("%d", &H[i]);
		absT[i] = abs(T*1000 - H[i] * 6-A*1000);
	}

	myMin(absT, N);

	printf("%d", flag + 1);


}


//---配列の最小値を求める---
void myMin(int num[], int length) {
	int temp = c_INF;
	for (int i = 0; i < length; i++) {
		temp = min(temp, num[i]);
		if (temp == num[i])flag = i;
		//printf("%d\t%d\n", temp, flag);
	}

	
}


/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
lis_1=[]
lis_2=[]
for i in range(10):
    a=int(input())
    lis_1.append(a)
lis_1.sort()
for i in range(10,20):
    a=int(input())
    lis_2.append(a)
lis_2.sort()
x=lis_1[-1]
y=lis_1[-2]
z=lis_1[-3]
v=x+y+z
s=lis_2[-1]
t=lis_2[-2]
u=lis_2[-3]
w=s+t+u
print(v,w)


Measured memory_bytes: 5600
def count_big(s):
    count = 0
    for s_i in s:
        if s_i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
            count += 1
    return count

s = input()
if s[0] == "A" and s[2:-1].count("C") == 1 and count_big(s) == 2:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
bool isPrime(int x){
    bool flag = true;
    for(int i = 2; i*i<=x; i++){
        if(x%i == 0){
            flag = false;
            break;
        }
    }
    return flag;
}
int main(){
    int x; cin >> x;
    while(1){
        if(isPrime(x)){
            cout << x << endl;
            return 0;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll m,nn,nx;
    cin>>m>>nn>>nx;
    if(m==0 && nn==0 && nx==0) return 0;
    vector<ll> v(m);
    rep(i,m) cin>>v[i];
    vector<ll> w(m-1);
    rep(i,m-1) w[i]=v[i]-v[i+1];
    ll ans=0;
    ll tmp=0;
    for(ll i=nn-1;i<min(nx,m);i++){
      if(ans<=w[i]){
        ans=w[i];
        tmp=i;
      }
    }
    cout<<tmp+1<<endl;
  }
}


Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	ll k, n; cin >> k >> n;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];
	

	ll ans = INFL;
	rep(i, 0, n - 1) {
		ll d = abs(a[i + 1] - a[i]);
		ans = min(ans, k - d);
	}
	ans = min(ans, k - (k - a[n - 1] + a[0]));
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4776
n = int(input())
i = 0
ans = 0

while n-10**i >= 0:
    if not i & 1:
        if n-10**(i+1) < 0:
            ans += n - 10**i + 1
        else:
            ans += 10**i * 9

    i += 1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
 
int main(){
    int X, Y, A, B, C;
    std::cin >> X >> Y >> A >> B >> C;
    std::vector< int > P(A);
    std::vector< int > Q(B);
    std::vector< int > R(C);
    for(int i=0; i<A; i++){
        std::cin >> P[i];
    }
    for(int i=0; i<B; i++){
        std::cin >> Q[i];
    }
    for(int i=0; i<C; i++){
        std::cin >> R[i];
    }
    P.push_back(0);
    Q.push_back(0);
    R.push_back(0);
    
    std::sort(P.begin(), P.end());
    std::sort(Q.begin(), Q.end());
    std::sort(R.begin(), R.end());
    
    long long ans = 0;
    
    int Aind = P.size() - 1;
    int Bind = Q.size() - 1;
    int Cind = R.size() - 1;
    for(int i=0; i<X+Y; i++){
        if(P[Aind] >= Q[Bind] && P[Aind] >= R[Cind]){
            ans += P[Aind];
            Aind--;
            if(P.size() - Aind > X){
                Aind = 0;
            }
        }else if(Q[Bind] >= P[Aind] && Q[Bind] >= R[Cind]){
            ans += Q[Bind];
            Bind--;
            if(Q.size() - Bind > Y){
                Bind = 0;
            }
        }else{
            ans += R[Cind];
            Cind--;
        }
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}
 

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
ll x, y, z;
/******* define variable end *******/
ll solve() {
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return (int)end_solve;
}


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

int main(){
	int n;	cin>>n;
	vector<string> list(n+1);
	list[n]="zzzzzzzzzzzz";
	for(int i=0;i<n;i++)cin>>list[i];
	sort(list.begin(), list.end());

	int maxCnt=0,cnt=0;
	string tmp="";
	for(int i=0;i<=n;i++){
		if(tmp==list[i]){
			cnt++;
		}else{
			maxCnt=max(maxCnt,cnt);
			cnt=1;
			tmp=list[i];
		}
	}

	//cout<<maxCnt<<endl;
	tmp="";	cnt=0;
	for(int i=0;i<=n;i++){
		if(tmp==list[i]){
			cnt++;
		}else{
			if(maxCnt==cnt)cout<<tmp<<endl;
			cnt=1;
			tmp=list[i];
		}
	}

	return 0;
}


Measured memory_bytes: 14208
import java.util.*
fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val x = cin.nextInt()

    val l = Array<Int>(n, {cin.nextInt()})

    var now = 0
    var count = 1
    for (i in 0..n-1) {
        now += l[i]
        if (now > x) {
            break
        }
        count += 1
    }
    println(count)
}

Measured memory_bytes: 31396
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<ll,ll>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll ans = INF;
    for(int i = -100;i <= 100;i++){
        ll sum = 0;
        for(auto v : a){
            sum += (v-i)*(v-i);
        }
        chmin(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s;
    cin >> s;
    if(s == "SUN")cout << 7 << endl;
    else if(s == "MON")cout << 6 << endl;
    else if(s == "TUE")cout << 5 << endl;
    else if (s == "WED")cout << 4 << endl;
    else if( s == "THU")cout << 3 << endl;
    else if(s == "FRI")cout << 2 << endl;
    else if(s == "SAT")cout << 1 << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> II;

string S, T;

int memo[3004][3004];
char nxt[3004][3004];
int F(int n, int m) {
   if (n >= SZ(S) || m >= SZ(T)) return 0;
   int& res = memo[n][m];
   if (res < 0) {
      if (S[n] == T[m]) {
         res = F(n+1, m+1) + 1;
         nxt[n][m] = 'B';
      }
      else {
         int res1 = F(n+1, m);
         int res2 = F(n, m+1);
         if (res1 >= res2) {
            res = res1;
            nxt[n][m] = 'S';
         }
         else {
            res = res2;
            nxt[n][m] = 'T';
         }
      }
   }
   return res;
}


int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> S;
   cin >> T;

   memset(memo, -1, sizeof(memo));
   F(0, 0);

   string res;
   for (int n = 0, m = 0; n < SZ(S) && m < SZ(T); ) {
      switch (nxt[n][m]) {
         case 'B':
            res += S[n];
            ++n;
            ++m;
            break;
         case 'S':
            ++n;
            break;
         case 'T':
            ++m;
            break;
      }
   }
   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 44672
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r)          \
	for (int i = l; i < r; i++) \
		cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int a, b;
	cin >> a >> b;
	if ((a - 2 * b) <= 0)
		cout << 0 << endl;
	else
		cout << (a - 2 * b) << endl;

	return 0;
}

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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define MOD 1000000007

int main()
{
    speed;
    ll k,x;
    cin>>k>>x;
    --k;
    for(ll i=x-k;i<=x+k;++i)
    	cout<<i<<" ";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a < b && b < c) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}



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

int main(){
    string s;

    cin >> s;
    int n=s.size();

    long long ans(0),b(0);

    rep(i,n){
        if(s[i]=='B'){
            b++;
        }else{
            ans += b;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 640
x = input()
k = int(input())
x = x.split()
y = [int(s) for s in x]
dict = {"red":0, "green":0}
dict["red"] = y[0]
dict["green"] = y[1]
count = 0
if dict["red"] < dict["green"]:
      pass
else:
  for N in range(k):
    count += 1
    dict["green"] = dict["green"] * 2
    if dict["red"] < dict["green"]:
        break
    else:
        continue
dict["blue"] = y[2]
if k - count == 0:
  if dict["green"] > dict["blue"]:
    pass
  else:
    print("Yes")
    exit()
else:
  pass
i = k - count
if dict["green"] < dict["blue"]:
  print("Yes")
  exit()
else:
  for N in range(i):
    dict["blue"] = dict["blue"] * 2
    if dict["green"] < dict["blue"]:
      print("Yes")
      exit()
    else:
        continue
print("No")

Measured memory_bytes: 9152
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    constexpr int A_MAX = 1000000;
    vector<int> min_factor(A_MAX + 1);
    vector<int> q(A_MAX + 1, 1);
    vector<int> primes;
    for (int i = 2; i <= A_MAX; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
            primes.push_back(i);
        }
        int min_factor_i = min_factor[i];
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    int N = 0;
    char c = getchar_unlocked();
    do {
        N = 10 * N + c - '0';
    } while ((c = getchar_unlocked()) >= '0');
    vector<int> a(A_MAX + 1);
    for (int i = 0; i < N; ++i) {
        int A = 0;
        c = getchar_unlocked();
        do {
            A = 10 * A + c - '0';
    	} while ((c = getchar_unlocked()) >= '0');
        ++a[A];
    }
 
    bool is_pairwise_coprime = true;
    for (int n = A_MAX; n > 1; --n) {
        int a_n = a[n];
        if (a_n > 1) {
            if (a_n == N) {
                printf("not coprime\n");
                return 0;
            }
            is_pairwise_coprime = false;
        }
        a[min_factor[n]] += a_n;
        a[q[n]] += a_n;
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

Measured memory_bytes: 15472
def main():
    N = int(input())
    l = []
    for _ in range(N):
        x,y,h = map(int, input().split())
        l.append((x,y,h))
    l.sort(key=lambda x:x[2], reverse=True)
    for i in range(101):
        for j in range(101):
            H = l[0][2] +  abs(l[0][0] - i) + abs(l[0][1] - j)
            for k in range(N):
                if max(H-abs(l[k][0]-i) - abs(l[k][1] - j), 0) != l[k][2]:
                    break
            else:
                return i, j, H
i, j, H = main()
print(i,j,H)


Measured memory_bytes: 9140
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    x = II()

    t = x // 500
    x = x % 500

    t2 = x // 5
    # print(t, t2)
    print(1000*t + 5 * t2)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail
{
  template <typename T, std::size_t NDIMS>
  struct vector_builder
  {
    using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
      if (!dims.empty())
        dims.pop_back();
      return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
    }
  };

  template <typename T>
  struct vector_builder<T, 1>
  {
    using type = std::vector<T>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      return type(dims.empty() ? 0 : dims.back(), v);
    }
  };
} // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T &v, SIZE_T... dims)
{
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N)
{

  LL ans = 0;
  for (int i = 1; i <= N; i++)
  {
    if (i % 3 == 0)
      continue;
    if (i % 5 == 0)
      continue;
    ans += i;
  }
  cout << ans << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3652
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll r;
    cin >> r;

    cout << r * r * 3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;

  int mn = A1 + A2 + A3;
  mn = min(mn, abs(A1 - A2) + abs(A2 - A3));
  mn = min(mn, abs(A1 - A3) + abs(A3 - A2));
  mn = min(mn, abs(A2 - A1) + abs(A1 - A3));
  mn = min(mn, abs(A2 - A3) + abs(A3 - A1));
  mn = min(mn, abs(A3 - A1) + abs(A1 - A2));
  mn = min(mn, abs(A3 - A2) + abs(A2 - A1));

  cout << mn << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<cctype>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll L,R,d;
ll ans = 0;

cin >> L >> R >> d;

for(ll i = L;i <=R;++i){

  if(i%d == 0) ans++;

}

cout << ans << endl;

return 0;

}   


Measured memory_bytes: 3516
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define maxn 500005
#define ll long long
using namespace std;
ll cnt,ans;
char s[maxn];
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)
	{
		if(s[i]=='W')
		{
			ans+=i-cnt;
			cnt++;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    string S;
    int Q;
    cin >> S >> Q;

    deque<char> xs(S.begin(), S.end());
    int r = 0;

    while (Q--)
    {
        int T;
        cin >> T;

        switch (T) {
        case 1:
            r = 1 - r;
            break;

        case 2:
            {
                int F;
                string s;

                cin >> F >> s;

                char c = s.front();

                if (r)
                    F = 3 - F;

                F == 1 ? xs.push_front(c) : xs.push_back(c);
            }
        }
    }

    if (r)
        reverse(xs.begin(), xs.end());

    string ans(xs.begin(), xs.end());

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4064
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(void){
   int n;int t=0;int h=0;
   string T;string H;
    scanf("%d",&n);
    while(n>0){
        cin >> T >> H;
        if(T>H){
            t=t+3;    
        }else if(H>T){
            h=h+3;
        }else{
            t=t+1; h=h+1;
        }




n=n-1;
}

    printf("%d %d\n",t,h);
}


Measured memory_bytes: 3304
#include "bits/stdc++.h"
using namespace std;
typedef pair<long long, long long> P;
int main() {
	long long N, M; cin >> N >> M;
	vector<long long>num;
	for (long long i = 1; i <= sqrt(M); i++) {
		if (M % i == 0) {
			if (i == M / i)num.push_back(i);
			else {
				num.push_back(i);
				num.push_back(M / i);
			}
		}
	}
	sort(num.begin(), num.end());
	long long ans = 0;
	for (long long i = 0; i < num.size(); i++) {
		if ((M - num.at(i) * (N - 1)) % num.at(i) == 0 && (M - num.at(i) * (N - 1)) > 0) ans = num.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
        var n, k int
        fmt.Scan(&n, &k)

        if (n - 1)%(k - 1) == 0 {
                fmt.Println((n - 1) / (k - 1))
        } else {
                fmt.Println((n-1)/(k-1) + 1)
        }
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

int D;
const int CONTESTS = 26;
vector<int> c(CONTESTS), held_contests;
vector<vector<int>> s;

void calc_score(){
    int ans = 0;
    vector<int> last(CONTESTS,0);
    rep(i,D){
        ans += s[i][held_contests[i]];
        last[held_contests[i]] = i + 1;
        rep(j,CONTESTS){
            ans -= c[j] * (i + 1 - last[j]);
        }
        cout << ans << endl;
    }
}

void answer(){
    for(int i : held_contests){
        cout << i + 1 << endl;
    }
}

void debug(int seed){
    string cmd = "python3 /Users/trpfrog/Downloads/tester/generator.py ";
    cmd += to_string(seed);
    cmd += " > /Users/trpfrog/Documents/AtCoder/AtCoder/input.txt";
    system(cmd.c_str());
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
}

signed main(){
    cin >> D;
    held_contests = vector<int>(D);
    
    rep(i,CONTESTS) cin >> c[i];
    s = vector<vector<int>>(D, vector<int>(CONTESTS));
    rep(i,D)rep(j,CONTESTS) cin >> s[i][j];
    
    rep(i,D){
        cin >> held_contests[i];
        held_contests[i]--;
    }
    
    calc_score();
}

Measured memory_bytes: 3752
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

int main(int argc, char* argv[]) {
  int N, M;
  std::cin >> N >> M;
  int data[N][M];
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < M; i++) {
      data[j][i] = 0;
    }
  }
  for (int j = 0; j < N; j++) {
    int K;
    std::cin >> K;
    for (int i = 0; i < K; i++) {
      int A;
      std::cin >> A;
      data[j][A - 1] = 1;
    }
  }

  int cnt = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (data[j][i] == 0) {
        break;
      }
      if (j == N - 1) {
        cnt++;
      }
    }
  }
  std::cout << cnt << std::endl;
  return 0;
}


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

ll diff(vector<ll> S) {
  sort(S.begin(), S.end());
  return S[2] - S[0];
}

int main() {
  ll H, W;
  cin >> H >> W;
  ll ans = H * W;
  vector<ll> S(3);

  for (int i = 1; i <= H - 1; i++) {
    S[0] = i * W;
    if (H - i >= 2) {
      S[1] = (H - i) / 2 * W;
      S[2] = (H - i - (H - i) / 2) * W;
      ans = min(ans, diff(S));
    }
    S[1] = (H - i) * (W / 2);
    S[2] = (H - i) * (W - W / 2);
    ans = min(ans, diff(S));
  }

  for (int i = 1; i <= W - 1; i++) {
    S[0] = H * i;
    if (W - i >= 2) {
      S[1] = H * ((W - i) / 2);
      S[2] = H * (W - i - (W - i) / 2);
      ans = min(ans, diff(S));
    }
    S[1] = (H / 2) * (W - i);
    S[2] = (H - H / 2) * (W - i);
    ans = min(ans, diff(S));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if a == b + c:
        print("Yes")
    elif b == a + c:
        print("Yes")
    elif c == a + b:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N =1e3+5 , M = 3e5+5, OO = 0x3f3f3f3f, mod = 1e9+7;
const double EPS = 1e-3;
#define M_PI 3.14159265358979323846
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define fori(i,m) for(int i=0;i<(int)(m);++i)
#define for2(i,n,m) for(int i=n;i<(int)(m);++i)
#define sc1(n) scanf("%d",&n)
#define sc2(n,m) scanf("%d %d",&n,&m)
#define pf(n) printf("%lld\n",n)
#define all(v) ((v).begin()) , ((v).end())
#define sz(v)  ((int)((v).size()))
typedef vector<int> vi;

int r;

int main(){

  scanf("%d", &r);
  int ans = 3*r*r;
  printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char s[3];
    int count=0;
    scanf("%s", s);
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') printf("%d", 3);
    else if(s[0]=='R'&&s[1]=='R') printf("%d", 2);
    else if(s[1]=='R'&&s[2]=='R') printf("%d", 2);
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R') printf("%d", 1);
    else printf("%d", 0);
    return 0;
}

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

int main() {
    int n;
    cin >> n;
 
    double  inv = 0;
    for(int i = 0; i < n; i++){
        double a;
        cin >> a;
        inv += 1 / a;
    }
    double inv_sum;
    inv_sum = 1 / inv;
    cout << inv_sum << endl;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

string S;
int n;

void fail() {
	cout << -1;
	exit(0);
}

int main() {
	cin >> S;
	n = S.length();
	S = 'A' + S;
	
	if (S[n] == '1' or S[1] == '0') fail();
	for (int i =2;i <= n/2;i++) {
		//cout << i << "\n";
		if (S[i] != S[n-i]) fail();
	}

	int co = 3;
	int curn = 2;
	cout << 1 << " " << curn << "\n";
	for (int i = 2;i < n; i++) {
		if (S[i] == '1') {
			cout << curn << " " << co++ << "\n";
			curn = co-1;
		} else cout <<	curn << " " << co++ << "\n";
	}
}


Measured memory_bytes: 1660
a,b,c,x,y = map(int,input().split())
ans = 2000000000
if x >= y:
    cnt = 0
    cnt += y * 2 * c
    cnt += (x - y) * a
    ans = min(ans,cnt)
else:
    cnt = 0
    cnt += x * 2 * c
    cnt += (y - x) * b
    ans = min(ans,cnt)
ans = min(ans, a * x + b * y)
ans = min(ans, max(x,y) * 2 * c)
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_150a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            if (input[0]*500 >= input[1])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27304
#include<stdio.h>
#include<stdlib.h>

typedef struct directedGraph{
  int *vertex;
  int *next;
  int *start;
  int v,e;
  int pointer;
} graph;

graph* newGraph(const int v,const int e){
  graph *g=(graph *)malloc(sizeof(graph));
  g->vertex=(int *)calloc(e,sizeof(int));
  g->next=(int *)calloc(e,sizeof(int));
  g->start=(int *)calloc(v,sizeof(int));
  for(int i=0;i<v;i++) g->start[i]=-1;
  g->v=v;
  g->e=e;
  g->pointer=0;
  return g;
}

void freeGraph(graph *g){
  free(g->vertex);
  free(g->next);
  free(g->start);
  free(g);
  return;
}

void addEdge(graph *g,const int from,const int to){
  const int p=g->pointer;
  g->vertex[p]=to;
  g->next[p]=g->start[from];
  g->start[from]=p;
  g->pointer++;
  return;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  graph *g=newGraph(n,n-1+m);
  int i;
  for(i=0;i<n-1+m;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;
    b--;
    addEdge(g,a,b);
  }
  int *parent=(int *)calloc(n,sizeof(int));
  int *cnt=(int *)calloc(n,sizeof(int));
  int *q=(int *)calloc(n,sizeof(int));
  for(i=0;i<n;i++){
    for(int p=g->start[i];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      cnt[u]++;
    }
  }
  int front=0;
  int last=0;
  for(i=0;i<n;i++) if(cnt[i]==0) q[last++]=i;
  parent[q[0]]=-1;
  while(last<n){
    int v=q[front++];
    for(int p=g->start[v];p!=-1;p=g->next[p]){
      int u=g->vertex[p];
      cnt[u]--;
      if(cnt[u]==0){
	parent[u]=v;
	q[last++]=u;
      }
    }
  }
  for(i=0;i<n;i++) printf("%d\n",parent[i]+1);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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 Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

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

    int xor_sum = a[0];
    rep(i,N){
        if (i == 0) continue;

        xor_sum = xor_sum ^ a[i];
    }
    int ans;
    rep(i,N){
        ans = xor_sum ^ a[i];
        cout << ans << endl;
    }

}

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

struct edge {
    ll to;
    ll cost;
};

using P = pair<ll, ll>;	// <最短距離, 頂点の番号>
void dijkstra(vector<vector<edge>> &g, vector<ll> &dist, ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    dist.assign(dist.size(), 1LL<<60);
    dist[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (dist[v] < p.first) continue;
        for (ll i=0; i<g[v].size(); ++i) {
            edge e = g[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
	ll n;
	cin >> n;
	vector<vector<edge>> g(n);
	rep(i, n-1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	ll Q, k;
	cin >> Q >> k;
	k--;
	vector<ll> dist(n);
	dijkstra(g, dist, k);
	rep(q, Q) {
		ll x, y;
		cin >> x >> y;
		x--; y--;
		ll ans = dist[x] + dist[y];
		printf("%lld\n", ans);
	}
	return 0;
}

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

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

    double ll = l;
    ll /= 3;
    cout << fixed << setprecision(10) << ll*ll*ll;
}

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

using namespace std;

int nbdays;
int activities[100000][3];
int bestscore[100000][3];

signed main()
{
    ios::sync_with_stdio(false);
    cin>>nbdays;
    for(int i = 0 ; i < nbdays ; i++)
    {
        cin>>activities[i][0];
        cin>>activities[i][1];
        cin>>activities[i][2];
    }
    bestscore[nbdays-1][0]=activities[nbdays-1][0];
    bestscore[nbdays-1][1]=activities[nbdays-1][1];
    bestscore[nbdays-1][2]=activities[nbdays-1][2];
    for(int i = nbdays-2 ; i>=0 ; i--)
    {
        for(int j = 0 ; j < 3 ; j++)
        {
            bestscore[i][j]=activities[i][j];
            int maxi = -1;
            for(int k = 0 ; k < 3 ; k++)
            {
                if(k!=j)
                {
                    maxi = max(maxi,bestscore[i+1][k]);
                }
            }
            bestscore[i][j]+=maxi;
        }
    }
    cout<<max(bestscore[0][0],max(bestscore[0][1],bestscore[0][2]));
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9


int main(){
  int N, sum = 0;
  cin >> N;
  vector<int> A(N+2,0), cost(N+2, 0);
  REP(i, N){
    cin >> A[i+1];
    cost[i+1] = abs(A[i] - A[i+1]);
    sum += cost[i+1];
  }
  cost[N+1] = abs(A[N] - A[N+1]);
  sum += cost[N+1];
  FOR(i, 1, N+1){
    cout << sum - cost[i] - cost[i+1] + abs(A[i-1] - A[i+1]) << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld%ld", &n, &k);
    n--;

    long bad[10]={0};
    long i;
    for(i=0; i<k; i++) {
        long  tmp;
        scanf("%ld", &tmp);
        bad[tmp]=1;
    }

    vector<long> a;
    long curr=n;
    while(curr) {
        a.push_back(curr%10);
        curr /= 10;
    }

    long siz=(long)a.size();
    long bb=-1;
    for(i=0; i<siz; i++) {
        if(bad[a[i]]) bb = i;
    }

    for(i=0; i<=siz; i++) {
        if(i==siz) {
            a.push_back(0);
        }
        long m;
        if(i>=bb) {
            for(m=1; m<10; m++) {
                if(bad[m]==0 && m>a[i])
                    break;
            }
            if(m<10) {
                a[i]=m;
                break;
            }
        }

        for(m=0; m<10; m++) {
            if(bad[m]==0)
                break;
        }
        a[i]=m;
    }

    long tmp=0;
    for(i=a.size()-1; i>=0; i--) {
        tmp = tmp*10 + a[i];
    }
    printf("%ld\n", tmp);
 
    return 0;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%d",$n);
  if($n==1){
    echo 'Hello World';
  }
  elseif($n==2){
    fscanf(STDIN,"%d",$a);
    fscanf(STDIN,"%d",$b);
    $ans=$a+$b;
    echo $ans;
  }
?>

Measured memory_bytes: 4728
a = []
i = 0
n = 0
calc = 0

while True:
    a.append(list(map(int, input().split())))
    if a[n][0] == -1 and a[n][1] == -1 and a[n][2] == -1:
        break
    n += 1

while i < n:
    calc = a[i][0] + a[i][1]

    if a[i][0] < 0 or a[i][1] < 0:
        print("F")
    else:
        if calc >= 80:
            print("A")
        elif calc >= 65 and calc < 80:
            print("B")
        elif calc >= 50 and calc < 65:
            print("C")
        elif calc >= 30 and calc < 50:
            if a[i][2] >= 50:
                print("C")
            else:
                print("D")
        elif calc < 30:
            print("F")
    i += 1


Measured memory_bytes: 5608
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;

int main(void){
  int H, W;
  char S[100][100];
  int cnt;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> S[i][j];
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(S[i][j] == '.'){
        cnt = 0;
        for(int x = i - 1; x <= i + 1; x++){
          for(int y = j - 1; y <= j + 1; y++){
            if(S[x][y] == '#') cnt++;
          }
        }
        S[i][j] = cnt + '0';
      }
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << S[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,sum=0;
  cin >> n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        sum+=gcd(k,gcd(i,j));
      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3564
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args){
        int N = nextInt();

        int[] d = new int[N];
        for(int i=0; i<N; i++){
            d[i] = nextInt();
        }

        Arrays.sort(d);

        int middle = N/2-1;
        int min = d[middle];
        int max = d[middle+1];

        int scope = min<=max ? max-min : 0;

        println(scope);
    }

    //各桁の和
    public static int sumDigits(long n) {
        int sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;//合計を返す
    }

    //最大公約数gcd
    static long gcd (long a, long b) {
        long temp;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return b;
    }
    //最小公倍数lcm
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }
    static int nextInt(){
        return Integer.parseInt(next());
    }
    static Long nextLong(){
        return Long.parseLong(next());
    }
    static String next(){
        return sc.next();
    }
    static void println(Object o){
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
}


Measured memory_bytes: 50364
import sys
z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j)
input()
for s in sys.stdin:
 s=s.strip()
 k=f()
 print(s.translate(str.maketrans(''.join(e(c,*k)for c in z),z)))


Measured memory_bytes: 5572
//MLE
#include <cstdio>
#include <map>
using namespace std;

int mp[144], m, n, hs, ch;
int dir[] = { -12, -1, 1, 12 };
map<int,int> memo;

int func( int p, int d, int u ){
	while(1){
		int h = mp[p];
		if( h >= 0 ){
			int s = 0;
			mp[p] = -1;
			hs ^= 1 << h;
			if( u > 10 ){
				for(int i = 0; i < 4; i++ )
					s += func( p + dir[i], dir[i], u - 1 );
			}else{
				int mi = h << 23 | hs;
				map<int,int>::iterator it = memo.find(mi);
				if( it == memo.end() ){
					for(int i = 0; i < 4; i++ )
						s += func( p + dir[i], dir[i], u - 1 );
					memo[mi] = s;
				}else{
					s = it->second;
				}
			}
			hs |= 1 << h;
			mp[p] = h;
			return s;
		}
		if( h == -9 )break;
		p += d;
	}
	return 0;
}

int main(void){
	int i,j,p,t;
	for(; scanf("%d%d",&m,&n),m;){
		hs = 0;
		memo.clear();
		for( i = 0; i < 144; i++ ) mp[i] = -9;
		for( i = 1; i <= n; i++ )
			for( j = 1; j <= m; j++ ){
				p = i * 12 + j;
				scanf("%d",&t);
				switch( t ){
					case 2:
						ch = p;
					case 0:
						mp[p] = -1; break;
					case 1:
						memo[hs<<23] = 0;
						mp[p] = hs++;
						break;
				}
			}
		for( i = 0; i < 4; i++ ){
			t = dir[i];
			for( j = ch; mp[j+=t] != -9; )
				if( mp[j] >= 0 )memo[ mp[j]<<23 ] = 1;
		}
		j = hs;
		hs = ( 1 << hs ) - 1;
		t = 0;
		for( i = 0; i < 4; i++ ){
			t += func( ch + dir[i], dir[i], j );
		}
		printf("%d\n", t );
	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int32> cnt(n+1,0);
  REP(i,n-1){
    cnt[i+1] = cnt[i];
    if(s[i] == 'A' && s[i+1] == 'C')cnt[i+1]++;
  }
  REP(i,q){
    int32 l,r;
    cin >> l >> r;
    ANS(cnt[r-1] - cnt[l-1]);
  }
  return 0;
}

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

const int N = 2002, mod = 1e9+7;
int c[N][N];
int main(){

    int n, k;
    int i, j;
    cin>>n>>k;


    for(i = 0; i<=n+1; i++){
        c[i][0] = 1;
        for(j=1; j<=i; j++){
            c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
        }
    }

    for(i=1; i<=k; i++){
        int ans = 1ll * c[k-1][i-1] * c[n-k+1][i] % mod;
        cout<<ans<<endl;

    }
    return 0;
}

Measured memory_bytes: 15104