akhauriyash/Code-Regression huggingface dataset:
let id x = x
let (|>) x f = f x

let repeat f =
  let rec loop arr = function
    | 0 -> List.rev arr
    | n -> loop (f () :: arr) (n-1)
  in
  loop []

let n = Scanf.scanf "%d\n" (fun n -> n)
let a = repeat (fun () -> Scanf.scanf "%d " id) n

let select choose arr x = List.fold_left choose x arr
let max_list arr = select max arr min_int
let min_list arr = select min arr max_int

let () =
  let ma = max_list a in
  let mi = min_list a in
  Printf.printf "%d\n" (ma-mi)


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const ll mod = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int x; cin >> x;
	ll sum = 0;
	while (x >= 500)
	{
		sum += 1000;
		x -= 500;
	}
	while (x >= 5)
	{
		sum += 5;
		x -= 5;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

int main() {
  int i = 1;
  int a = -1;
  do {
    cin >> a;
    if (a == 0) {
      cout << i;
      break;
    }
    i++;
  } while(true);
  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main(){int n,i,j,p[9],h[32];char c;
for(cin>>n;n>0;n--){
 for(i=0;i<30;i++)h[i]=0;
 for(i=0;i<9;i++)cin>>p[i];
 for(i=0;i<9;i++){cin>>c;if(c=='G')p[i]+=10;if(c=='B')p[i]+=20;}
 for(i=0;i<9;i++)h[p[i]]++;
 for(i=0;i<30;i++)while(h[i]%3)for(j=0;j<3;j++)h[i+j]--;
 for(i=0;i<30;i++)if(h[i]<0)break;
 if(i-30)cout<<0<<endl;else cout<<1<<endl;}
return 0;}

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

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

    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            --a;
            sunuke[a]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (sunuke[i] == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    int N, M;
    string S;
    vector<string> target(1);
    vector<int> cnt(1);
    cin >> N;
    cin >> S;
    target.at(0) = S;
    cnt.at(0)++;
    bool x;
    for (int i = 1; i < N;i++){
        x = false;
        cin >> S;
        for (int j = 0; j < target.size();j++){
            if (target.at(j)==S){
                cnt.at(j)++;
                x = true;
                break;
            }
        }
        if (!x){
            target.push_back(S);
            cnt.push_back(1);
        }
    }
    cin >> M;
    for (int i = 0; i < M;i++){
        cin >> S;
        for (int j = 0; j < target.size();j++){
            if (target.at(j)==S){
                cnt.at(j)--;
                break;
            }
        }
    }
    int ans = 0;
    for (int j = 0; j < target.size();j++){
        if (cnt.at(j)>ans){
            ans = cnt.at(j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
//#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GrandGarden | diff GrandGarden.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GrandGarden.cpp && ./a.out

/*
 
 2/19/2019
 
 19:35-
 
 */

const int MAX_N=1e6+1;
LL H[MAX_N];
int N;

void solve() {
  int res=0;
  int l=-1;
  queue<II> Q;
  auto sweep=[&]() {
    dumpC(H,H+N);
    REP(i,N) {
      if((i==0&&H[i]>0)||(H[i-1]==0&&H[i]>0)) {
        l=i;
      }
      if((i==N-1&&H[i]>0)||(H[i]>0&&H[i+1]==0)) {
        dump(l,i);
        if(l!=-1) Q.emplace(l,i+1),l=-1;
      }
    }
  };
  sweep();
  while(SZ(Q)) {
    int t=SZ(Q);
    while(t--) {
      int l,r; tie(l,r)=Q.front(); Q.pop();
      int x=*min_element(H+l,H+r);
      dump(l,r,x);
      assert(x>0);
      res+=x;
      FOR(i,l,r) H[i]-=x;
    }
    sweep();
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>H[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const ll mod = 1e9 + 7;

ll extgcd(ll a, ll b, ll&x, ll&y)
{
  if (b == 0)
  {
    x = 1;
    y = 0;
    return a;
  }
  else
  {
    ll q = a / b;
    ll g = extgcd(b, a - q * b, x, y);
    ll z = x - q * y;
    x = y;
    y = z;
    return g;
  }
}

//modp逆元
ll inversemod(ll a, ll p)
{
  ll x, y;
  extgcd(a, p, x, y);
  x %= p;
  if (x < 0)
  {
    x += p;
  }
  return x;
}

int main()
{
  int n, k;
  cin >> n >> k;
  ll a[100100];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a, a + n);
  if (k == 1)
  {
    cout << 0 << "\n";
  }
  else
  {
    ll c[100100] = {0};
    c[k - 1] = 1;
    for (int i = k; i < n; i++)
    {
      c[i] = c[i - 1] * i;
      c[i] %= mod;
      c[i] *= inversemod(i - k + 1, mod);
      c[i] %= mod;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
      ans += (c[i] - c[n - i - 1]) * a[i];
      ans %= mod;
    }
    cout << (ans + mod) % mod << "\n";
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
  int64_t A,B;
    cin>>A>>B;
    int64_t a=min(A,B);
    int64_t b=max(A,B);
    if(a==b)
      cout<<2*a-2<<endl;
    else{
    int64_t c=a*b-1;
    int64_t J=powl(c,0.5);
      if(J*(J+1)<=c)
        J++;
    int64_t ans=J+(c/J)-2;
    cout<<ans<<endl;
    }
  
  
  }
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

int main() {
	string s;
	cin >> s;
	int cntt = 0, cnts = 0;
	rep(i, s.size()) {
		if (s[i] == 'S') {
			cnts++;
		}
		else {
			if (cnts != 0) {
				cnts--;
			}
			else {
				cntt++;
			}
		}
	}
	cout << cntt * 2 << endl;
	return 0;
}

Measured memory_bytes: 640
/*一次元DP*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
  IOS;
  ll n,w;
  cin>>n>>w;
  vector<ll> value(n),weight(n);
  rep(i,n) cin>>weight[i]>>value[i];
  ll dp[w+1];
  rep(i,w+1) dp[i]=0;
  rep(i,n) for(ll j=w;j>=0;j--) if(j-weight[i]>=0) dp[j]=max(dp[j],dp[j-weight[i]]+value[i]);
  cout<<dp[w]<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
  {
  int count[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
count[b-1][f-1][r-1]=count[b-1][f-1][r-1]+v;

      
    
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
        printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;





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

    ll n;
    cin >> n;
    ll ac = 0, wa = 0, tle = 0, re = 0;

    for (int i = 0; i < n; ++i) {
        string str;
        cin >> str;

        if (str == "AC") {
            ac++;
        } else if (str =="WA") {
            wa++;
        } else if (str == "TLE") {
            tle++;
        } else if (str == "RE") {
            re++;
        }
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

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

#define LARGE 1000000001
#define N 100001

typedef struct _card {
    char mark;
    int value;
} Card;

void swap(Card A[], int i, int j) {
    Card temp = A[i];
    A[i] = A[j];
    A[j] = temp;
}

int partition(Card A[], int p, int r) {
    int x = A[r].value;
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A[j].value <= x) {
            i++;
            swap(A, i, j);
        }
    }

    swap(A, r, i+1);

    return i+1;
}

void quickSort(Card A[], int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q + 1, r);
    }
}

void merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;

    Card L[N / 2 + 2], R[N / 2 + 2];
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    L[n1] = {' ', LARGE};
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    R[n2] = {' ', LARGE};

    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(Card A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main() {
    int n;

    cin >> n;
    char mark;
    int value;
    Card A[N], B[N];
    for (int i = 0; i < n; i++) {
        cin >> mark;
        cin >> value;
        A[i] = {mark, value};
        B[i] = {mark, value};
    }

    quickSort(A, 0, n - 1);
    mergeSort(B, 0, n);

    bool stable = true;
    for (int i = 0; i < n; i++) {
        if (A[i].mark != B[i].mark) {
            stable = false;
        }
    }

    if (stable) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }

    for (int i = 0; i < n; i++) {
        cout << A[i].mark << " " << A[i].value << endl;
    }
}


Measured memory_bytes: 5424
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
//#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

int a, b;
set <int> s;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("meetings.in", "r", stdin);
	//freopen("meetings.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> a >> b;
	s.insert(a);
	s.insert(b);
	for (int x = 1; x <= 3; x++)
		if (s.find(x) == s.end())
			cout << x;




	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

int main() {
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  vector<ll> v{h, w, h};

  ll ans = 10000000000000000;
  if (h % 3 == 0 or w % 3 == 0) ans = 0;
  else ans = min(ans, min(h, w));

  rep(i, 2) {
    ll au = v.at(i) % 2 == 0 ? v.at(i) / 2 : v.at(i) / 2 + 1;
    ll al = v.at(i) % 2 == 0 ? v.at(i) / 2 : v.at(i) / 2;
    for (int j = 1; j < v.at(i + 1); ++j) {
      ans = min(ans, max(v.at(i) * j, (v.at(i + 1) - j) * au) - min(v.at(i) * j, (v.at(i + 1) - j) * al));
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n, a[MAXN], b[MAXN];

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> n;
	rep(i, 1, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a+1, a+1+n);
	rep(i, 1, n) {
		if(b[i] <= a[n/2]) cout << a[n/2+1] << '\n';
		else cout << a[n/2] << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, F[101][11], P[101][11];
int main(){
    cin >> N;
    REP(i, N) REP(j, 10) cin >> F[i][j];
    REP(i, N) REP(j, 11) cin >> P[i][j];
    int ans = (-1) * INT_MAX/2;
    for(int msk = 1; msk < 1 << 10; msk++){
        int sm = 0;
        REP(i, N){
            int c = 0;
            REP(j, 10) if(msk & (1 << j)) if(F[i][j]) c++;
            sm += P[i][c];
        }
        ans = max(ans, sm);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
count = 0

for k in range(x+1):
    kame = k
    turu = x-k
    ashi = 2*turu + 4*kame
    if ashi==y:
        count += 1
        break

if count>0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9188
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
#include<map>
#include<bitset>
#include<array>
#include<cmath>
#include<functional>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const llint big=2e18+100000;
const int mod=1e9+7;
const lldo eps=1e-7;
const long double pai=3.141592653589793238462643383279502884197;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
#define dme(in) cout<<in<<endl;return 0
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	int i,n;cin>>n;
	vector<tuple<llint,int,int>>hen(n-1);
	vector<int>oya(n);
	vector<int>siz(n,1);
	vector<llint>imo(n);//下方向
	for(i=0;i<n;i++){oya[i]=i;}
	for(i=0;i<n-1;i++){
		int a,b,c;cin>>a>>b>>c;a--;b--;
		hen[i]=mt(c,a,b);
	}
	sort(hen.rbegin(),hen.rend());
	//すぬけ 木である必要はない
	for(i=0;i<n-1;i++){
		int a,b;llint c;
		tie(c,a,b)=hen[i];
		while(a!=oya[a]){a=oya[a];}
		while(b!=oya[b]){b=oya[b];}
		if(a==b){continue;}
		if(siz[a]<siz[b]){swap(a,b);}
		imo[a]+=c*siz[b];
		imo[b]+=c*siz[a]-imo[a];
		siz[a]+=siz[b];
		oya[b]=a;
	}
	vector<pair<int,int>>miru(n);
	for(i=0;i<n;i++){miru[i]=mp(siz[i],i);}
	//子のほうがサイズが小さいので親から見る=サイズの大きい順
	sort(miru.rbegin(),miru.rend());
	for(i=1;i<n;i++){//最大は根なので
		imo[miru[i].sec]+=imo[oya[miru[i].sec]];
	}
	for(i=0;i<n;i++){cout<<imo[i]<<endl;}
	return 0;
}

Measured memory_bytes: 5632
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <set>
int read(){
	register int x = 0;
	register char ch = getchar(), f = 1;
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = !f;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
#define N 5005
const int B1 = 233, P1 = 382538579, B2 = 331, P2 = 952959323;
int pw1[N], pw2[N];
struct node{
	int H1, H2;
	node(int _H1 = 0, int _H2 = 0){ H1 = _H1, H2 = _H2; }
	bool operator < (const node &rhs) const {
		return H1 < rhs.H1 || (H1 == rhs.H1 && H2 < rhs.H2);
	}
	bool operator == (const node &rhs) const {
		return H1 == rhs.H1 && H2 == rhs.H2;
	}
	node operator + (const char ch) const {
		return node((1ll * H1 * B1 + ch) % P1, (1ll * H2 * B2 + ch) % P2);
	}
	node operator - (const node &rhs) const {
		return node((H1 - rhs.H1 + P1) % P1, (H2 - rhs.H2 + P2) % P2);
	}
	node operator << (const int x) const {
		return node(1ll * H1 * pw1[x] % P1, 1ll * H2 * pw2[x] % P2);
	}
}h[N];
int n;
char a[N];
int main(){
	scanf("%d%s", &n, a + 1);
	pw1[0] = pw2[0] = 1;
	for (register int i = 1; i <= n; ++i)
		pw1[i] = 1ll * pw1[i - 1] * B1 % P1, pw2[i] = 1ll * pw2[i - 1] * B2 % P2;
	for (register int i = 1; i <= n; ++i) h[i] = h[i - 1] + a[i];
	for (register int len = n >> 1; len; --len){
		std :: set<node> S;
		for (register int i = len << 1; i <= n; ++i){
			S.insert(h[i - len] - (h[i - (len << 1)] << len));
			if (S.count(h[i] - (h[i - len] << len))) return printf("%d\n", len), 0;
		}
	}
	printf("0\n");
}


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

int main() {
  // input
  int N;  cin >> N;
  int total = 0, a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    total += a;
  }
  
  // output
  cout << total - N << endl;
  
  return 0;
}

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

int main()
{
	int h1, m1, h2, m2, k;
	scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
	int t = h2 * 60 + m2 - h1 * 60 - m1;
	if (t < 0) t = -t;
	printf("%d\n", max(0, t - k));
	return 0;
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

int main() {
    FIO
    string s;
    cin>>s;
    bool fc=false, ff = false;
    int len = s.size();
    for(int i=0; i<len; i++)
    {
        if(s[i] == 'C')
            fc = true;
        if(fc && s[i] == 'F')
        {
            ff = true;
            break;
        }
    }
    if(fc && ff)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}


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

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

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll R, G, B, N;
    cin >> R >> G >> B >> N;

    ll ans = 0;

    for (ll r=0;r<=N;r+=R)
    {
        for (ll g=0;r+g<=N;g+=G)
        {
            const ll b = N - r - g;

            if (b == 0 || (b % B) == 0)
            {
                ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b,c,n;
	int sum=0;
	scanf("%d %d %d",&a,&b,&c);
	for(n=1;n<=10000;n++){
		if(c%n==0){
			if(n>=a){
				if(n<=b){
					sum=sum+1;
				}
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 2112
import scala.io.Source.stdin

object Main extends App {
  stdin.getLines.foreach { s =>
    val n = s.split(" ").map(_.toInt)
    val sum = n(0)+n(1)
    if(sum <= 10) println("YES")
    else if((1 to 10).filter( i => i!=n(0) && i!=n(1) && i!=n(2) ).count( _ <= 20-sum ) >= 4)
      println("YES")
    else
      println("NO")
  }
}

Measured memory_bytes: 43964
#include<stdio.h>

int main(void)
{
  int a;
  int b;
  int c;
  int i;
  
  scanf("%d", &a);
  scanf("%d", &b);
  
  c = b - (a - 1);

    for(i = c; i <= b + a - 1; i++){
      printf("%d ", i);
    }
  return 0;
}
  





Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define REP(i, n) for(int i = 0; i < n; i++)
#define INF 1000000000000 //10^12
typedef long long ll;

typedef struct edge {int a, b; ll c;} E;
typedef struct graph {
  int vcnt, ecnt;
  E e[40010];
  int id[200];
} G;

int esort(const void *a, const void *b){
  E *A = (E *)a, *B = (E *)b;
  return A->a - B->a;
}

void MakeGraph(G *g, int n, int m){
  g->vcnt = n; g->ecnt = 2 * m;

  int x, y; ll z;
  REP(i, g->ecnt/2){
    scanf("%d %d %lld", &x, &y, &z);
    x--; y--;
    g->e[2 * i].a = x; g->e[2 * i].b = y; g->e[2 * i].c = z;
    g->e[2 * i + 1].a = y; g->e[2 * i + 1].b = x; g->e[2 * i + 1].c = z;
  }

  qsort(g->e, g->ecnt, sizeof(E), esort);

  int p = 0;
  REP(i, g->vcnt){
    while(p < g->ecnt && g->e[p].a < i) p++;
    g->id[i] = p;
  }
  g->id[n] = g->ecnt;
}

ll d[200][200];

void shortest(int s, G *g){
  for(int i = 0; i < g->vcnt; i++) d[i][s] = INF;
  d[s][s] = 0;
  while(true){
    bool update = false;
    for(int i = 0; i < g->ecnt; i++){
      E e = g->e[i];
      if(d[e.a][s] != INF && d[e.b][s] > d[e.a][s] + e.c){
	d[e.b][s] = d[e.a][s] + e.c;
	update = true;
      }
    }
    if(!update) break;
  }
}

/*ll get_d(int i, int s, G *g){
  if(i == s) return 0;
  if(d[i][s] != 0) return d[i][s];
  d[i][s] = 1000000000;
  for(int j = g->id[i]; j < g->id[i + 1]; j++){
    d[i][s] = Min(d[i][s], g->e[j].c + get_d(g->e[j].b, s, g));
  }
  return d[i][s];
  }*/

int array[10], visited[10], r[100], R;
void solve(int i, ll *ans, G *g){
  if(i == R){
    ll a = 0;
    REP(j, R - 1) a += d[r[array[j + 1]]][r[array[j]]];
    *ans = Min(*ans, a);
    return;
  }
  for(int j = 0; j < R; j++){
    if(visited[j] == 0){
      visited[j] = 1;
      array[i] = j;
      solve(i + 1, ans, g);
      visited[j] = 0;
    }
  }
  return;
}
      

int
main(int argc, char *argv[])
{
  int n, m; G g;
  scanf("%d %d %d", &n, &m, &R);
  REP(i, R){
    scanf("%d", &r[i]);
    r[i]--;
  }
  MakeGraph(&g, n, m);

  for(int i = 0; i < n; i++) shortest(i, &g);
  ll ans = 1000000000000;
  solve(0, &ans, &g);

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 1404
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v) {std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

#define EPS 1e-8
#define EQ(a, b) (abs((a) - (b)) < EPS)

typedef complex<double> P;

P getMiddle(P a, P b) {
    return (a + b) / 2.0;
}

P getUnit(P a) {
    return a / abs(a);
}

pair<P, P> getNormals(P a) {
    return make_pair((a / abs(a)) * P(0, 1), (a / abs(a)) * P(0, -1));
}

int main() {

    while (true) {

        int N;
        cin >> N;

        if (N == 0) break;

        vector<P> points(N);
        for (int i = 0; i < N; i++) {
            double x, y;
            cin >> x >> y;
            points[i] = P(x, y);
        }

        int maxV = 1;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {

                P p1 = points[i];
                P p2 = points[j];
                P middle = getMiddle(p1, p2);

                double a, b, c;
                b = abs(middle - p2);
                c = 1.0;
                if (b * b + EPS > 1.0) continue;
                a = sqrt(1.0 - b * b);

                P o1 = middle + ((p2 - p1) / abs(p2 - p1)) * P(0, 1) * a;
                P o2 = middle + ((p2 - p1) / abs(p2 - p1)) * P(0, -1) * a;

                int count = 0;
                for (int k = 0; k < N; k++) {
                    double dx = o1.real() - points[k].real();
                    double dy = o1.imag() - points[k].imag();
                    if (dx * dx + dy * dy < 1.0 + EPS) count++;
                }
                maxV = max(maxV, count);

                count = 0;
                for (int k = 0; k < N; k++) {
                    double dx = o2.real() - points[k].real();
                    double dy = o2.imag() - points[k].imag();
                    if (dx * dx + dy * dy < 1.0 + EPS) count++;
                }
                maxV = max(maxV, count);
            }
        }

        cout << maxV << endl;

    }

    return 0;
}














































Measured memory_bytes: 3276
function main()
	N,M=map(x->parse(Int32,x),split(readline()))
	rank=ones(Int,N)
	parent=collect(1:N)
	dweight=zeros(Int,N)
	function find(a)
		if parent[a]==a
			a
		else
			ar=find(parent[a])
			dweight[a]+=dweight[parent[a]]
			parent[a]=ar
		end
	end
	function weight(a)
		find(a)
		dweight[a]
	end
	same(a,b)=find(a)==find(b)
	function unite(a,b,w)
		w+=weight(a)
		w-=weight(b)
		a=find(a)
		b=find(b)
		if a==b
			false
		elseif rank[a]<rank[b]
			parent[a]=b
			dweight[a]=-w
			rank[b]+=rank[a]
			true
		else
			parent[b]=a
			dweight[b]=w
			rank[a]+=rank[b]
			true
		end
	end
	diff(a,b)=weight(b)-weight(a)
	for s=readlines()
		L,R,D=map(x->parse(Int32,x),split(s))
		if same(L,R)
			if diff(L,R)!=D
				println("No")
				exit()
			end
		else
			unite(L,R,D)
		end
	end
	println("Yes")
end
main()


Measured memory_bytes: 166276
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion 

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

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

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define printpair(v) for(auto val: v){cout<<val.fi<<":"<<val.se<<", ";}cout<<endl;
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define ln length()
const int mod = 1e9+7;
#define sz size()
const int inf = 1e18;

void solve() {
    int n;
    cin>>n;
    vector<pi> v;
    int a,b;
    multiset <int > m;
    multiset <int> m1;
    rep(i,0,n){
        cin>>a>>b;
        v.pub({a,b});
        m.insert(a+b);
        m1.insert(a-b);
    }
    sort(v.begin(),v.end());
    int ans=0;
    repd(i,n-1,1){
        m.erase(m.find(v[i].fi+v[i].se));
        m1.erase(m1.find(v[i].fi-v[i].se));
        auto lol= *m.begin();
        auto lol1 = *m1.begin();
        ans=max(ans,((v[i].fi+v[i].se))-lol);
        ans=max(ans,((v[i].fi-v[i].se))-lol1);


    }
    cout<<ans<<endl;

}

int32_t main(){
    fastIO
#ifndef ONLINE_JUDGE
    freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin);
#endif
    int t=1;
//    cin>>t;
    while(t--){
        solve();
//        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 25060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int a,b,h;
int ans[100005];

int main(void) {
	map<int, int>mp;
	cin >> a >> b >> h;
	mp[a]++; mp[b]++; mp[h]++;
	ct(mp.size());
	
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		int i,j;
		int[][] list=new int[4][13];
		for(i=0;i<4;i++){
			for(j=0;j<13;j++){
				list[i][j]=0;
			}
		}
		String str=br.readLine();
		int n=Integer.parseInt(str);
		for(i=0;i<n;i++){
			String[] card=br.readLine().split(" ");
			String mark=card[0];
			int num=Integer.parseInt(card[1]);
			if(mark.equals("S")){
				list[0][num-1]=1;
			}
			else if(mark.equals("H")){
				list[1][num-1]=1;
			}
			else if(mark.equals("C")){
				list[2][num-1]=1;
			}
			else if(mark.equals("D")){
				list[3][num-1]=1;
			}
		}
		for(i=0;i<4;i++){
			for(j=0;j<13;j++){
				if(list[i][j]==0){
					if(i==0){
						sb.append("S ").append(j+1).append("\n");
					}
					else if(i==1){
						sb.append("H ").append(j+1).append("\n");
					}
					else if(i==2){
						sb.append("C ").append(j+1).append("\n");
					}
					else if(i==3){
						sb.append("D ").append(j+1).append("\n");
					}
				}
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 24364
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll dp[110000];
ll h[110000];


int main(){
	/*#ifndef ONLINE_JUDGE
	freopen("/home/shubham/Desktop/codes/input.txt", "r", stdin);
	freopen("/home/shubham/Desktop/codes/output.txt", "w", stdout);
	#endif*/

	
	ll n,k;
	cin>>n>>k;
	for(ll i=0; i<n; i++){
		cin>>h[i];
		dp[i] = mod;
	}
	dp[0] = 0;
	for(ll i=0; i<n; i++){
		for(ll j=1; j<=k; j++){
			if(n>i+j){
				dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
			}
		}
	}
	cout<<dp[n-1];

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,ans = 9999999;
    scanf("%d",&n);
    for (int i = 1;i < n;i++) {
        int tmp = i,sum = 0;
        while (tmp) {
            sum += tmp%10;
            tmp /= 10;
        }
        tmp = n-i;
        while (tmp) {
            sum += tmp%10;
            tmp /= 10;
        }
        ans = min(ans,sum);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
while True:
    n = input()
    if n == 0:
        break
    W, H = map(int, raw_input().split())
    p = set()

    for _ in range(n):
        x, y = map(int, raw_input().split())
        p.add((x, y))

    S, T = map(int, raw_input().split())

    mcnt = 0
    for col in range(W - S + 1):
        for row in range(H - T + 1):
            cnt = 0
            pp = set()
            for i in range(col, col + S):
                for j in range(row, row + T):
                    if (i + 1, j + 1) in p:
                        cnt += 1
                        pp.add((i, j))
            mcnt = max(mcnt, cnt)
    print mcnt

Measured memory_bytes: 6376
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=100005;
int n,a[N],b[N],f0=1,mn=1e9;
LL sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]),sum+=a[i];
	for(int i=1;i<=n;i++)
	  if(a[i]!=b[i]) f0=0;
	if(f0) {puts("0");return 0;}
	for(int i=1;i<=n;i++)
	  if(a[i]>b[i]) mn=min(mn,b[i]);
	printf("%lld\n",sum-mn);
	return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int a, b;
  cin >> a >> b;
  if (1 <= a && a <= 9 && 1 <= b && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from bisect import bisect_right
from random import randint
from copy import deepcopy


def calculate_score(i: int, last_i, S, D: int, C: list, T):
    rst = 0
    for d in range(1, D + 1):
        down = C[i] * (d - last_i[d])
        up = S[d][i] if i == T[d] else 0
        rst += up - down
    return rst


def create_last_i(i, T, D):
    _last_i = [0] * (D + 1)
    for d in range(1, D + 1):
        if T[d] == i:
            _last_i[d] = d
        else:
            _last_i[d] = _last_i[d - 1]
    return _last_i


def main():
    Z = 26
    D = int(input())
    C = list(map(int, input().split()))
    S = [tuple([None] * Z)] + [tuple(map(int, input().split())) for _ in range(D)]

    last = [0] * Z
    T = [0]
    for d in range(1, D + 1):
        maxScore = -float('inf')
        cntst = 0
        for i in range(26):
            tmp = last[i]
            last[i] = d
            up = S[d][i]
            down = sum(C[j] * (d - last[j]) for j in range(Z))
            score = up - down
            if maxScore < score:
                cntst = i
                maxScore = score
            last[i] = tmp
        last[cntst] = d
        T.append(cntst)

    last = [None] * Z
    V = [0] * Z
    for i in range(Z):
        last[i] = create_last_i(i, T, D)
    for i in range(Z):
        V[i] = calculate_score(i, last[i], S, D, C, T)

    score = sum(V)
    maxScore = score
    maxT = deepcopy(T)
    # print('Initial Score: ', score)

    max_iter = 10 ** 4
    for _ in range(max_iter):
        d = randint(1, D)
        q = randint(0, Z - 1)

        p = T[d]
        if p == q:
            continue

        T[d] = q
        last_p = create_last_i(p, T, D)
        last_q = create_last_i(q, T, D)

        Vp = calculate_score(p, last_p, S, D, C, T)
        Vq = calculate_score(q, last_q, S, D, C, T)
        if V[p] + V[q] < Vp + Vq:
            score -= V[p] + V[q]
            score += Vp + Vq
            V[p] = Vp
            V[q] = Vq
            last[p] = last_p
            last[q] = last_q
        else:
            T[d] = p

    if score > maxScore:
        for i in range(1, D + 1):
            print(T[i] + 1)
    else:
        for i in range(1, D + 1):
            print(maxT[i] + 1)
    # print(score)
    # for d in range(1, D + 1):
    #     print(T[d] + 1)


if __name__ == "__main__":
    main()


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

int main(){
  int n; cin >> n;
  vector<int> s(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
    ans += s.at(i);
  }
  if(ans % 10 != 0){
    cout << ans << endl;
    return 0;
  }
  sort(s.begin(), s.end());
  bool ok = false;
  for(int i = 0; i < n; i++){
    if(s.at(i) % 10 != 0){
      ans -= s.at(i);
      cout << ans << endl;
      ok = true;
    }
    if(ok) break;
  }
  if(!ok) cout << 0 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

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

typedef struct {
  int B[3][3];
}board;

board P,Q;

int dfs(int,int,int,int,int);
int heuri(void);
void move(int,int);

int main() {
  int i, j,k, x, y, time;
  board S;

  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      scanf("%d", &P.B[i][j]);
      if (P.B[i][j] == 0) {
	x = j;
	y = i;
      }
    }
  }

  S = P;

  for (i = 1; i < 46; i++) {
    P = S;

    time = dfs(x, y, i, 0, -1);
    if (time != -1) {
      printf("%d\n", time);
      break;
    }
  }

  return 0;
}

int dfs(int x, int y, int max, int cnt, int n) {
  int i, temp, x0, y0, time, h;

  h = heuri();
  if (h == 0) return cnt;
  else if (cnt + h > max) return -1;

  for (i = 0; i < 4; i++) {
    x0 = x + dx[i];
    y0 = y + dy[i];

    if ((i == (n + 2) % 4 && n != -1) || (x0 < 0 || 3 <= x0 || y0 < 0 || 3 <= y0)) continue;
    temp = P.B[y][x];
    P.B[y][x] = P.B[y0][x0];
    P.B[y0][x0] = temp;

    time = dfs(x0, y0, max, cnt + 1, i);

    if (time != -1) return time;
    temp = P.B[y][x];
    P.B[y][x] = P.B[y0][x0];
    P.B[y0][x0] = temp;
  }

  return -1;
}

int heuri() {
  int i, j, x, y, sum = 0;

  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      if (P.B[i][j] == 0) continue;

      x = (P.B[i][j] - 1) % 3 - j;
      y = (P.B[i][j] - 1) / 3 - i;

      if (x < 0) sum -= x;
      else sum += x;

      if (y < 0) sum -= y;
      else sum += y;
    }
  }

  return sum;
}

void move(int x,int y){

}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define ll long long int
#define MOD1        1000000007
#define MOD2        998244353
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

ll n, k, c;
string s;
vector<vector<ll> >ans;
vector<ll> row;
ll a[200010], b[200010];
void backtrack(ll pos, ll daysLeft)
{
    if(daysLeft == 0)
    {
        ans.push_back(row);
        return;
    }
    if(pos >= n)
        return;
    if(s[pos] == 'x')
        backtrack(pos+1, daysLeft);
    else
    {
        row.push_back(pos);
        backtrack(pos+c+1, daysLeft-1);
        row.pop_back();
        backtrack(pos+1, daysLeft);
    }
}

void solve()
{
    cin >> n >> k >> c >> s;
    ll cnt = 0;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'o')
        {
            a[cnt++] = i;
            i += c;
        }
    }
    cnt = 0;

    for(int i = n-1; i >= 0; --i)
    {
        if(s[i] == 'o')
        {
            b[cnt++]=i;
            i -= c;
        }
    }
    // for(int i = 0; i < k; i++)
    //     cout << a[i] << " " << b[i] << "\n";
    for(int i = 0; i < k; ++i)
    {
        if(a[i] == b[k-i-1])
            cout << a[i] + 1 << "\n";
    }
    /*
    Find the earliest and latest day of
    the i-th working day. If for some i they are the same,
    this is a day bound to work.
    */
}


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

    ll t = 1;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}

Measured memory_bytes: 4996
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  int res=0;
  while(n>0){
    n /= k;
    res++;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>S;
    N=S.size();
    ll inx1,inx2;
    rep(i,N){
        if(S[i]=='A'){
            inx1=i;
            break;
        }
    }

    rep(i,N){
        if(S[N-1-i]=='Z'){
            inx2=N-1-i;
            break;
        }
    }
    
    cout << inx2-inx1+1 << endl;


    return 0;
    

}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define lli long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int const mod = 1e9+7;
int power(int a,int b){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= mod;
        }
        a=a*a;
        a%=mod;
        b=b/2;
    }
    return res;
}
 
// int inverse_mod(int x){
//     return power(x,mod-2);
// }

int const N = 2e5+5;
int a0[60];
int a1[60];

void solve(){
    int i,j,l;
    int n;
    cin>>n;
    int ans = 0;
    for(i=0;i<n;i++){
        int x;
        cin>>x;
        for(j=0;j<60;j++){
            if(x&(1LL<<j)){
                ans = ans + (a0[j]*power(2,j))%mod;
                ans %= mod;
                a1[j]++;
            }
            else{
                ans = ans + (a1[j]*power(2,j))%mod;
                ans%=mod;
                a0[j]++;
            }
        }
        // cout<<ans<<endl;
    }

    cout<<ans<<endl;
}       


int32_t main(){
    IOS;
    int t;
    t = 1;
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256