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

int main(){
    int N, T;  cin >> N >> T;
    vector<pair<int, int>> D(N);
    for(int i=0; i<N; i++){
        cin >> D[i].first >> D[i].second;
    }
    sort(D.begin(), D.end(),[](const pair<int,int>& a, const pair<int,int>& b){
        return a.second < b.second;
    });
    vector<pair<int,int>> E(N);
    for(int i=0; i<N; i++){
        E[i] = D[N-1-i];
    }

    int maxT = T + 3000;
    vector<vector<int>> dp1(N+1, vector<int>(maxT + 1, 0));
    vector<vector<int>> dp2(N+1, vector<int>(maxT + 1, 0));
    for(int i=0; i<N; i++) for(int j=0; j<=maxT; j++){
        dp1[i+1][j] = dp1[i][j];
        dp2[i+1][j] = dp2[i][j];
        if(j >= D[i].first){
            dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j-D[i].first]+D[i].second);
        }

        if(j >= E[i].first){
            dp2[i+1][j] = max(dp2[i+1][j], dp2[i][j-E[i].first]+E[i].second);
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++) for(int j=0; j<=T-1; j++){
        ans = max(ans, dp1[i][j] + dp2[N-i-1][T-j-1] + D[i].second);
    }
    cout << ans << endl;
}   

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

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << #x " = " << (x) << '\n'
#define DBG         cerr << "Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

struct edgeData{
    int u, v, c;
};
bool operator < (edgeData a, edgeData b)
{
    return a.c < b.c;
}
vector<edgeData>V;
int A[310][310];
int main()
{
//    freopen("in.txt","r",stdin);
    int n;
    sf(n);
    LL sum = 0;
    for(int i = 1; i<=n; i++)
    {
        for(int j = 1; j<=n; j++)
        {
            sf(A[i][j]);
            if(i < j)
                sum += A[i][j], V.pb({i,j,A[i][j]});;
        }
    }
    sort(all(V));
    bool ok = true;
    for(auto e: V)
    {
        int u = e.u, v = e.v, c = e.c;
        bool need = true;
        for(int k = 1; k<=n; k++)
        {
            if(k == u || k == v)
                continue;
            if(A[u][k] + A[k][v] == c)
                need = false;
            else if(A[u][k] + A[k][v] < c)
            {
                ok = false;
                break;
            }
        }
        if(!ok)
            break;
        if(need == false)
            sum -= c;
    }
    if(!ok)
        puts("-1");
    else
        printf("%lld\n",sum);
    return 0;
}





Measured memory_bytes: 1276
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    quit()
s = 1
for x in a:
    s *= x
    # pythonずるくない？
    if s > 1000000000000000000:
        print(-1)
        quit()
print(s)


Measured memory_bytes: 87740
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    ll digit = 0;
    while (n >= (ll)pow(k, digit)) digit++;
    cout << digit << endl;
    return 0;
}

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

int main()
{
  int A, B, C;
  cin >> A>>B>>C;

  if(A==B) cout << C << endl;
  else if(B==C) cout << A << endl;
  else cout << B<< endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

const int MAX = 100005;

int n, a[MAX], l[MAX];

int lis() {
  l[0] = a[0];
  int length = 1;
  FOR(i, 1, n) {
    if (l[length-1] < a[i]) {
      l[length++] = a[i];
    }
    else {
      *lower_bound(l, l + length, a[i]) = a[i];
    }
  }
  return length;
}

int main() {
  cin >> n;
  rep(i, n) {
    cin >> a[i];
  }
  cout << lis() << endl;

  
  return 0;
}


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

long long min(long long x,long long y){
	if(x<y)return x;
	return y;
}

int compare(const void *a, const void *b){
	long long int *A = (long long int *)a;
	long long int *B = (long long int *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}

int main(){
	long long N,K,i,j,k,l,m;
	scanf("%lld%lld",&N,&K);
	long long x[N],y[N],xsort[N],ysort[N];
	for(i=0;i<N;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		xsort[i]=x[i];
		ysort[i]=y[i];
	}
	qsort(xsort,N,sizeof(long long),compare);
	qsort(ysort,N,sizeof(long long),compare);
	
	long long ans=(xsort[0]-xsort[N-1])*(ysort[0]-ysort[N-1]);
	
	for(i=0;i+K-1<N;i++){
		for(j=i+K-1;j<N;j++){
			for(k=0;k+K-1<N;k++){
				for(l=k+K-1;l<N;l++){
					long long c=0;
					for(m=0;m<N;m++)if(x[m]<=xsort[i] && x[m]>=xsort[j] && y[m]<=ysort[k] && y[m]>=ysort[l])c++;
					if(c>=K){
						ans=min(ans,(xsort[i]-xsort[j])*(ysort[k]-ysort[l]));
						break;
					}
				}
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;
ll mod = 998244353;

int main()
{
    int n, x, y;
    cin>> n >> x>>y;
    x--;y--;
    vector<int> table(n,0);
    rep(i, n) rep(j,i){
        int tmp = min(i-j, abs(x-i)+abs(y-j)+1);
        tmp = min(tmp,abs(x-j)+abs(y-i)+1);
        table[tmp]++;
    }
    repran(i, 1, n) cout << table[i] << endl;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int ans=0;
    for (int i = 0; i < n; i++) {
        int l,r;
        std::cin >> l >>r;
        ans+=r-l+1;
    }
    std::cout << ans << std::endl;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  std::string s;
  std::cin >> s;
  std::set<char> p;
  std::multiset<char> t;

  for (const auto i : s) {
    p.insert(i);
    t.insert(i);
  }

  if (p.size() == 2) {
    const auto c1 = *p.begin();
    auto itr = p.begin();
    itr++;
    const auto c2 = *itr;
    if (t.count(c1) == 2 && t.count(c2) == 2) {
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }
  std::cout << "No" << std::endl;
  return 0;
}


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

typedef long long ll;

int n;
ll a[100005];
__int128_t ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    ans=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        ans*=a[i];
        if(ans>1000000000000000000ll){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<(ll)ans<<endl;

    return 0;
}

Measured memory_bytes: 4428
#include <cstdio>
#include <iostream>
#define inf 3001

int main(){
	long long n,road[301][301],route[301][301];
	long long sum;
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++){
			scanf("%lld",&road[i][j]);
			route[i][j]=road[i][j];
		}
	bool flag=false;

    for(int k=0;k<n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++) {
                if(road[i][k]+road[k][j]<road[i][j]){
                	flag=true;
                }if(road[i][k]+road[k][j]==road[i][j]){
                	if((i!=k)&&(j!=k)){
                		route[i][j]=0;
                	}
                }
            }

    if(flag) printf("-1\n");
    else{
    for(int k=0;k<n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++) {
                if(road[i][k]+road[k][j]<road[i][j]){
                	flag=true;
                }if(road[i][k]+road[k][j]==road[i][j]){
                	if((i!=k)&&(j!=k)) route[i][j]=0;
                }
            }
    for(int i=0;i<n;i++){
    	for(int j=i;j<n;j++){
    		sum+=route[i][j];
    	}
    }
    printf("%lld",sum);
    }
    return 0;
}

Measured memory_bytes: 1664
#!/usr/bin/ruby
include Math

class Float  
  def round(d=0)
    x = 10**d
    if self < 0
      (self * x - 0.5).ceil.quo(x)
    else
      (self * x + 0.5).floor.quo(x)
    end
  end
end

gets.to_i.times do
  b = false
  x, y = gets.split.map!{|f| f.to_f }.partition{ b = !b }

  a = [x[1] - x[0], x[2] - x[0]].map!{|i| i * 2}
  b = [y[1] - y[0], y[2] - y[0]].map!{|i| i * 2}
  c = [x[0] ** 2 - x[1] ** 2 + y[0] ** 2 - y[1] ** 2, 
       x[0] ** 2 - x[2] ** 2 + y[0] ** 2 - y[2] ** 2]
  
  p = [b[0] * c[1] - b[1] * c[0], c[0] * a[1] - c[1] * a[0]]     
  p.map! {|i| i / (a[0] * b[1] - a[1] * b[0]) }
  
  r = sqrt((p[0] - x[0]) ** 2 + (p[1] - y[0]) ** 2) 
  
  printf("%.3f %.3f %.3f", p[0].round(3), p[1].round(3), r.round(3))
  puts
end

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
   string s,t,u;
   cin>>s>>t;
   int a,b;
   cin>>a>>b>>u;
   if(s==u) a--;
   else if(t==u) b--;
   cout<<a<<" "<<b<<endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,cnt[62];
string alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
int qry(string s){
	cout<<"? "<<s<<endl;
	int v; cin>>v; return v;
}
bool subsequence(string s){
	return (int)s.size()+qry(s)==n;
}
string combine(string a,string b){
	if(!a.size()||!b.size()) return a+b;
	string ret="";
	for(int i=0,j=0,s1=a.size(),s2=b.size();i<s1||j<s2;)
		if(i<s1&&(j==s2||subsequence(a.substr(0,i+1)+b.substr(j)))) ret+=a[i++];
		else ret+=b[j++];
	return ret;
}
string solve(int l,int r){
	if(l==r) return string(cnt[l],alphabet[l]);
	int mid=(l+r)>>1;
	return combine(solve(l,mid),solve(mid+1,r));
}
int main()
{
	for(int i=0;i<62;i++) cnt[i]=128-qry(string(128,alphabet[i])),n+=cnt[i];
	string ans=solve(0,61);
	cout<<"! "<<ans<<endl;
}

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

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

    for(int i = 1; i < 10; i++) {
        if(n % i == 0 && n / i < 10) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

int x, k, d;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> x >> k >> d;
    x = abs(x);
    int lo = x / d;
    int take = min(k, lo);
    x -= take * d;
    k -= take;
    int alt = abs(x - d);
    if(k & 1)
        cout << alt << "\n";
    else
        cout << x << "\n";
    return 0;
}

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

using namespace std;

bool ok(const vector<long long>& L, int i, int j, int k)
{
	if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) {
		return false;
	}
	vector<long long> v = { L[i], L[j], L[k] };
	sort(v.begin(), v.end());

	return v[0] + v[1] > v[2];
}

int main()
{
	int N;
	cin >> N;
	vector<long long> L(N);
	for (auto& x : L) {
		cin >> x;
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			for (int k = j + 1; k < N; ++k) {
				if (ok(L, i, j, k)) {
					++ans;
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_right
n,k,m = map(int,readline().split())
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

aa = [0]*(n+1)
bb = [0]*(k+1)
for i in range(n):
  aa[i+1] = aa[i]+a[i]
for i in range(k):
  bb[i+1] = bb[i]+b[i]
  
ans = 0
for num,i in enumerate(bb):
  M = m-i
  if M >= 0:
    ind = bisect_right(aa,M)
    ans = max(ans,num+ind-1)
  
print(ans)

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

int main()
{
    int H, A;
    cin >> H >> A;
    int res;
    if (H % A == 0)
        res = H / A;
    else
    {
        res = (H / A) + 1;
    }

    cout << res;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

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

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, m;
    cin >> n >> m;

    int i0 = 0, i1 = n;
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l--;

        i0 = max(i0, l);
        i1 = min(i1, r);
    }

    cout << max(i1 - i0, 0) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ll = long long;
using ull = unsigned long long;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


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


    ll num = ceil(n / 1000.0);
    cout << num * 1000 - n << newl;


    return 0;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
int dp[100001];
int main(){
	#ifdef EVAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int N,K;
	cin>>N>>K;
	int vet[N];
	for(int i=0;i<N;i++){
		cin>>vet[i];
	}
	fill(dp,dp+N,INT_MAX);
	dp[0]=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<K+i+1 && j<N;j++){
			dp[j]=min(dp[j],abs(dp[i]+abs(vet[i]-vet[j])));
		}
	}
	cout<<dp[N-1];
}


Measured memory_bytes: 1024
#include <iostream>

int main() {
  long A, B, X;

  std::cin >> A;
  std::cin >> B;
  std::cin >> X;

  if (A <= X && A+B >= X)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;

  return 0;
}


Measured memory_bytes: 256
/**
*    created: 24.06.2020 00:47:46
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int bit = 0; bit < (1 << (n-1)); bit++) {
        string s1 = "";
        int siz = 0;
        rep(i,n-1) {
            s1.insert(siz, s.substr(i,1));
            siz++;
            if ((bit >> i) & 1) {
                s1.insert(siz,"+");
                siz++;
            }
        }
        s1.insert(siz,s.substr(s.size()-1,1));
        int l = 0;
        int sum = 0;
        rep(i,s1.size()) {
            if (s1[i] != '+') continue;
            sum += stol(s1.substr(l,i-l));
            l = i+1;
        }
        sum += stol(s1.substr(l));
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int N;
    int c[10][10] = {};
    int ans = 0;
    cin >> N;
    for (int i = 1; i <= N; i++) c[to_string(i)[0] - '0'][i % 10]++;
    for (int a = 1; a <= 9; a++) {
        for (int b = 1; b <= 9; b++) {
            ans += c[a][b] * c[b][a];
        }
    }
    cout << ans << endl;
    return (0);
}

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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (1LL << 60);

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("template.1", "r", stdin);

  int N;
  cin >> N;
  vector<int> h(N + 2, 0);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  vector<ll> dp(N + 2, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    dumpv(dp);
    // if (i > 0) {
    //   dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    // }
    // if (i > 1) {
    //   dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    // }
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  dumpv(dp);
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] h = new int[n];
      for(int i=0;i<n;i++){
        h[i] = sc.nextInt();
      }
      long minx = 1000000001;
      Arrays.sort(h);
      for(int i=0;i<n-(k-1);i++){
        if(h[i+(k-1)]-h[i]<minx){
          minx = h[i+(k-1)]-h[i];
        }
      }
      System.out.println(minx);
    }
}


Measured memory_bytes: 50916
"""
NTC here
"""
import sys
inp = sys.stdin.readline
def input(): return inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())


def lin(): return list(map(int, input().split()))

# out = []
# range = xrange
# input = raw_input

def main():
    from math import gcd
    n = iin()
    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                ans += gcd(gcd(i, j), k)
    print(ans)

main()
# threading.Thread(target=main).start()


Measured memory_bytes: 67788
#include <bits/stdc++.h>
using namespace std;
signed main(){
    int n , p[100005] , ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    
    for(int i=0;i<n-1;i++){
        if(p[i] == i+1){
             ans++;
            swap(p[i],p[i+1]);
        }
    } if (p[n-1] == n){
        ans++;
    }
    cout<<ans<<endl;
    return(0);
}

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

lli k, s;

int main(void){
	cin >> k >> s;
	lli ans = 0;
	for(lli i = 0; i <= k; i++){
		for(lli j = 0; j <= k; j++){
			lli u = s-i-j;
			if(u >= 0 && u <= k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
N,K,*A = `dd`.split.map &:to_i
NK = N*K
AA = A + A
indexmap = {}
hop = Array.new(N,nil)
(0...N).reverse_each{ |i| indexmap[AA[N+i]] = N+i }
(0...N).reverse_each{ |i|
  hop[i] = (indexmap[AA[i]] + 1) - i
  indexmap[AA[i]] = i
}

orbit_s = 0
orbit_t = 0
k = 0
while true do
  d = hop[k]
  orbit_s += d
  orbit_t += 1
  k = (k + d) % N
  break if k == 0
end
$stderr.puts N,K,orbit_s,orbit_t

i = (NK/orbit_s)*orbit_s
ans = []
while i < NK do
  a = A[i % N]
  j = hop[i % N] + i
  if j <= NK
    i = j
  else
    ans << a
    i += 1
  end
end
puts ans * " "


Measured memory_bytes: 43984
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) A.push_back(A[i]);

    vector<ll> next(N);
    vector<ll> index(2*N);
    for(int i=0; i<2*N; i++) index[i] = i;
    auto cmp = [&](ll a, ll b){
        if(A[a%N] == A[b%N]) return a < b;
        return A[a%N] < A[b%N];
    };
    stable_sort(index.begin(), index.end(), cmp);
    for(int i=0; i<2*N; i++){
        if(index[i]<N) next[index[i]] = index[i+1]+1;
    }
    // for(auto& x: next) cout << x << " "; cout << endl;

    ll T = 0;
    int tmp = 0;
    do{
        tmp = next[tmp];
        if(tmp >= N){
            T += tmp/N; tmp %= N;
        }
    }while(tmp != 0);
    K %= T;
    // cout << "T = " << T << endl;
    // cout << "K = " << K << endl;

    ll k = 1;
    tmp = 0;
    vector<ll> ans;
    for(;k<=K;){
        if(k==K && next[tmp]>N){
            ans.push_back(A[tmp]); tmp++;
            if(tmp >= N) break;
            continue;
        }
        tmp = next[tmp];
        if(tmp >= N){
            k += tmp/N; tmp %= N;
        }
    }

    for(ll& x: ans) cout << x << " ";
    cout << endl;
}

Measured memory_bytes: 13256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long A, B, C, D;
    scan(A, B);
    scan(C, D);
    writeln(C - A);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int h,w;
ll m = ll(1e9+7);
ll dp[1001][1001];
bool g[1001][1001];
ll ways(int i,int j)
{
    if(i == h && j == w)
        return 1;
    if(i>h || j>w || !g[i][j])
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    ll ans=0;

    ans = (ways(i+1,j)%m+ways(i,j+1)%m)%m;

    return dp[i][j]=ans;
}
int main()
{
    char ch;
    cin>>h>>w;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
    {
        cin>>ch;
        if(ch == '.')
            g[i][j] = true;
        else
            g[i][j] = false;
    }
    memset(dp,-1,sizeof(dp));
    cout<<ways(1,1);
    return 0;
}



Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#include <stack>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int H,W;
vector<string> S;

int same[2020][2020];
int diff[2020][2020];

void preprocess(){
    rep(i,H) rep(j,W){
        if(j==0) continue;
        if(S[i][j]==S[i][j-1]) same[i][j]=1;
        if(i>0&&S[i][j]==S[i][j-1]) same[i][j]+=same[i-1][j];
    }
    rep(i,H) rep(j,W){
        if(j==0) continue;
        if(S[i][j]!=S[i][j-1]) diff[i][j]=1;
        if(i>0&&S[i][j]!=S[i][j-1]) diff[i][j]+=diff[i-1][j];
    }
}

int calc(vector<int> &P){
    stack<pair<int,int>> st;
    int res=0;
    rep(j,W){
        if(j==0) continue;
        int pos=j;
        while(st.size()&&st.top().first>=P[j]){
            auto f=st.top();
            st.pop();
            pos=f.second;
            chmax(res,f.first*(j-pos+1));
        }
        st.push(mkp(P[j],pos));
    }
    while(st.size()){
        auto f=st.top();
        st.pop();
        chmax(res,f.first*(W+1-f.second));
    }

    return res;
}

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

  cin>>H>>W;
  S.resize(H);
  rep(i,H) cin>>S[i];

  preprocess();

  int ans=max(H,W);
  rep(i,H){
      if(i==0) continue;
      {
          vector<int> P(W,0);
          vector<int> rev(W,0);
          rep(j,W) if(S[i][j]=='.') rev[j]=1;
          rep(j,W){
              if(j==0) continue;
              if(rev[j]==rev[j-1]) P[j]=same[i][j];
              else P[j]=diff[i][j];
          }
          chmax(ans,calc(P));
      }

      {
          vector<int> P(W,0);
          vector<int> rev(W,0);
          rep(j,W) if(S[i][j]!='.') rev[j]=1;
          rep(j,W){
              if(j==0) continue;
              if(rev[j]==rev[j-1]) P[j]=same[i][j];
              else P[j]=diff[i][j];
          }
          chmax(ans,calc(P));
      }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 36224
#include <iostream>
#include <sstream>
#include <map>
using namespace std;
int main(){
  string s,S;
  int mx = 0;
  map<string,int>mp;
  getline(cin,S);
  stringstream ss(S);
  string ans2,ans1;
  while(ss >> s){
    if((int)s.size() > mx){
      mx = s.size();
      ans1 = s;
    }
    mp[s]++; 
  }

  map<string,int>::iterator it = mp.begin();
  int mx2 = 0;

  for(;it != mp.end();it++){
    if((*it).second > mx2){
      mx2 = (*it).second;
      ans2 = (*it).first;
    }
  }
  cout << ans2 << ' ' << ans1 << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
	return __builtin_parity(x);
}

int N,Q;
int V[1<<19],W[1<<19];

int sumV[1<<9],sumW[1<<9];
void calc(int v,int lim){
	memset(sumV,0,sizeof(sumV));
	memset(sumW,0,sizeof(sumW));
	vint vs,ws;
	while(lim<=topbit(v)){
		vs.pb(V[v]);
		ws.pb(W[v]);
		v>>=1;
	}
	for(int i=1;i<1<<vs.size();i++){
		int k=topbit(i);
		sumV[i]=sumV[i^(1<<k)]+vs[k];
		sumW[i]=sumW[i^(1<<k)]+ws[k];
	}
}


vector<tuple<int,int,int>>bucket[1<<9];

const int X=100000;
int dp[X+1];
int ans[111111];
signed main(){
	scanf("%lld",&N);
	rep(i,N)scanf("%lld%lld",&V[i+1],&W[i+1]);
	scanf("%lld",&Q);
	rep(i,Q){
		int v,L;
		scanf("%lld%lld",&v,&L);
		int w=v;
		w>>=max(0ll,topbit(v)-8);
		bucket[w].eb(v,L,i);
	}

	for(int i=1;i<=N&&i<(1<<9);i++){
		calc(i,0);
		memset(dp,0,sizeof(dp));
		rep(j,1<<9){
			if(sumW[j]>X)continue;
			chmax(dp[sumW[j]],sumV[j]);
		}
		for(int j=0;j<X;j++)chmax(dp[j+1],dp[j]);

		for(auto &tpl:bucket[i]){
			int v,L,k;
			tie(v,L,k)=tpl;

			calc(v,9);
			rep(j,1<<9){
				if(sumW[j]>L)continue;
				chmax(ans[k],dp[L-sumW[j]]+sumV[j]);
			}
		}
	}

	rep(i,Q)printf("%lld\n",ans[i]);
	return 0;
}


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

int main(void){
    int a, b, ans = 0;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        bool flag = true;
        for (int j = 0; j < s.size() / 2; j++) {
            if (s[j] != s[s.size() - (j + 1)])
                flag = false;
        }
        if (flag)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  char str[102];
  int i, j, flag[102]={0};
  scanf("%s", str);
  for(i = 0; str[i] != '\0'; i++){
    for(j = i+1; str[j] != '\0'; j++){
      if(flag[j] == 0 && str[i] == str[j]){
	flag[i]++;
	flag[j] = 1;
      }
    } 
      if((flag[i]+1)%2 != 0){
	printf("No\n");
	return 0;
      }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
def main():
    n, d = map(int, input().split())
    count = 0
    d2 = d ** 2
    for i in range(n):
        x, y = map(int, input().split())
        dis = x ** 2 + y ** 2
        if dis <= d2:
            count += 1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74736
n =  list(input())
N = [int(n[i]) for i in range(len(n))]
if N[0] == max(N):
  print(max(N) * 100 + max(N)*10 + max(N))
else:
  m = N[0]+1
  print(m * 100 + m * 10 + m)


Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
using ul = unsigned long;

struct st{
    ul l;
    ul c;
    bool operator<( const st& right ) const {
        return l < right.l;
    }
    bool operator==( const st& right ) const {
        return l == right.l;
    }
};

bool tr(ul a,ul b, ul c){
    if(a+b>c){
        return true;
    }else{
        return false;
    }
}

int main(){
    int N;
    std::cin >> N;
    std::vector<st> v;
    int count =0;
    for(int i=0;i<N;i++){
        ul tmp;
        std::cin >> tmp;
        st stmp = {tmp, 1};
        auto it = std::find(v.begin(),v.end(),stmp);
        if(it==v.end()){
            v.push_back(stmp);
        }else{
            (it->c)++;
        }
    }
    int n = v.size();
    if(n<3){
        std::cout << "0" << std::endl;
        return 0;
    }
    std::sort(v.begin(),v.end());
    /*
    for(int i=0;i<n;i++){
        std::cout << v[i].l << ":" << v[i].c<< std::endl;;
    }
    */
    for(int i=0;i<n-2;i++){
        st li = v[i];
        for(int j=i+1;j<n-1;j++){
            st lj = v[j];
            for(int k=j+1;k<n;k++){
                st lk = v[k];
                if(tr(li.l,lj.l,lk.l)){
                    count += li.c*lj.c*lk.c;
                }
            }
        }
    }
    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n, m;
  cin >> n >> m;
  vi p(m);
  vs s(m);
  rep(i, m) cin >> p[i] >> s[i];
  vi ac(n, 0);
  vi pena(n, 0);
  rep(i, m) {
    if(s[i] == "AC") {
      ac[p[i] - 1] = 1;
    } else if(ac[p[i] - 1] == 0) {
      pena[p[i] - 1] += 1;
    }
  }
  int acnum = accumulate(all(ac), 0);
  int penanum = 0;
  rep(i, n) {
    if(ac[i] == 1)
      penanum += pena[i];
  }
  cout << acnum << ' ' << penanum << endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include<iomanip>

using namespace std;

int main()
{
    double r,t,f;
    cin >> r;
    f=r*r*3.14159265358979;
    t=2*r*3.14159265358979;
    cout << fixed;
    cout << setprecision(8) << f << " " << setprecision(8) << t << endl;
}



Measured memory_bytes: 3220
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  string s; cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long q = sc.nextLong();
    long h = sc.nextLong();
    long s = sc.nextLong();
    long d = sc.nextLong();
    long n = sc.nextLong();
    long one = Math.min(4 * q, 2 * h);
    one  = Math.min(one, s);
    long two = Math.min(2 * one, d);
    long ans = two * (n / 2) + one * (n - (n / 2) * 2);
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<stdlib.h>
int main(){

	int x,m,*s,*k,b,*y1,*y2,nn,n1;
	
	scanf("%d",&x);
	k=(int*)malloc(sizeof(int)*(x*2+1));
	y1=(int*)malloc(sizeof(int)*(x*2+1));
	y2=(int*)malloc(sizeof(int)*(x*2+1));
	scanf("%d",&m);
	s=(int*)malloc(sizeof(int)*(m+1));
	for(nn=1;nn<=m;nn++){
		scanf("%d",&s[nn]);
	}
	for(nn=1;nn<=x*2;nn++){
		k[nn]=nn;
	}
	for(nn=1;nn<=m;nn++){
		if(s[nn]==0){	
			for(n1=1;n1<=x;n1++){
				y1[n1]=k[n1];
			}
			for(n1=1;n1<=x*2;n1++){
				y2[n1-x]=k[n1];
			}
			for(n1=1;n1<=x*2;n1++){
				if(n1%2==1)k[n1]=y1[n1/2+1];
				if(n1%2==0)k[n1]=y2[n1/2];
			}
		}
		if(s[nn]>0){
			for(n1=1;n1<=s[nn];n1++){
				y1[n1]=k[n1];
			}
			for(n1=s[nn]+1;n1<=x*2;n1++){
				y2[n1-s[nn]]=k[n1];
			}
			for(n1=1;n1<=x*2-s[nn];n1++){
				k[n1]=y2[n1];
			}
			for(n1=x*2-s[nn]+1;n1<=x*2;n1++){
				k[n1]=y1[n1-x*2+s[nn]];
			}
		}
	}
	for(n1=1;n1<=x*2;n1++){
		printf("%d\n",k[n1]);
	}       
	return 0;  
} 

Measured memory_bytes: 0
#include <stdio.h>

#define N 200000

int main()
{

  int n, R[N], i, j, minv, maxv;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d", &R[i]);
  }

  maxv = R[1] - R[0];
  minv = R[0];
  for(j=1; j<n; j++){
    if(maxv < R[j]-minv) maxv = R[j]-minv;
    if(minv > R[j]) minv = R[j];
  }

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

  return 0;
}

Measured memory_bytes: 1380
# 2019-11-12 15:53:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    
    ans = reduce(gcd, a)
    print(ans)



if __name__ == "__main__":
    main()


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

#define MOD 1000000007

typedef long long int ll;

int main() {

	IOS

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

	ll sum = 0;

	for (int i = 0; i < n; i++)
		sum = (sum + a[i]) % MOD;

	ll res = 0;

	for (int i = 0; i < n; i++) {
		sum = (sum - a[i] + MOD) % MOD;
		res = (res + (a[i] * sum) % MOD) % MOD;
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 5232
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
s=[tuple(map(int, input().split())) for i in range(M)]
from operator import itemgetter
s.sort(key=itemgetter(1))
t=0
a=0
for i in s:
    if i[0]>t:
        a+=1
        t=i[1]-1
print(a)

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

using namespace std;

const int INF = 1e9;

int n, m, mat[35][35];

int main(){
	scanf("%d%d", &n, &m);
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++)
		scanf("%d", &mat[i][j]);
	}
	
	int res = INF;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			int tot = 0;
			for(int ii = 0; ii < n; ii++){
				for(int jj = 0; jj < m; jj++){
					tot += mat[ii][jj] * (min(abs(ii - i), abs(jj - j)));
				}
			}
			res = min(res, tot);
		}
	}
	
	printf("%d\n", res);
}



Measured memory_bytes: 3236
N, H = map(int, input().split())
#ab = [list(map(int, input().split())) for i in range(N)]
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
from bisect import bisect_left
end = bisect_left(b, max(a))
#H = 500
i = N - 1
cnt = 0
while H > 0 and end <= i:
    #print(i)
    H -= b[i]
    cnt += 1
    i -= 1
if H <= 0:
    print(cnt)
    quit()
import math
print(math.ceil(H / max(a)) + cnt)

Measured memory_bytes: 11352
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>

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

using namespace std;

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

void solve_A(){
    string s;
    cin >> s;

    if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No";
}

void solve_B(){
    ll n;
    cin >> n;

    ll ans = 0;
    for(int i = 0; i <= n; i++){
        if(i%3==0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}

void solve_C(){
    ll k;
    cin >> k;

    ll ans = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                ans += gcd(gcd(a, b), c);
            }
        }
    }

    cout << ans << endl;
}

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

Measured memory_bytes: 3632
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

double v;

int main()
{
	
	while(cin>>v)
	{
		double t=v/9.8;
		double y=4.9*t*t;

		int ans=1;
		while(ans*5-5<y)
			ans++;
		cout<<ans<<endl;

	}


	return 0;
}

Measured memory_bytes: 1224
N = int(input()) # 入力数
L1 = input().split(" ")
# print(L1)
L2 = list(map(int, L1))
A = []
B = []


# print("modeB")
for n in range(N - 1):
    A.append(max(L2))
    L2.remove(max(L2))
    # print(A)
    if L2 == []:
        break
    B.append(max(L2))
    # print(B)
    L2.remove(max(L2))
    if L2 == []:
        break
    n += 1

# print(A, "f")
# print(B, "f")
PA = sum(A)
PB = sum(B)
print(PA - PB)



Measured memory_bytes: 3064
#include <atcoder/mincostflow>
#include <iostream>

using namespace std;
using namespace atcoder;

const long long BIG = 1'000'000'000;

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

    /**
     * generate (s -> row -> column -> t) graph
     * i-th row correspond to vertex i
     * i-th col correspond to vertex n + i
     **/
    mcf_graph<int, long long> g(2 * n + 2);
    int s = 2 * n, t = 2 * n + 1;

    // we can "waste" the flow
    g.add_edge(s, t, n * k, BIG);

    for (int i = 0; i < n; i++) {
        g.add_edge(s, i, k, 0);
        g.add_edge(n + i, t, k, 0);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            long long a;
            cin >> a;
            g.add_edge(i, n + j, 1, BIG - a);
        }
    }

    auto result = g.flow(s, t, n * k);
    cout << 1LL * n * k * BIG - result.second << endl;

    vector<string> grid(n, string(n, '.'));
    auto edges = g.edges();
    for (auto e : edges) {
        if (e.from == s || e.to == t || e.flow == 0) continue;

        grid[e.from][e.to - n] = 'X';
    }

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

Measured memory_bytes: 3924
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=200200,D=20;
int i,j,k,n,m,nm,mm,ch,ff;
int x[N],pre[1<<D],suf[1<<D],ans[N];
vector<int> X[D];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
int find1(int i,int x) {
	int l=0,r=X[i].size()-1,mid;
	while (l<r) {
		mid=(l+r+1)>>1;
		if (X[i][mid]>x) r=mid-1;
		else l=mid;
	}
	return l;
}
int find2(int i,int x) {
	int l=0,r=X[i].size()-1,mid;
	while (l<r) {
		mid=(l+r-1)>>1;
		if (X[i][mid]<x) l=mid+1;
		else r=mid;
	}
	return l;
}
void Max(int &x,int y) {
	if (y>x) x=y;
}
void Min(int &x,int y) {
	if (y<x) x=y;
}
int main() {
	R(n);R(m);
	for (i=1;i<=n;i++) R(x[i]);
	k=m;
	while (1) {
		X[nm].push_back(1);
		for (i=1;i<n;i++) if (x[i]+k<x[i+1]) X[nm].push_back(i+1);
		X[nm].push_back(n+1);
		nm++;
		if (!k) break;
		k>>=1;
	}
	mm=1<<nm;
	for (i=0;i<mm;i++) suf[i]=n+1;
	for (i=0;i<mm;i+=2)
		for (j=1;j<nm;j++) if (!(i&1<<j)) {
			Max(pre[i|1<<j],X[j][find1(j,pre[i]+1)+1]-1);
			Min(suf[i|1<<j],X[j][find2(j,suf[i])-1]);
		}
	if (X[0].size()>mm+1) {
		for (i=0;i<n;i++) puts("Impossible");
		return 0;
	}
	for (i=1;i<X[0].size();i++) {
		int l=X[0][i-1],r=X[0][i]-1,fg=0;
		for (j=0;j<mm;j+=2) if (pre[j]+1>=l && suf[(mm-2)^j]-1<=r) {
			fg=1;
			break;
		}
		for (j=l;j<=r;j++) ans[j]=fg;
	}
	for (i=1;i<=n;i++) {
		if (ans[i]) puts("Possible");
		else puts("Impossible");
	}
}

Measured memory_bytes: 13044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0062
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                string res = line;
                while (res.Length > 1)
                {
                    string tmp = "";
                    for (int i = 0 ; i < res.Length-1 ; i++)
                    {
                        string newNum = (int.Parse(res[i].ToString()) + int.Parse(res[i + 1].ToString())).ToString();
                        tmp += newNum.Substring(newNum.Length - 1, 1);
                    }
                    res = tmp;
                }
                Console.WriteLine(res);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 13908
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    int n,m,x,temp,sel,ans=10000000,fg=0,temp_cost,jd;
    vector<int> cost,t_skill;
    vector<vector<int>> skill;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++)skill.push_back(vector<int>(0));
    for(int i=0;i<m;i++)t_skill.push_back(0);

    for(int i=0;i<n;i++){
        cin>>temp;
        cost.push_back(temp);
        for(int j=0;j<m;j++){
            cin>>temp;
            skill[i].push_back(temp);
        }
    }

    for(int i=0;i<pow(2,n);i++){
        temp_cost=0;
        sel=i;
        for(int j=0;j<m;j++)t_skill[j]=0;

        for(int j=0;j<n;j++){
            if(sel%2==1){
                temp_cost+=cost[j];
                for(int k=0;k<m;k++)t_skill[k]+=skill[j][k];
            }
            sel=sel>>1;
        }
        jd=0;
        for(int j=0;j<m;j++){
            if(t_skill[j]<x){
                jd++;
                break;
            }
        }
        if(jd==0){
            if(temp_cost<ans){
                ans=temp_cost;
            }
            fg++;
        }
    }
    if(fg==0){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4048
import sys
input = sys.stdin.readline

n = int(input())
ss = {}

for i in range(n):
  s = str(input()).rstrip('\n')
  if s in ss:
    ss[s] = ss[s]+1
  else:
    ss[s] = 1

m = max(list(ss.values()))
ss1 = sorted({k:v for k,v in ss.items() if v == m}.items())

for k,v in ss1:
  print(k)

Measured memory_bytes: 54740