akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair <int, int>;

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;
const ll MOD = 1000000007;

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

  // cout << "/* message */" << '\n';
  ll tmp0 = 1, tmp1 = 1, tmp2 = 1;
  // std::cout << "tmp0" << tmp0 << "tmp1" << tmp1 << "tmp2" << tmp2 << '\n';
  for (ll i = 0; i < n; i++) {
    tmp0 *= 10;
    tmp0 %= MOD;
  }
  for (ll i = 0; i < n; i++) {
    tmp1 *= 9;
    tmp1 %= MOD;
  }
  for (ll i = 0; i < n; i++) {
    tmp2 *= 8;
    tmp2 %= MOD;
    // std::cout << "tmp0" << tmp0 << "tmp1" << tmp1 << "tmp2" << tmp2 << '\n';
  }
  // tmp1 *= 2; tmp1 %= MOD;
  // std::cout << "tmp0:" << tmp0 << "tmp1:" << tmp1 << "tmp2:" << tmp2 << '\n';
  // ans = tmp0 - tmp1 - tmp1 + tmp2;
  ans = (tmp0 - tmp1) % MOD;
  ans = (ans - tmp1) % MOD;
  ans = (ans + tmp2) % MOD;

  // ans %= MOD;
  ans = (ans + MOD) % MOD;
  // ans *= n * (n - 1) % MOD;
  // ans *= n; ans %= MOD;
  // ans *= (n - 1); ans %= MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans += a[i] * a[j];
        }
    }
    cout << ans;
}

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

const ll INF = 1LL << 60;

const int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N, M;
int main() {
    cin >> N >> M;
    combination comb(1e6 + 10);
    mint ans = 1;

    ll res = M;
    for (ll i = 2; i * i <= M; i++) {
        if (res % i == 0) {
            int num = 0;
            while (res % i == 0) {
                num++;
                res /= i;
            }

            // 組み合わせ
            ans *= comb(num + N - 1, N - 1);            
        }
    }

    if (res != 1) {
        ans *= comb(1 + N - 1, 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 18820
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

max_a = max(a for a, _ in ab)

dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0

for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)

print(min(dp[h:]))

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

#define ll long long int

int main() {
    ll n, m, p;
    cin >> n >> m >> p;
    vector<ll> a(m), b(m), c(m), dp(n, 1e11);
    vector<bool> reach(n, false); 
    bool flag = false;
    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        c[i] = p - c[i]; // -(c[i] - p)
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(dp[a[j]] != 1e11 && dp[b[j]] > dp[a[j]] + c[j]) {
                dp[b[j]] = dp[a[j]] + c[j];
                if(i == n - 1) {
                    flag = true;
                    reach[a[j]] = reach[b[j]] = true;
                }
            }
        }
    }
    if(flag) {
        for(int i = 0; i < n - 1; i++) {
            for(int j = 0; j < m; j++) {
                reach[b[j]] = reach[a[j]] | reach[b[j]];
            }
        }
    }
    if(reach[n - 1])
        cout << -1 << endl;
    else    
        cout << max(0LL, -dp[n - 1]) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first 
#define S second
const ll N = 200022 ;
ll n, h[N], dp[N], k; 
int main()
{
	scanf("%lld%lld", &n, &k) ;
	for(int i = 1 ; i <= n ; i ++)	
		scanf("%lld", &h[i]) ;
	dp[2] = fabs(h[2]-h[1]) ;
	for(int i = 3 ; i <= n ; i ++){
		dp[i] = 1e9+1e4 ;
		for(int j = i-1 ; j >= i-k and j >= 1; j --)
			dp[i] = min(dp[i], dp[j]+(int)fabs(h[i]-h[j])) ;	
	}
	cout << dp[n] ; 
}


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

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

    ll n = s.size();
    vector<ll> ans(n+1, 0);

    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'R' && s[i+1] == 'L') {
            int j = i, rc = 0, lc = 0;
            while (j-1 >= 0 && s[j-1] == 'R') {
                rc++;
                j--;
            }
            j = i+1;
            while (j+1 < n && s[j+1] == 'L') {
                lc++;
                j++;
            }
            int rans;
            int lans = rans = (rc + lc + 2) / 2;
            if (rc > lc && (rc + lc) % 2 != 0) rans++;
            else if (lc > rc && (rc + lc) % 2 != 0) lans++;

            if (max(lc, rc) % 2 == 0) {
                ans[i] = rans;
                ans[i+1] = lans;
            } else {
                ans[i] = lans;
                ans[i+1] = rans;
            }
            i++;
        }
    }

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

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line
vector<pair<ll,int>> factorize(ll n){
	vector<pair<ll,int>> res;
	for( ll i = 2; i*i <= n; ++i){
		if(n%i) continue ; 
		res.emplace_back(i,0);
		while(n%i == 0){
			n /= i ;
			res.back().second++;
		}
	}
	if ( n != 1) res.emplace_back(n,1);
	return res;
}

int main()
{
	cout << setprecision(10);
	ll p ;
	cin >> n >> p;

	vector<pair<ll,int>> fact = factorize(p);
	ll ans = 1; 
	for(auto x : fact){
		while(x.second >= n){
			ans *= x.first; 
			x.second -= n;
		}
	}
	cout << ans << endl;

}


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

int main(){
    int M;
    cin >> M;
    vector<ll> c(M), d(M);
    ll N = 0, x = 0; 
    for (int i = 0; i < M; i++) {
        cin >> d[i] >> c[i];
        N += c[i];
        x += c[i] * d[i];
    }
    if (x % 9 > 0) cout << (N-1)+(x/9) << endl;
    else cout << N-2+(x/9) << endl;
    return 0;
}

Measured memory_bytes: 3328
n,k=map(int,input().split())
*p,=map(int,input().split())
px=[(i+1)/2 for i in p]
px_sum=[0]
for j in range(len(px)):
	px_sum.append(px_sum[j]+px[j])
ans=0
for i in range(n-k+1):
	a=px_sum[i+k]-px_sum[i]
	ans=max(a,ans)
print(ans)

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int N;
    cin >> N;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

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

    ll ans = L_INF;
    int l = 1, r = 3;
    for (int i = 2; i < N - 1; i++) {
        while (l < i && csum[l] - csum[0] < csum[i] - csum[l]) ++l;
        --l;
        while (r < N && csum[r] - csum[i] < csum[N] - csum[r]) ++r;
        --r;

        int l_tmp = l, r_tmp = r;
        if (l_tmp < i - 1) {
            ll t1 = abs((csum[i] - csum[l_tmp]) - (csum[l_tmp] - csum[0]));
            ll t2 = abs((csum[i] - csum[l_tmp + 1]) - (csum[l_tmp + 1] - csum[0]));
            if (t1 > t2) {
                ++l_tmp;
            }
        }
        if (r_tmp < N - 1) {
            ll t1 = abs((csum[N] - csum[r_tmp]) - (csum[r_tmp] - csum[i]));
            ll t2 = abs((csum[N] - csum[r_tmp + 1]) - (csum[r_tmp + 1] - csum[i]));
            if (t1 > t2) {
                ++r_tmp;
            }
        }

        ll s1, s2, s3, s4;
        s1 = csum[l_tmp] - csum[0];
        s2 = csum[i] - csum[l_tmp];
        s3 = csum[r_tmp] - csum[i];
        s4 = csum[N] - csum[r_tmp];

        ll mn, mx;
        mn = min({s1, s2, s3, s4});
        mx = max({s1, s2, s3, s4});

        ans = min(ans, mx - mn);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, s = na()
a = na()

def invl(a, mod):
    b = mod
    p = 1; q = 0
    while b > 0:
        c = a // b
        a, b = b, a%b
        p, q = q, p-c*q
    return p + mod if p < 0 else p

mod = 998244353
i2 = invl(2, mod)
dp = [0] * (s+1)
dp[0] = pow(2, n, mod)

for x in a:
    for i in range(s, x-1, -1):
        dp[i] += dp[i-x] * i2
        dp[i] %= mod

print(dp[s] % mod)


Measured memory_bytes: 70248
#include<bits/stdc++.h>
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
template<typename T> inline void print(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int h,w,n;
int main(){
	inc>>h>>w>>n;
	int k=max(h,w);
	if(n%k==0) print(n/k);
	else print(n/k+1);
	exit(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int N;
long long h[100010];
long long dp[100010];

int main()
{
  cout << fixed << setprecision(10);
  int N,K;
  cin >> N >> K;
  rep(i,N) cin >> h[i];
  rep(i,100010) dp[i] = INF;
  dp[0] = 0;
  for(int i=0;i<N;i++)
  {
    for(int j=1;j<=K;j++)
    {
      chmin(dp[i+j],dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}


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

int main() {
  int a, b;

  cin >> a >> b;

  if (a <= 5) {
    cout << "0";
  } else if (a <= 12) {
    cout << b / 2;
  } else {
    cout << b;
  }

  return 0;
}

Measured memory_bytes: 764
#include<cstdio>
#include<algorithm>
using namespace std;
long long  k,a,b,ans;
int main(){
	scanf("%lld%lld%lld",&k,&a,&b);
	if(b-a<=2||k<=a-1)printf("%lld\n",k+1);
	else{
		k-=(a-1);
		ans=a;
		ans=ans+k/2*(b-a)+(k&1);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int i,j,key,n,m;
  int l[100];

  scanf("%d",&n);/* 要素の数の格納 */

  for(i=0;i<n;i++){
    scanf("%d",&l[i]);/* 配列の格納 */
  }
  for(i=0;i<n;i++){
    printf("%d",l[i]);/* 変換前の配列の表示 */
    if(i<n-1)printf(" ");/* 空白の表示 */
  }
  printf("\n");/* 改行の表示 */

  for(i=1;i<n;i++){
    key = l[i];/* 位置の変換のために後続の値を入れる変数 */
    j = i - 1;
    while(l[j]>key && j>=0){/* 位置の変換の条件 */
      l[j+1] = l[j];/* 位置の変換 */
      j--;
    }
    l[j+1] = key;/* 位置の変換 */
    for(m=0;m<n;m++){
      printf("%d",l[m]);/* 変換後の配列の表示 */
      if(m<n-1)printf(" ");/* 空白の表示 */
    }
  printf("\n");/* 改行の表示 */
  } 
   return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	int cnt = 0;
	for( int i = 1; i <= n; ++i ){
		int t; cin >> t;
		if( i % 2 == 1 and t % 2 == 1 ) ++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3580
import math
A, B, C, K = map(int, input().split())

abs_ans = abs(A-B)

if A <= B:
    if K % 2 == 0:
        print(-abs_ans)
    else:
        print(abs_ans)
else:
    if K % 2 == 0:
        print(abs_ans)
    else:
        print(-abs_ans)

Measured memory_bytes: 9108
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		long x = Long.parseLong(st.nextToken());
		int[] arr = new int[n];
		st = new StringTokenizer(br.readLine());
		for(int i = 0; i < n; i++){
			arr[i] = Integer.parseInt(st.nextToken());
		}
		int curr = 0; int count = 1;
		for(int i = 0; i < n; i++){
			curr += arr[i];
			if(curr <= x) count++;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 22996
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    else:
        for i in range(h):
            if i%2==0:
                for j in range(w):
                    if j%2==0:
                        print("#",end="")
                    else:
                        print(".",end="")
                print()
            if i%2==1:
                for j in range(w):
                    if j%2==0:
                        print(".",end="")
                    else:
                        print("#",end="")
                print()
        print()


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


int main(){
    string a,b;
    cin>>a>>b;
    int len=b.size();
    for(int i=0;i<=a.size()-b.size();i++){
        string s=a.substr(i,b.size());
        int cnt=0;
        for(int j=0;j<b.size();j++){
            if(b[j]-s[j]) cnt++;
        }
        len=min(len,cnt);
    }
    printf("%d",len);
    return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  for(int &x: a) cin>>x;
  sort(a.begin(),a.end());
  int b=0,count=0;
  for(int i=0;i<N;i++){
    if(a[i]==b) continue;
    else {b=a[i]; count++;}
  }
  cout<<count<<endl;
}
    
    


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include<algorithm>
#define mod 1000000007;
using namespace std;
struct jk
{
    char name[15];
    int fen;
    int bian;
}a[105];
int cmp(jk aa,jk bb)
{
    if(strcmp(aa.name,bb.name)==0)
    {
        return aa.fen>bb.fen;
    }
    return strcmp(aa.name,bb.name)<0;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int x=1;x<=n;x++)
    {
        scanf("%s%d",a[x-1].name,&a[x-1].fen);
        a[x-1].bian=x;
    }
    sort(a,a+n,cmp);
    for(int x=0;x<n;x++)
    {
        printf("%d\n",a[x].bian);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
  int n,i,a[100010],ans=0;
  cin >> n;
  for (i=1;i<=n;i++) cin >> a[i];
  for (i=1;i<=n;i++) if (a[a[i]]==i) ans++;
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;


#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
vector<pair<int, int> > vp;
 
struct Less {
    bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
        return x.first > y.first;
    }
};

ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}


//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
int p[11], c[11];
int main(void) {
    int D, G; cin >> D >> G;
    REP(i, D) cin >> p[i] >> c[i];
    
    int ans=10001;
    for(int i=0; i<(1<<D); ++i){
        ll sum=0;
        int cnt=0;
        for(int j=0; j<D; ++j){
            if(1&i>>j) {
                sum += c[j] + (j+1)*100*p[j];
                cnt += p[j];
            }
        }
        if(sum>=G) {
            ans = min(ans, cnt);
            continue;
        }
        if(sum<G){
            int t = 0;
            for(int j=0; j<D; ++j){
                if(1&(~i)>>j) t=j;
            }
            for(int k=1; k<p[t]; ++k){
                if(sum+k*(t+1)*100>=G){
                    cnt=cnt+k;
                    ans=min(ans, cnt);
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[310][310],D[310][310],sum=0;
    cin>>n;
    // o-index
    rep(i,n){
        rep(j,n){
            cin>>a[i][j];
            D[i][j]=a[i][j];
            sum+=a[i][j];
        }
    }
    sum/=2;
    rep(k,n){
        rep(i,n){
            rep(j,n){
                D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(D[i][j]!=a[i][j]){
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    rep(i,n){
        rep2(j,i+1,n){
            rep(k,n){
                if(k==i || k==j) continue;
                if(D[i][j]==D[i][k]+D[k][j]){
                    sum-=D[i][j];
                    break;
                }
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll dp[1111][11111];

int main(){
	
	int n;cin >> n;
	vector<pair<pair<ll,ll>,pair<ll,ll>>> v;
	REP(i,n){
		ll a,b,c;cin >> a >> b >> c;
		v.PB(MP(MP(a+b,a),MP(b,c)));
	}
	
	sort(ALL(v));
	
	ll ans = 0;
	REP(i,n){
		REP(j,11111){
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
			if(v[i].SE.FI >= j && j + v[i].FI.SE < 11111){
				dp[i+1][j + v[i].FI.SE] = max(dp[i+1][j + v[i].FI.SE],dp[i][j] + v[i].SE.SE);
			}
			if(v[i].SE.FI >= j){
				ans = max(ans,dp[i][j] + v[i].SE.SE);
			}
		}
	}
	
	REP(i,11111)ans = max(ans,dp[n][i]);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 88320
#include <bits/stdc++.h>
//*/
using namespace std;
static const int _ = []() {
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();
// I hate typing .first or .second
template<typename T, typename U>
struct par {
	T x;
	U y;
	par() :x(-1), y(-1) {}
	par(const T& x, const U& y) :x(x), y(y) {}
	bool operator<(const par& other) const {
		if (x == other.x) return y < other.y;
		return x < other.x;
	}
	bool operator==(const par& other) const {
		return x == other.x && y == other.y;
	}
	par operator-(const par& b) const {
		return { x - b.x, y - b.y };
	}
};
#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rp1(i,a) for(ll i=1;i<=(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll par<ll,ll>
#define pii par<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>
template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T> inline void amax(T& a, const T& b) { if (a < b) a = b; }
template<class T> inline void amin(T& a, const T& b) { if (a > b) a = b; }
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(int argc, char** argv) {
	ll n, m, C;
	cin >> n >> m;
	vector<pll> a(n);
	rep(i, n) 
		cin >> a[i].x >> a[i].y;
	ll ans = 0, i = 0;
	sort(all(a));
	while (m && i<n) {
		ans += min(m, a[i].y)*a[i].x;
		m -= min(m, a[i].y);
		i++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    for (int i = 0; i <= 7; ++i) {
        if (pow(2, i) > N) {
            cout << pow(2, i - 1) << endl; break;
        }
    }
}


Measured memory_bytes: 4288
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
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 (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> A(N); rep(i, 0, N) {
		cin >> A[i];
	}

	vector<int> B = A;
	rep(i, 0, N - 1) {
		B[i] %= K;
		B[i + 1] += B[i];
	}
	B.back() %= K;

	dump(B);

	auto f = [&](int x) {
		if (x < 0) {
			int k = abs(x) / K;
			x += (k + 1) * K;
			x %= K;
		}
		x %= K;
		return x;
	};

	rep(i, 0, N) {
		B[i] = i + 1 - B[i];
		B[i] = f(B[i]);
	}
	dump(B);

	int ans = 0;
	map<int, int> mp;
	rep(i, 0, min(N, K - 1)) {
		mp[B[i]]++;
	}

	int x = 0;
	rep(i, 0, N) {
		dump(mp);
		dump(x, mp[x]);
		ans += mp[x];
		dump(ans);
		x++;
		x -= A[i];
		x = f(x);
		dump(x);
		mp[B[i]]--;
		if (i + K - 1 < N)
			mp[B[i + K - 1]]++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        String[] x = null;
        Scanner sc = new Scanner(System.in);
		String ip = sc.nextLine();
		x = ip.split(" ", 0);
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		int c = Integer.parseInt(x[2]);

		if(a<b && b<c){
		    System.out.println("Yes");
		}else{
		    System.out.println("No");
		}
    }
}



Measured memory_bytes: 26308
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,K;
    cin >> N >> K;
    vector<int> dp(N,INF),V(N);
    rep(i,0,N)cin >> V[i];
    dp[0] = 0;
    rep(i,1,N){
        rep(j,max(0,i-K),i){
            dp[i] = min(dp[i], abs(V[i] - V[j]) + dp[j]);
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
 
long long N, W, w[109], v[109], dp[109][100009];
 
int main() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= W; j++) dp[i][j] = -(1LL << 60);
	}
	dp[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= W; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j + w[i] <= W) dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[i - 1][j] + v[i]);
		}
	}
	long long rem = 0;
	for (int i = 0; i <= W; i++) rem = max(rem, dp[N][i]);
	cout << rem << endl;
	return 0;
}

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

int n, m;

int main() {
	cin >> n >> m;
	if (n & 1) {
		for (int i = 0; i < m; i++)
			cout << i + 1 << ' ' << n - i << endl;
	} else {
		for (int i = 0; i < m; i++)
			cout << i + 1 << ' ' << (2 * i + 1 < n / 2 ? n - i : n - i - 1)
					<< endl;

	}

}


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

/***** MAIN *****/
signed main() {
  int n, k, sum;
  cin >> n >> k >> sum;

  REP(i,n) {
    int tmp;
    if(i < k) tmp = sum;
    else tmp = sum + 1;

    if(tmp > 1e9) tmp = 1;

    if(i == n-1) cout << tmp;
    else COUTS(tmp);
  }
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    int n,l;cin>>n>>l;
    int taste=0;
    for (int i = 1; i <= n; i++)
    {
        /* code */
        taste+=l+i-1;
    }
    
    
    int pie=10000000;int j=0;

    for (int i = 1; i <= n; i++)
    {
        /* code */
          if (pie>abs((l+i-1)))
        {
            /* code */
            j=i;
        }
        
        pie=min(pie,abs((l+i-1)));
        
        
    }
    
    cout<<taste-(l+j-1)<<endl;
   }

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

int main()
{
    long long x,k,d;
    scanf("%lld%lld%lld",&x,&k,&d);
    //.//cin >> x >> k >> d;
    if(x<0)
        x=-x;
    long long siz = x/d;
    if(siz<=k){
        x=x%d;
        k-=siz;
        if(k%2==0){
            //cout << (x%d) <<endl;
            printf("%lld\n",x%d);
        }
        else{
            printf("%lld\n",d-x);
        }
    }
    else{
        printf("%lld\n",x-k*d);
    }
    return 0;
}


Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int N=5e2+5,mod=1e9+7;
int n,c[N],f[N][N][N],pw[N][N],C[N][N],fac[N],ifc[N];
inline void inc(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
inline int power(int b,int n){int ans=1;for(;n;n>>=1,b=1ll*b*b%mod)if(n&1)ans=1ll*ans*b%mod;return ans;}

int main(){
    //freopen("in.in","r",stdin);
    int m=read();n=read();
    REP(i,1,m)++c[read()];
    REP(i,0,n)REP(j,pw[i][0]=1,m)pw[i][j]=1ll*pw[i][j-1]*i%mod;
    REP(i,0,n)REP(j,C[i][0]=1,n)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    REP(i,fac[0]=1,N-1)fac[i]=1ll*fac[i-1]*i%mod;
    ifc[N-1]=power(fac[N-1],mod-2);
    DREP(i,N-2,0)ifc[i]=1ll*ifc[i+1]*(i+1)%mod;
    f[n+1][0][0]=1;
    DREP(i,n,1)REP(j,0,n)REP(k,0,n)if(f[i+1][j][k])
	for(int l=0;k+i*l<=n;++l)
	    inc(f[i][j+l][k+i*l],1ll*f[i+1][j][k]*ifc[l]%mod*pw[k-(i-1)*j+l][c[i]]%mod);
    int ans=0;
    REP(j,0,n)REP(k,j,n){
	int res=1ll*fac[j]*C[n-k+1][j]%mod*f[1][j][k]%mod;
	if((n-k)&1)res=mod-res;
	inc(ans,res);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 501888
#include <stdio.h>

int main(){
	int a,b;
	int d,r;
	double f;
	
	scanf("%d %d",&a,&b);
	
	d=a/b;
	r=a%b;
	f=(double)a/b;
	
	printf("%d %d %f\n",d,r,f);
	
	return 0;
}
	

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

using namespace std;

int main(){

  string s;
  int sum = 0;
  
  cin >> s;

  for(int i = 1;i < s.size() - 2;++i){
	for(int j = i + 1;j < s.size() - 1;++j){
	  for(int k = j + 1;k < s.size();++k){
		vector<string> ss(4);
		vector<int> mm(4);
		bool flag = true;

		  for(int m = 0;m < i;++m)
			ss[0].push_back(s[m]);
		  for(int m = i;m < j;++m)
			ss[1].push_back(s[m]);
		  for(int m = j;m < k;++m)
			ss[2].push_back(s[m]);
		  for(int m = k;m < s.size();++m)
			ss[3].push_back(s[m]);

		  for(int m = 0;m < 4;++m){
			if(ss[m].size() >= 2){
			  if(ss[m][0] == '0'){
				flag = false;
			  }
			}
		  }

		  if(flag == false)
			continue;
		  
		  //cout << ss[0] << "." << ss[1] << "." << ss[2] << "." << ss[3] << endl;

		  for(int m = 0;m < 4;++m)
			mm[m] = atoi(ss[m].c_str());

		  //cout << mm[0] << "." << mm[1] << "." << mm[2] << "." << mm[3] << endl;

		  if(mm[0] < 0 || mm[0] > 255 ||mm[1] < 0 || mm[1] > 255 ||
			 mm[2] < 0 || mm[2] > 255 ||mm[3] < 0 || mm[3] > 255 )
			continue;

		  else
			sum++;
		  
	  }
	}
  }

  cout << sum << endl;
  
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(all(v));
    ll res = 0;
    for (int i = 0; i < k; i++) res += v[i];
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3644
// Beginner163.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main()
{
	//A
    /*double r;
	cin >> r;
	cout << 2 * M_PI * r;*/

	//B
	int n, m;
	cin >> n >> m;
	int res = n;
	int a;
	for (int i = 0; i < m; ++i)
	{
		cin >> a;
		res -= a;
	}
	cout << (res >= 0 ? res : -1);
}



Measured memory_bytes: 3620
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

public class Main {

	void submit() {
		int a = nextInt();
		int b = nextInt();
		int c = nextInt();
		
		c = Math.min(c, a + b + 1);
		out.println(b + c);
		
	}

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	Main() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 5;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isTrash(b))
			;
		return b;
	}

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	char nextChar() {
		return (char) skip();
	}

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}


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

int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  vector<int> d(n,-1);
  queue<int> q;
  
  d[0]=0;
  q.push(0);
  
  int cnt=1;
  while(!q.empty()){
    int v=q.front();q.pop();
    
    for(int &x: g[v]){
      if(d[x]!=-1) continue;
      d[x]=v+1;
      q.push(x);
      cnt++;
    }
  }
  if(cnt<n) cout<<"No"<<endl;
  else{
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
      cout<<d[i]<<endl;
    }
  }
}

Measured memory_bytes: 10188
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
-- templete



main = map (swap . fmap head . swap . fmap sjoin . unzip) . groupBy (on (==) fst) . sort . map ((\[w,p] -> (w, readInt p)) . words) . lines <$> getContents >>= mapM_ (\(w,p) -> putStrLn w >> putStrLn p)


Measured memory_bytes: 4072
## tasks https://atcoder.jp/contests/dp/tasks

def solution():
    # result array for calculation for optimal cost for every stone
    res = [None]*n
    res[0] = 0
    res[1] = abs(h[1]-h[0])
    for i in range(2, n):
        res[i] = min(res[i-1] + abs(h[i]-h[i-1]), res[i-2] + abs(h[i]-h[i-2]))

    return res[-1]

if __name__ == "__main__":
    n = int(input())

    # global scope actually
    h = list(map(int, input().split(" ")))

    print(solution())


Measured memory_bytes: 13928
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#else
#define print(...)
#endif

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<P> items(N);
    rep(i, N) {
        items[i] = make_pair(A[i], i);
    }
    sort(items.begin(), items.end(), [](P a, P b) {
        if (a.first == b.first) {
            return a.second > b.second;
        }
        return a.first > b.first;
    });
    items.push_back(make_pair(0, 0));
    print(items);
    vector<ll> ans(N, 0);
    ll m = INF;
    rep(i, N) {
        P p = items[i];
        P p2 = items[i + 1];
        ll d = abs(p.first - p2.first);
        m = min(m, p.second);
        ans[m] += d * (i + 1);
    }
    rep(i, N) {
        cout << ans[i] << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
//ofstream cout("output.out");

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

#define ll long long

int main(){
	
	fast();
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 1; i <= n; ++i){
		if(i % 3 != 0 && i % 5 != 0){
			ans += (ll)i;
		} 
	}
	cout << ans;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

class A {
	int N;
public:
	void solve()
	{
		if (N % 10 == 9 || ( N / 10 % 10 == 9)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	A() { cin >> N; }
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

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

ll n;
void dfs(ll now, int use, ll &res) {
  if (now > n) return;
  if (use == 0b111) res++;
  dfs(now*10+7, use | 0b001, res);
  dfs(now*10+5, use | 0b010, res);
  dfs(now*10+3, use | 0b100, res);
}

int main(){
  cin >> n;
  ll res = 0;
  dfs(0,0,res);
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define endl '\n'
const ll N = 22,mod = 1e9+7;
const ll t = (1<<N);
ll dp[t][N],n,mt[N][N];
using namespace std;

ll solve(ll s,ll k)
{
    if(!s && !k)
        return 1;
    if(dp[s][k]!=-1)
        return dp[s][k];
    ll c = 0;
    bitset<N> b = s;
    if(b.count()!=(k)){
        dp[s][k]=0;
        return dp[s][k];
    }
    for(int i=0;i<n;i++){
        if(b[i]==1 && mt[i][k-1]){
            //cout<<i<<" "<<k<<endl;
            ll tmp = s-(1<<i);
            c = (c+solve(tmp,k-1))%mod;
        }
    }
    //cout<<s<<" "<<k<<" "<<c<<endl;
    dp[s][k] = c;
  	return dp[s][k];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>mt[i][j];
    for(int i=0;i<t;i++)
        for(int j=0;j<N;j++)
            dp[i][j] = -1;
    dp[0][0]=1;
    ll p = (1<<n)-1;
    bitset<22> bb = p;
    ll ans = solve(p,n);
    cout<<ans<<endl;
}



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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"

ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}

int runtimeTerror()
{
	int n,i,j;
	map<string,int> m;
	cin >> n;
	string str;int mx=-1;
	for(i=0;i<n;++i)
	{
		cin>>str;
		m[str]++;
	}
	set<string> s;
	for(auto j:m)
	{
		mx=max(mx,j.S);
	}
	for(auto j:m)
	{
		if(j.S==mx)s.insert(j.F);
	}
	for(auto j:s)cout<<j<<endl;
}

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

	int tests=1;
	//cin>>tests;
	while(tests--)
		runtimeTerror();
	return 0;
}


Measured memory_bytes: 33280
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		int ret=0;
		for(int i=0;i<(1<<a);i++){
			if(__builtin_popcount(i)!=b)continue;
			int v=0;
			for(int j=0;j<a;j++)if(i&(1<<j))v+=j+1;
			if(v==c)ret++;
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1032