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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;

#define deb(x) cerr<<#x<<":"<<x<<"\n";
#define dvi(x) for(ll i=0;i<x.size();i++)cerr<<#x<<"["<<i<<"]:"<<x[i]<<" ";
#define iter(v) for(auto it:v)
#define wt ll t;cin>>t;while(t--)
#define rl(x) ll x;cin>>x;
#define rvi(x,n) vi x(n);for(ll i=0;i<n;i++) cin>>x[i];
#define rs(x) string x;cin>>x;
#define w(x) cout<<x<<endl;
#define wvi(x) for(ll i=0;i<x.size();i++) cout<<x[i]<<" ";cout<<endl;
#define ws(x) cout<<x<<endl;
#define all(v) v.begin(),v.end()
#define pb push_back
#define ppb pop_back
#define pll pair<ll, ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
const ll N = 1e9+7;

map<long long, long long> factorize(long long n) {	//returns map containing factor and multiplicity, Eg: 60 = {{2,2},{3,1},{5,1}}
	map<long long, long long> ans;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans[i]++;
			n /= i;
		}
	}
	if (n > 1) {
		ans[n]++;
		n = 1;
	}
	return ans;
}

void FAST() {	//FAST Input Output, DONT use both scnaf,prllf / cin,cout , Use any ONE system
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll nCrModp(ll n, ll r, ll p) 
{ 
    // Optimization for the cases when r is large 
    if (r > n - r) 
        r = n - r; 
  
    // The array C is going to store last row of 
    // pascal triangle at the end. And last entry 
    // of last row is nCr 
    vi C(r+1); 
  
    C[0] = 1; // Top row of Pascal Triangle 
  
    // One by constructs remaining rows of Pascal 
    // Triangle from top to bottom 
    for (ll i = 1; i <= n; i++) { 
  
        // Fill entries of current row using previous 
        // row values 
        for (ll j = min(i, r); j > 0; j--) 
  
            // nCj = (n-1)Cj + (n-1)C(j-1); 
            C[j] = (C[j] + C[j - 1]) % p; 
    } 
    return C[r]; 
} 

ll nCrModpLucas(ll n,ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
   // Compute last digits of n and r in base p 
   ll ni = n%p, ri = r%p; 
  
   // Compute result for last digits computed above, and 
   // for remaining digits.  Multiply the two results and 
   // compute the result of multiplication in modulo p. 
   return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r 
           nCrModp(ni, ri, p)) % p;  // Remaining digits 
} 

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt","w", stdout);
    #endif
	FAST();
	rl(s)
	ll r=s/3;
	ll ans=0;
	forr(i,1,r+1)
	{
		ans+=nCrModpLucas(s-(2*i)-1,i-1,N);
		ans%=N;
	}	
	cout<<ans%N;
}

Measured memory_bytes: 3676
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,m,s[2]; Edg
bool gg=0;
int col[SZ];
void dfs(int x)
{
	++s[col[x]];
	for esb(x,e,b)
	{
		int g=col[x]^1;
		if(col[b]!=-1&&col[b]!=g) gg=1;
		else if(col[b]==-1) col[b]=g, dfs(b);
	}
}
int main()
{
	memset(col,-1,sizeof col); col[1]=0;
	scanf("%d%d",&n,&m);
	for(int i=1,a,b;i<=m;++i)
		scanf("%d%d",&a,&b),adde(a,b);
	dfs(1);
	ll ans=gg?((ll)n*(n-1)/2):((ll)s[0]*s[1]);
	printf("%lld\n",ans-m);
}


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

int main()
{
  int N,i ;
  cin>>N ;
  int V[N],C[N] ;
  for(i=0;i<N;i++) cin>>V[i] ;
  for(i=0;i<N;i++) cin>>C[i] ;
  
  int max ;
  for(i=0;i<N;i++) if((V[i]-C[i])>0) max+=(V[i]-C[i]) ;
  
  cout<<max<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  static final Scanner in = new Scanner(System.in);
  static int N, K;

  static int[] a;
  static boolean dp[];

  public static void main(String[] args) throws Exception {
    N = in.nextInt();
    K = in.nextInt();
    a = new int[N];
    dp = new boolean[K + 1];

    for (int i = 0; i < N; i++) a[i] = in.nextInt();

    G();
    if (dp[K]) 
        System.out.println("First"); 
    else 
        System.out.println("Second");
  }

  static void G() {

    for (int k = a[0]; k <= K; k++) {

      boolean win_state = false;

      for (int i = 0; i < N; i++) {
        if (k < a[i]) 
            break;

        if (!dp[k - a[i]]) 
            win_state = true;
      }

      dp[k] = win_state;

    }
  }
}


Measured memory_bytes: 36520
// :(((
// g & h for subtitle
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ld long double
const int maxn = 2e5 + 10 , mod = 1e9 + 7;

ll n;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	cout << ( (n + 999) / 1000 )*1000 - n << endl;
	return 0;	
}


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

int main(){
    int a;
    cin >> a;
    if(a == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep2(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
//const ll mod = 1e9+7;
int gcd(int a, int b){if(a<b) swap(a,b); if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

ll N, M, K, H, W, L, R;

int main(){
  cin >> N;
  vi X(N), Y(N);
  rep(i,N){
    cin >> X[i];
    Y[i]=X[i];
  }
  sort(all(Y));
  int m = Y[N/2-1], n = Y[N/2];
  
  rep(i,N){
    if(X[i]<=m) cout << n << endl;
    else cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 4740
import java.util.Scanner;
public class Main {

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

		long h = stdIn.nextLong();
		long w = stdIn.nextLong();
		
		long cnt = 0;
		if(h==1 || w == 1) {
			System.out.println(1);
			return;
		}
		
		if(h % 2 == 0 && w % 2 == 0) { //h偶数、w偶数
			for(int i = 0; i < h; i++) {
				cnt += w/2;
			}
		}else if(h % 2 == 0 && w % 2 != 0) { //h偶数、w奇数
			for(int i = 0; i < h ; i++) {
				if(i % 2 == 0) {
					cnt += (w+1)/2;
				}else {
					cnt += w/2;
				}
			}
		}else if( h % 2 != 0 && w % 2 == 0) { // h奇数,w偶数
			for(int i = 0; i < h; i++) {
				cnt += w/2;
			}
		}else {                                //h奇数,w奇数
			for(int i = 0; i < h ; i++) {
				if(i % 2 == 0) {
					cnt += (w+1)/2;
				}else {
					cnt += w/2;
				}
			}
		}

		System.out.println(cnt);

	}

}


Measured memory_bytes: 21716
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

const ll INF = ll(1e18)+1;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll l=-INF, r=INF;
    while(l+1<r){
        ll x = (l+r)/2;
        bool ok = [&]{
            ll tot=0;
            rep(i,n){
                if(a[i]>=0){
                    int l=-1, r=n;
                    while(l+1<r){
                        int c = (l+r)/2;
                        if(a[c]*a[i]<x) l=c; else r=c;
                    }
                    tot += r;
                }else{
                    int l=-1, r=n;
                    while(l+1<r){
                        int c = (l+r)/2;
                        if(a[c]*a[i]<x) r=c; else l=c;
                    }
                    tot += n-r;
                }

                if(a[i]*a[i]<x) tot--;
            }
            tot /= 2;
            return tot < k;
        }();
        if(ok) l=x; else r=x;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 1920
<?php
  $input = trim(fgets(STDIN));
  $input = str_replace(array("\r\n", "\r", "\n"), "", $input);
  $array = explode(" ", $input);

  $sum = 0;
  for( $i = 1; $i <= $array[0]; $i++){
    $input_num = str_split($i);
    $num = array_sum($input_num);
    
    if( $num >= $array[1] && $num <= $array[2]){
      $sum+=$i;
    }
  }
  
  echo $sum;
?>

Measured memory_bytes: 3576
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;
long long MOD = 1000000007;

//逆元計算
long long modinv(long long a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

int main() {
	long long n, k;
	long long a[5000];
	long long b[5000];
	long long d[5000];
	long long ans;
	long long temp;

	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = 0;
	}
	for (int i = n; i < 2 * n; i++) {
		a[i] = a[i - n];
		b[i] = 0;
	}


	for (int i = 2 * n - 1; i >= 1; i--) {
		for (int j = i - 1; j >= 0; j--) {
			if (a[i] < a[j]) {
				b[i]++;
			}
		}
	}

	ans = 0;

	for (int i = 0; i < n; i++) {
		d[i] = b[i + n] - b[i];
		//cout << b[i] << " " << b[i + n] << " " << d[i] << endl;
		ans += ((b[i] + ((b[i] + d[i] * (k - 1)) % MOD)) * k % MOD) * modinv(2);
		ans = ans % MOD;
	}

	if (ans < 0) {
		ans += MOD;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }

int n, a[17][17];
ll cost[1 << 16];

int main(){
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> a[i][j];
    for(int mask = 0; mask < (1 << n); mask++){
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                if((mask & (1 << i)) && (mask & (1 << j)))
                    cost[mask] += a[i][j];
            }
        }
    }
    for(int mask = 0; mask < (1 << n); mask++){
        for(int sbmask = mask; sbmask > 0; sbmask = (sbmask - 1) & mask){
            cost[mask] = max(cost[mask], cost[sbmask] + cost[mask ^ sbmask]); 
        }
    }
    cout << cost[(1 << n) - 1];
}

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

template <class T>
vector<int> z_algorithm(const T &s) {
  vector<int> res;
  int i = 1, j = 0, ssize = s.size();
  res.resize(s.size());
  res[0] = ssize;
  while (i < ssize) {
    while (i + j < ssize && s[j] == s[i + j]) ++j;
    res[i] = j;
    if (j == 0) {
      ++i;
      continue;
    }
    int k = 1;
    while (i + k < ssize && k + res[k] < j) res[i + k] = res[k], ++k;
    i += k, j -= k;
  }
  return res;
}

int n, m;
string s, t, ts;
vector<int> memo;

int solve();

int main() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
  {
    string tmp = s;
    s += s;
    while (s.size() < 2 * m) s += tmp;
  }
  ts = t + '#' + s;
  memo = z_algorithm(ts);
  cout << solve() << endl;
  return 0;
}

int solve() {
  int res = 0;
  vector<int> cnt(n, -1);
  for (int i = 0; i < n; ++i)
    if (cnt[i] < 0) {
      vector<int> v(1, i);
      while (cnt[v.back()] < 0 && memo[v.back() + m + 1] == m) {
        int nxt = (v.back() + m) % n;
        if (nxt == i) return -1;
        v.push_back(nxt);
      }
      int now = 0;
      if (cnt[v.back()] < 0) cnt[v.back()] = 0;
      now = cnt[v.back()];
      while (v.size()) {
        cnt[v.back()] = now;
        v.pop_back();
        ++now;
      }
      res = max(res, cnt[i]);
    }
  return res;
}

Measured memory_bytes: 19896
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);

template<class T> inline T sqr(T x) {return x*x;}

int main() {
	int n;
	cin >> n;
	int i = 0;
	LL sum = 0;
	for (; sum < n; ++i) {
		sum += i;
		//cout << i << " " << sum << endl;
	}
	--i;
	//cout << i << endl;
	while (n > 0 && i >= 0) {
		if (i <= n) {
			cout << i << endl;
			n -= i;
		}
		--i;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
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; }



int main() {
  int N;
  cin >> N;
  vector<int> b(N);
  rep(i, 0, N) cin >> b[i];
  vector<int> a;
  rep(i, 0, N) {
    bool f = false;
    rem(j, b.size() - 1, 0) {
      if(b[j] == j + 1) {
        a.push_back(b[j]);
        b.erase(b.begin() + j);
        f = true;
        break;
      }
    }
    if(!f) break;
  }
  reverse(a.begin(),a.end());
  if(a.size() != N) cout << -1 << endl;
  else rep(i, 0, N) cout << a[i] << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
  
list($n, $k) = explode(' ', trim(fgets(STDIN)));

if ($n >= $k){
  $c = ($n-$k+1) / $n;
  $ns = $k-1;
} else {
  $c = 0;
  $ns = $n;
}

$a = 0;
for($i=1; $i<=$ns; $i++){
	$ki = $k/$i;
  
    $kl = ceil(log($ki,2));
    $a += 1/$n * 0.5**$kl;
}

echo $c + $a;


?>

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

int main()
{
	int N;

	cin >> N;

	int B[N];

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

	long long int A[N + 1];

	A[1] = B[1];

	for (int i = 2; i <= N - 1; i++)
	{
		if (B[i - 1] < B[i])
		{
			A[i] = B[i - 1];
		}
		else
		{
			A[i] = B[i];
		}
	}

	A[N] = B[N - 1];

	long long int Asum = 0;

	for (int i = 1; i <= N; i++)
	{
		Asum += A[i];
	}

	cout << Asum << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

max_height = 0
ans = 0
for i in range(N):
    if A_list[i] > max_height:
        max_height = A_list[i]
    else:
        ans += max_height - A_list[i]
print(ans)

Measured memory_bytes: 32236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b != c) {
        cout << "Yes\n";
    }
    else if (a == c && c != b) {
        cout << "Yes\n";
    }
    else if (b == c && b != a) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main() {
    string s;
    ll k;
    cin>>s>>k;
    for(int i=0; i<s.size(); i++){
        int t=(26-(s[i]-'a'))%26;
        if(t<=k){
            k-=t;
            s[i]='a';
        }
    }
    s[s.size()-1]=(char) ( (k+s[s.size()-1]-'a')%26 + 'a' ) ;
    cout<<s<<endl;
}


Measured memory_bytes: 512
# include <bits/stdc++.h>
using namespace std;
# define lli long long int
# define mod 1000000007


lli findMinCost(lli n, lli arr[]){
	lli dp[n + 1] = {0};
	dp[2] = abs(arr[1] - arr[0]);
	for(lli i = 3; i <= n; i++){
		dp[i] = min(dp[i - 1] + abs(arr[i - 1] - arr[i - 2]),
			dp[i - 2] + abs(arr[i - 1] - arr[i - 3]));
	}
	return dp[n];
}

void solve(){
	lli n;
	cin >> n;
	lli i, arr[n];
	for(i = 0; i < n; i++) cin >> arr[i];

	cout << findMinCost(n, arr);
}

int main(){
	solve();
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int m,n,i,j;
    char a[100][100];
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%s",a[i]);
    int flag=1,cnt=0;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            cnt=0;
            if(a[i][j]=='#')
            {
                if(i-1>=0&&a[i-1][j]=='#')
                    cnt++;
                if(j-1>=0&&a[i][j-1]=='#')
                    cnt++;
                if(i+1<n&&a[i+1][j]=='#')
                    cnt++;
                if(j+1<m&&a[i][j+1]=='#')
                    cnt++;
                if(cnt==0) {flag=0;break;}
            }
        }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;

}



Measured memory_bytes: 128
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#define endl codeforces
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

int main() {
    ll k;
    std::cin >> k;
    ll ans = 0;
    for (ll a = 1; a <= k; a++) for (ll b = 1; b <= k; b++) {
        ll g = std::gcd(a, b);
        for (ll c = 1; c <= k; c++) {
            ll gg = std::gcd(g, c);
            ans += gg;
        }
    }
    std::cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] t_a = Console.ReadLine().Split(' ');
            string[] h_list = Console.ReadLine().Split(' ');
            int t = int.Parse(t_a[0]);
            int a = int.Parse(t_a[1]);
            double diff_min = 0;
            int ans_index = 0;

            for (var i = 0; i < n;i++)
            {
                double i_temp = t - int.Parse(h_list[i])*0.006;
                double diff = Math.Abs(a - i_temp);

                if ( i == 0 || diff < diff_min) 
                {
                    diff_min = diff;
                    ans_index = i;
                }
            }

            Console.WriteLine(ans_index + 1);


        }
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define SZ(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
using namespace std;

typedef long long ll;
typedef pair<int,int> PI;
typedef unsigned long long ull;

#define PR(...) do{cerr << "line : " << __LINE__ << endl; pr(#__VA_ARGS__, __VA_ARGS__);}while(0);
template<class T>
void pr(const string& name, T t){
  cerr << name << ": " << t << endl;
}

template<typename T, typename ... Types>
void pr(const string& names, T t, Types ... rest) {
  auto comma_pos = names.find(',');
  cerr << names.substr(0, comma_pos) << ": " << t << ", ";
  
  auto next_name_pos = names.find_first_not_of(" \t\n", comma_pos + 1);
  pr(string(names, next_name_pos), rest ...);
}

template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
template<class T> ostream& operator<< (ostream& o, const set<T> &v){o << "{";for(auto e : v) o << e << ", ";return o << "}";}
template<class T, class U> ostream& operator<< (ostream& o, const map<T,U> &v){o << "{";for(auto e : v) o << e.F << ": " << e.S << ", ";return o << "}";}

//                < v > ^
const int dx[] = {0,1,0,-1, 1, 1, -1, -1};
const int dy[] = {-1,0,1,0, 1, -1, 1, -1};
#define endl '\n'


int main(int argc, char *argv[])
{
  int n, k ;
  cin >> n >> k;
  int ok[10] = {};
  rep(i, k){
    int d;
    cin >> d;
    ok[d] = 1;
  }

  while(true) {
    stringstream ss;
    ss << n;
    bool tok = true;
    for (auto i : ss.str()) {
      tok &= !ok[i - '0'];
    }
    if (tok){ 
      cout << n << endl;
      return 0;
    }
    ++n;
  }
  return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  int ch,dh,cw,dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;cw--;dh--;dw--;
  string s[h];
  rep(i,h)cin >> s[i];
  int flag[h][w];
  rep(i,h)rep(j,w)flag[i][j] = INF;
  int nexth[4] = {-1,0,1,0};
  int nextw[4] = {0,-1,0,1};
  queue<pair<int,int>> que;
  queue<pair<int,int>> nque;
  que.push({ch,cw});
  flag[ch][cw] = 0;
  int iter = 0;
  while(que.empty()==0){
    while(que.empty()==0){
      pair<int,int> tmp = que.front();
      que.pop();
      int nowh = tmp.first, noww = tmp.second;
      nque.push({nowh,noww});
      iter = flag[nowh][noww];
      rep(i,4){
        int nh = nowh + nexth[i], nw = noww + nextw[i];
        if(nh<0 || nh>=h || nw<0 || nw>=w)continue;
        if(s[nh][nw]=='#')continue;
        if(flag[nh][nw] <= iter)continue;
        que.push({nh,nw});
        flag[nh][nw] = iter;
      }
    }
    while(nque.empty()==0){
      pair<int,int> tmp = nque.front();
      nque.pop();
      int nowh = tmp.first, noww = tmp.second;
      iter = flag[nowh][noww];
      for(int i=nowh-2;i<nowh+3;i++){
        for(int j=noww-2;j<noww+3;j++){
          if(i<0 || i>=h || j<0 || j>=w)continue;
          if(s[i][j]=='#')continue;
          if(flag[i][j] <= iter+1)continue;
          que.push({i,j});
          flag[i][j] = iter + 1;
        }
      }
    }
  }
  if(flag[dh][dw]==INF)cout << "-1" << endl;
  else cout << flag[dh][dw] << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

template<typename T>
class tRMQ {
  vector<T> data;
  T unit;

public:
  static const long long INF = 100000000000;
  int n;
  function<T(const T &, const T &)> f;

  tRMQ(int _, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < _) {
      n <<= 1;
    }
    data.resize(n * 4);
    for (int i = 0; i < n * 4; i++)
      data[i] = unit;
  }

  void update(int index, T val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if (a < 0 || r <= a || b <= l)
      return unit;
    if (a <= l && r <= b)
      return data[k];
    else
      return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (r + l) / 2, r));
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

tRMQ<ll> minrmq(int n) {
  return tRMQ<ll>(n, 10000000000000000LL, [](ll r, ll l) { return min(l, r); });
}

tRMQ<ll> maxrmq(int n) {
  return tRMQ<ll>(n, -10000000000000000LL,
                  [](ll r, ll l) { return max(l, r); });
}

tRMQ<ll> sumrmq(int n) {
  return tRMQ<ll>(n, 0, [](ll l, ll r) { return l + r; });
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  map<ll, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = 0;
  }
  int c = 1;
  for (auto &v : mp) {
    v.second = c++;
  }
  auto r = maxrmq(n + 3);
  r.update(0, 0);
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll b = r.query(0, mp[a[i]]) + 1;
    r.update(mp[a[i]] - 1, b);
    ans = max(ans, b);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11264
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 10007;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);

int dp[1001000],dp2[1001000];
vector<int> pollock, pollock2;
int main() {
	for (int i = 1;; i++) {
		LL num = i*(i + 1)*(i + 2)/6;

		if (num > 1000000)break;

		if (num % 2 == 1)pollock2.emplace_back(num);
		pollock.emplace_back(num);
	}
	//cout << 1 << endl;
	for (int i = 0; i < 1000000; i++) {
		dp[i] = dp2[i] = i;
	}
	//cout << 2 << endl;
	for (int i = 1; i < pollock.size(); i++) {
		for (int j = pollock[i]; j <= 1000000; j++) {
			dp[j] = min(dp[j], dp[j - pollock[i]] + 1);
		}
	}
	//cout << 3 << endl;
	for (int i = 1; i < pollock2.size(); i++) {
		for (int j = pollock2[i]; j <= 1000000; j++) {
			dp2[j] = min(dp2[j], dp2[j - pollock2[i]] + 1);
		}
	}
	//cout << 4 << endl;
	int n;
	while (cin >> n&&n) {
		cout << dp[n] << " " << dp2[n] << endl;
	}
}

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

long long n, m;
long long par[100000];
long long gs[100000];
long long inc;
vector<long long> result;

long long parent(long long node) {
    if (par[node] == node) {
        return node;
    }
    par[node] = parent(par[node]);
    return par[node];
}

bool areconnected(long long a, long long b) {
    return parent(a) == parent(b);
}

void connect(long long a, long long b) {
    long long au = parent(a);
    long long bu = parent(b);
    if (!areconnected(au, bu)) {
        long long gsa = gs[au];
        long long gsb = gs[bu];
        inc += gsa * gsb;
        gs[au] += gs[bu];
        par[bu] = au;
        assert(areconnected(au, bu));
    }
    result.push_back(inc);
}

int main() {

    cin >> n >> m;
    inc = 0;
    vector<pair<long long, long long> > qs;
    for (long long i=0; i<m; i++) {
        long long a, b;
        cin >> a >> b;
        qs.push_back(make_pair(a-1, b-1));
    }
    for (long long i=0; i<n; i++) {
        par[i] = i;
        gs[i] = 1;
    }
    reverse(qs.begin(), qs.end());
    for (long long i=0; i<m; i++) {
        long long a = qs[i].first, b = qs[i].second;
        connect(a, b);
    }
    reverse(result.begin(), result.end());
    for (long long i=1; i<m; i++) {
        cout << ((n) * (n-1) / 2) - result[i] << endl;
    }
    cout << ((n) * (n-1) / 2);

}


Measured memory_bytes: 6256
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	vector<vector<int>> cl(3);
	rep(i, 3) {
		rep(j, 3) {
			int c;
			cin >> c;
			cl[i].push_back(c);
		}
	}
	rep(a1, 101) {
		rep(a2, 101) {
			rep(a3, 101) {
				int b1 = -1, b2 = -1, b3 = -1;
				int pb1 = -1, pb2 = -1, pb3 = -1;
				bool isOK = true;
				rep(i, 3)
				{
					int a = 0;
					if (i == 0)
					{
						a = a1;
					}
					else if (i == 1) {
						a = a2;
					}
					else
					{
						a = a3;
					}
					b1 = cl[i][0] - a;
					b2 = cl[i][1] - a;
					b3 = cl[i][2] - a;
					if (i != 0 && !(pb1 == b1 && pb2 == b2 && pb3 == b3)) {
						isOK = false;
					}
					pb1 = b1;
					pb2 = b2;
					pb3 = b3;
				}
				if (isOK) {
					cout << "Yes" << endl;
					system("pause");
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n, y; cin >> n >> y;
	rep(i, n + 1){
		rep(j, n - i + 1){
			int k = n - i - j;
			if(i * 10000 + j * 5000 + k * 1000 == y){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
    using namespace std;
 
    typedef long long ll;
    typedef long double ld;
 
    typedef pair<int, int> pi;
    typedef pair<ll,ll> pl;

    typedef vector<int> vi;
    typedef vector<ll> vl;
    typedef vector<pi> vpi;
    typedef vector<pl> vpl;
    typedef vector<vi> vvi;

    #define FOR(i, a, b) for (int i=a; i<(b); i++)
    
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define lb lower_bound
    #define ub upper_bound
    #define all(x) x.begin(), x.end()
 
    template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
    template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
    
    #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
    #define PI 3.14159265358979323846264338327950L
    const int MOD = 1000000007;
    const char nl = '\n';
 
    int n,m,q,res=0;
    vi a,b,c,d,v;

    int check()
    {
        int sum=0;
        FOR(i,0,q)
        {
            if(v[b[i]]-v[a[i]] == c[i]) sum+=d[i];
        }

        return sum;

    }

    void dfs(int i,int curr)
    {
        if(i>=n)
        {
            res = max(res,check());
            return;
        }

        FOR(j,curr,m+1)
        {
            v.pb(j);
            dfs(i+1,j);
            v.pop_back();
        }
    
    }
    

    int main() 
    {
        ios_base::sync_with_stdio(0); cin.tie(0);
        cin>>n>>m>>q;
        
        a.resize(q);
        b.resize(q);
        c.resize(q);
        d.resize(q);

        FOR(i,0,q)
        {
            cin>>a[i]>>b[i]>>c[i]>>d[i];
            a[i]--,b[i]--;
        }

        dfs(0,1);

        cout<<res;

    }


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    FAST_IO();
    int N, K; cin >> N >> K;
    string S; cin >> S;
    S = "R" + S + "L";
    int happy = 0;
    repp(i, 1, N) {
        if(S[i] == 'L') happy += S[i - 1] == 'L';
        else happy += S[i + 1] == 'R';
    }
    cout << min(N - 1, happy + 2 * K);
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  int n; cin >> n;
  for (; n; --n) {
    int a, b, c; cin >> a >> b >> c;
    a = a * a;
    b = b * b;
    c = c * c;
    if (a + b == c || a + c == b || a == b + c) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1152
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd3(a, b, c int) int {
	d := gcd(a, b)
	return gcd(c, d)
}

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

	sum := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += gcd3(a, b, c)
			}
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 1776
#include <cstdio>
typedef long long ll;

int main() {
    ll k;
    scanf("%lld", &k);

    if (k == 0) {
        printf("2\n1 1\n");
    } else if (k == 1) {
        printf("2\n2 0\n");
    } else if (2 <= k && k <= 50) {
        printf("%lld\n", k);
        for (int i = 0; i < k; i++) {
            if (i) { printf(" "); }
            printf("%lld", k);
        }
        printf("\n");
    } else {
        ll quot = k / 50;
        ll rem  = k % 50;

        printf("50\n");
        for (int i = 0; i < 50; i++) {
            if (i) printf(" ");
            if (i < rem) {
                printf("%lld", (50 + quot - 1) + (50 - rem + 1));
            } else {
                printf("%lld", (50 + quot - 1) - rem);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    int N;
    cin >> N;
    vector<ll> L(N),R(N);
    rep(i,N) cin >> L[i] >> R[i];
    multiset<Pll> sl,sr;
    rep(i,N){
        sl.insert(Pll(L[i],i));
        sr.insert(Pll(R[i],i));
    }
    ll sum=0,now=0;
    bool right=true;
    while(!sl.empty()){
        if (right){
            Pll p=*sl.rbegin();
            ll next=p.first-now;
            if (next>0){
                sum+=next;
                now=p.first;
                sr.erase(sr.lower_bound(Pll(R[p.second],p.second)));
                sl.erase(sl.lower_bound(p));
                right=false;
            }
            else break;
        }
        else {
            Pll p=*sr.begin();
            ll next=now-p.first;
            if (next>0){
                sum+=next;
                now=p.first;
                sl.erase(sl.lower_bound(Pll(L[p.second],p.second)));
                sr.erase(sr.begin());
                right=true;
            }
            else break;
        }
    }
    sum+=abs(now);
    ll ans=sum;
    sl.clear(),sr.clear();
    rep(i,N){
        sl.insert(Pll(L[i],i));
        sr.insert(Pll(R[i],i));
    }
    sum=0,now=0;
    right=false;
    while(!sl.empty()){
        if (right){
            Pll p=*sl.rbegin();
            ll next=p.first-now;
            if (next>0){
                sum+=next;
                now=p.first;
                sr.erase(sr.lower_bound(Pll(R[p.second],p.second)));
                sl.erase(sl.lower_bound(p));
                right=false;
            }
            else break;
        }
        else {
            Pll p=*sr.begin();
            ll next=now-p.first;
            if (next>0){
                sum+=next;
                now=p.first;
                sl.erase(sl.lower_bound(Pll(L[p.second],p.second)));
                sr.erase(sr.begin());
                right=true;
            }
            else break;
        }
    }
    sum+=abs(now);
    chmax(ans,sum);
    cout << ans << endl;
}

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

int main(){
	int i,j,a[10],t;
	for(i=0;i<10;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<9;i++)
		for(j=i+1;j<10;j++)
			if(a[i]<a[j])
		   {
			  t=a[i];
			  a[i]=a[j];
			  a[j]=t;
		  }
	for(i=0;i<3;i++)
	{
		cout<<a[i]<<endl;
	}
    return 0;
}

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

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

using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  
  if(b%a==0){
    cout<<b+a;
  }else{
    cout<<b-a;
  }
  
  return 0;
}

Measured memory_bytes: 256
M = 1000000007
N = int(input())
A = list(map(int, input().split()))
count = [0 for i in range(N+1)]
count[N] = 3
ans = 1
for ai in A:
    ans = (ans * count[ai-1]) % M
    count[ai] += 1
    count[ai-1] -= 1
print(ans)

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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string S;
int main(){
  cin >> S;
  int N = S.size();
  bool ok = true;

  for (int i = 0; i < (N + 1) / 2; i++){
    char a = S[i];
    char b = S[N - 1 - i];
    if (a == 'b'){
      if (b != 'd')ok = false;
    }else if(a == 'd'){
      if (b != 'b')ok = false;
    }else if(a == 'p'){
      if (b != 'q')ok = false;
    }else if(a == 'q'){
      if (b != 'p')ok = false;
    }

		   
  }
  if (N == 1 or ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int get_pair_num(const vector<int>& v) {
    // v is sorted
    int prev = -1;
    int ans = 0;
    for(auto e: v) {
        if (e == prev) {
            ++ans;
            prev = -1;
        }
        else {
            prev = e;
        }
    }
    return ans;
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> Xs(N);
    REP(n,N) {
        cin >> Xs[n];
    }
    sort(ALL(Xs));


    vector<vector<int>> nums(M);
    REP(n,N) {
        int x = Xs[n];
        nums[x % M].pb(x);
    }

    ll ans = 0;
    REP(m, M / 2 + 1) {
        if (m == 0 || m * 2 == M) {
            ans += SIZE(nums[m]) / 2;
        }
        else {
            int n = M - m;
            auto size_m = SIZE(nums[m]);
            auto size_n = SIZE(nums[n]);
            ans += min(size_m, size_n);
            int pair_num = (size_m < size_n) ?
                get_pair_num(nums[n]) : 
                get_pair_num(nums[m]);
            ans += min(abs(size_m - size_n) / 2,
                       pair_num);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6144
import sys
S = input()[::-1]

length = len(S)
i = 0

while i < length:
    if S[i:i+5] == 'dream'[::-1]:
        i += 5
    elif S[i:i+7] == 'dreamer'[::-1]:
        i += 7
    elif S[i:i+5] == 'erase'[::-1]:
        i += 5
    elif S[i:i+6] == 'eraser'[::-1]:
        i += 6
    else:
        print('NO')
        sys.exit()
    
print('YES')



Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <utility>
using namespace std;

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

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

    int v, i, j;
    for (i = 1; i < n; i++)
    {

        for (j = 0; j < n - 1; j++)
            cout << a[j] << " ";
        cout << a[n - 1] << "\n";

        v = a[i];
        for (j = i - 1; j >= 0 && a[j] > v; j--)
        {
            a[j + 1] = a[j];
        }
        a[j + 1] = v;
    }

    for (j = 0; j < n - 1; j++)
        cout << a[j] << " ";
    cout << a[n - 1] << "\n";

    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  if(k%2==1) cout << (n/k)*(n/k)*(n/k) << endl;
  else {
    ll m=n/(k/2);
    cout << (m/2)*(m/2)*(m/2)+((m+1)/2)*((m+1)/2)*((m+1)/2) << endl;
  }
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:51 on 2019-09-01.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    rep(i, 3) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}



Measured memory_bytes: 256