akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// 参考：https://qiita.com/drken/items/1b7e6e459c24a83bb7fd
// 1-indexed BIT
// add:log(N),sum:log(N),get_k-th:log(N)
// https://codeforces.com/contest/1354/problem/D
struct BIT {
    vector<ll> dat;

    BIT(int n) {
        dat.resize(n + 1);
        for(int i = 0; i < (int)dat.size(); i++)
            dat[i] = 0;
    }

    // a is 1-indexed
    void add(int a, ll x) {
        for(int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    // [1,a], a is 1-indexed
    ll sum(int a) {
        ll res = 0;
        for(int i = a; i > 0; i -= i & -i) {
            res = res + dat[i];
        }
        return res;
    }

    // [a,b), a and b are 1-indexed
    ll sum(int a, int b) { return sum(b - 1) - sum(a - 1); }

    // k-th number (k is 1-indexed)
    // lower_bound
    int get(ll k) {
        if(k <= 0)
            return 0;
        int res = 0;
        int N = 1;
        while(N < (int)dat.size())
            N *= 2;
        for(int i = N / 2; i > 0; i /= 2) {
            if(res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N);
    rep(i, N) cin >> C[i];
    vector<int> last(N + 1, -1);
    vector<pair<pii, int>> query(Q);
    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        query[i] = MP(MP(r, l), i);
    }
    vector<int> res(Q);
    sort(All(query));
    int lastr = query[0].first.first;
    BIT bit(N + 1);
    rep(i, lastr) { last[C[i]] = i + 1; }
    rep(i, N + 1) {
        if(last[i] != -1)
            bit.add(last[i], 1);
    }
    rep(i, Q) {
        for(int j = lastr + 1; j <= query[i].first.first; j++) {
            int tmp = last[C[j - 1]];
            last[C[j - 1]] = j;
            if(tmp > 0)
                bit.add(tmp, -1);
            bit.add(j, 1);
            lastr = query[i].first.first;
        }
        res[query[i].second] =
            bit.sum(query[i].first.second, query[i].first.first + 1);
    }
    rep(i, Q) { cout << res[i] << endl; }
    return 0;
}

Measured memory_bytes: 19432
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

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

    int sum = 0;
    map<int, int> data;
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        data[a]++;
        sum++;
        if(data[a] == a){
            sum -= a;
        }
    }
    cout << sum << endl;
}

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

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

    ll ans = N - 1;
    for(ll i = 2; i * i <= N; i++) {
        if(N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }

    cout << ans << "\n";
    return 0;
}


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

class Main implements Comparable{
    public int id,res;
    Main(){id=0;res=0;}
    Main(int i){id = i;res= 0;}
    public int compareTo(Object a){
	if (this.res !=  ((Main)a).res)return this.res-((Main)a).res;
	return this.id - ((Main)a).id;
    }

    public static void main(String args[]){
	int n;
	Scanner in = new Scanner(System.in);
	n = in.nextInt();
	Main all[] = new Main[n];
	for(int i=0;i<n;i++){
	    all[i] = new Main(i+1);
	}

	for(int i=0;i<n;i++){
	    for(int j=i+1;j<n;j++){
		int a,b,c,d;
		a = in.nextInt();
		b = in.nextInt();
		c = in.nextInt();
		d = in.nextInt();
		a--;
		b--;

		int[] p = {0,0};
		if (c > d)p[0]=3;
		else if (c == d){
		    p[0]=1;
		    p[1] = 1;
		}else p[1] = 3;
		
		//System.out.println(a + " " + b + " " + p[0] + " " + p[1]);
		all[a].res += p[0];
		all[b].res += p[1];
	    }
	}
	//for(int i=0;i<n;i++)System.out.println(all[i].id + " " + all[i].res);
	for(int i=0;i<n;i++){
	    int cnt = 0;
	    for(int j=0;j<n;j++){
		if (all[i].res < all[j].res)cnt++;
	    }
	    System.out.println(cnt+1);
	}
	
    }
}

Measured memory_bytes: 13000
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
typedef pair<long long, long long> pll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//2リットルサイズ以外は、サイズは考えなくて良い
int main() {

    ll Q,H,S,D,res,N;

    cin >> Q >> H >> S >> D;
    cin >> N;
    
    ll iMinWithoutD = INF;
    ll iMin = INF;
    iMinWithoutD = min(iMinWithoutD, Q * 4);
    iMinWithoutD = min(iMinWithoutD, H * 2);
    iMinWithoutD = min(iMinWithoutD, S);

    iMin = min(iMinWithoutD * 2,D);

    if(iMin == Q * 4 * 2)
    {
        res = Q * 4 * N;
    }
    else if(iMin == H * 2 * 2)
    {
        res = H * 2 * N;
    }
    else if(iMin == S * 1 * 2)
    {
        res = S * 1 * N;
    }
    else//D
    {
        ll tmp = N / 2;
        res = tmp * D;
        if(N % 2 == 1)
        {
            res += iMinWithoutD;
        }
    }


    cout << res << endl;

    return 0;
    
}

Measured memory_bytes: 256
def getInteriorRadian(n)
  return Math.asin(Math.sqrt(n) / n)
end

def solve(n)
  result = Array.new
  s = Math.sqrt(n)
  result << s * Math.cos(@radian[n - 2])
  result << s * Math.sin(@radian[n - 2])
  return result
end

@radian = [getInteriorRadian(2)]
(3..1000).each{|n|
  @radian << getInteriorRadian(n) + @radian[n - 3]
}

loop do
  break if (n = $stdin.gets.to_i) == -1
  result = solve(n)
  p result[0], result[1]
end

Measured memory_bytes: 6196
#import numpy as np
#import math
#from decimal import *
#from numba import njit
from collections import Counter

#@njit
def main():
    S = input()
    A = list(map(int, S))[::-1]
    mod = []
    ten = 10
    for i in range(len(A)):
        if i == 0:
            mod += A[i],
        else:
            mod += (mod[i-1]+ten*A[i])%2019,
            ten = (ten*10)%2019
    mod += 0,

    C = Counter(mod)
    print(sum([c*(c-1)//2 for c in C.values()]))

main()

Measured memory_bytes: 18984
#include<iostream>

using namespace std;

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

int main(){
	int r, d, x;
	cin >> r >> d >> x;
	int ans = x;
	rep(i, 10){
		ans = ans * r - d;
		cout << ans << endl; 
	}	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

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

  vector<string> W(N);

  for (int i = 0; i < N; i++) {
    cin >> W[i];
//     cout << i << ": " << W[i] << endl;
    if (i > 0 && W[i-1][W[i-1].size() - 1] != W[i][0]) {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < i; j++) {
      if (W[i] == W[j]) {
	cout << "No" << endl;
	return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	ll n;
	cin >> n;
	ll res = INF;
	for (ll i = 1; i * i <= n; ++i) {
	  if (n % i != 0) continue;
	  res = min(res, i + n / i - 2);
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3668
#include<stdio.h>
int main(void){
    int n,m,i,j,c=0;
    int a[100][100],b[100];
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c+=a[i][j]*b[j];
        }
        printf("%d\n",c);
        c=0;
    }
    return 0;
}


Measured memory_bytes: 2104
/**
 * ?????£?????????

???????????¢????????????????????????????????? n ???????????????????±±????????£?????????????????????

1???????????£???????????§??????????????? h
???????????????????????¨???????????????????????????????????£????????????????±±??????????????????????????????

?????????????±±?????\???????????????????????????????????§?????????????????????

abcdeefab
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

????????°???????????? h ??? 4 ??§?????£?????????????????¨????????????4?????? abcd ????????????????????? eefab
???????°??????£?????????????????§??\??????????????????????????????

eefababcd
???????????£???????????????????????°??????????????????

?????????????±±???????????????????????????????????¨ h
?????????????????????????????????????????????????????????????????????????????°?????????????????????????????????

Constraints
?????????????????????200????¶??????????
?????£?????????????????°???100????¶??????????
Input
?????°??????????????????????????\?????¨?????????????????????????????????????????????????????\????????¢?????§?????????????????????

????????????????????¨????????????
?????£??????????????° m
h1
h2
  .
  .
hm
????????????????????¨??????????????? "-" ?????¨?????\?????????????????¨????????????

Output
??????????????????????????????????????????????????????????????????????????????????????????????????????

Sample Input
aabc
3
1
2
1
vwxyz
2
3
4
-
Sample Output
aabc
xyzvw
 */

#include <iostream>
#include <sstream>

int main(int argc, char const *argv[]) {
  unsigned int h;
  std::string Cards;

  while (true) {
    unsigned int m = 0;
    std::istringstream iss;
    std::string Param;

    getline(std::cin, Cards);
    if (Cards == "-") {
      break;
    } else {
      getline(std::cin, Param);
      iss.str(Param);
      iss >> m;
      iss.clear();
      for (size_t i = 0; i < m; i++) {
        getline(std::cin, Param);
        iss.str(Param);
        iss >> h;
        iss.clear();
        Cards = Cards.substr(h, Cards.length() - h) + Cards.substr(0, h);
      }
      std::cout << Cards << std::endl;
    }
  }
  return 0;
}

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

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

const long long INF = LLONG_MAX/3;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

signed main(){
	int h,n;
	cin>>h>>n;
	int a[100010];
	rep(i,n)cin>>a[i];
	int s=0;
	rep(i,n)s+=a[i];
	if(h<=s)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
using namespace std;
 
int main()
{
	
    fastio
    ll n, x, flag=0;
  __int128 ans=1, comp=1000000000000000000;
  cin>>n;
  for(int i=0; i<n; i++)
  {
    cin>>x;
    ans*=x;
    if(x==0)
    {
      flag=2;
      break;
    }
    if(ans>comp)
    {
      flag=1;
    }
  }
  ll rans;
  if(flag==1)
  {
    rans=-1;
  }
  else if(flag==2)
  {
    rans=0;
  }
  else
  {
    rans=ans;
  }
  cout<<rans;
}

Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

//二項係数
const int MAX = 2010000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 前処理 COMinit();
// 計算例 cout << COM(100000, 50000) << endl;

int main()
{
  ll X,Y; cin>>X>>Y; if((X+Y)%3!=0) {cout<<0<<endl; return 0;}
  ll i=(2*X-Y)/3,j=(2*Y-X)/3;
  COMinit();
  cout<<C(i+j,i)<<endl;
  return 0;
}

Measured memory_bytes: 50748
#include <stdio.h>

int main(void) 
{
    int H, W, i, j;
    while (1) 
    {
        scanf("%d %d", &H, &W);

        if ((H == 0) && (W == 0)) 
        {
            break;
        }

        for (i = 0; i < H; i++) 
        {
            for (j = 0; j < W; j++) 
            {
                printf("#");
            }

            printf("\n");
        }

        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    repi(i, n, 0)
    {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    auto d = [](const string& s) {
        int ans = 0;
        for (const char c : s) { ans += c - '0'; }
        return ans;
    };
    int ans = 1 << 30;
    for (int i = 1; i < N; i++) {
        ans = min(ans, d(to_string(i)) + d(to_string(N - i)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{
    int n;
    int count[100000] = {};
 
    cin >> n;
    int m1;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &m1);
        count[m1]++;
        if (m1 - 1 >= 0)
            count[m1 - 1]++;
        if (m1 + 1 < 100000)
            count[m1 + 1]++;
    }
 
    int max = 0;
    for (int i = 0; i < 100000; i++)
    {
        if (count[i] > max)
            max = count[i];
    }
 
    cout << max << endl;
 
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#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;
string s,t;
int dp[3010][3010];
int main()
{
  cin >> s >> t;
  int ss = s.size(),ts = t.size();

  rep(i,ss+1){
    rep(j,ts+1){
      dp[i][j] = 0;
    }
  }
  
  rep(i,ss){
    rep(j,ts){
      if(s[i]==t[j]){
	dp[i+1][j+1] = max( dp[i][j]+1 , max( dp[i][j+1] , dp[i+1][j] ) ); 
      }
      else{
	dp[i+1][j+1] = max( dp[i][j+1] , dp[i+1][j] );
      }
    }
  }
  
  string res = "";
  int x = ss,y = ts;
  while(y>0){
    if( dp[x][y] == dp[x][y-1] ) y--;
    else if( dp[x][y] ==dp[x-1][y]) x--;
    else if( dp[x][y]-1 == dp[x-1][y-1] && dp[x][y]-1 == dp[x-1][y] && dp[x][y]-1 == dp[x][y-1] ) {
      res += s[x-1];
      x--;y--;
    }
  }
  reverse(res.begin(), res.end());
  cout << res << "\n";
  
  return 0;
}


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

using namespace std;

#define MAX 3010
#define INF (1<<29)
typedef pair<int, int> pii;

struct Edge {
    int to, cost;
    Edge (int to, int cost) :
        to(to), cost(cost) {}
};

int N, M, K;
vector<Edge> G[MAX];
int d[MAX];

void dijkstra(int src)
{
    d[src] = 0;

    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push(pii(0, src));

    while (!pq.empty()) {
        pii p = pq.top(); pq.pop();
        int v = p.second;

        for (int i = 0; i < (int)G[v].size(); i++) {
            Edge &e = G[v][i];
            if (d[v] + e.cost < d[e.to]) {
                d[e.to] = d[v] + e.cost;
                pq.push(pii(d[e.to], e.to));
            }
        }
    }  
}

int main()
{
    cin >> N >> M >> K;
    for (int i = 0; i < M; i++) {
        int a, b, l;
        cin >> a >> b >> l;
        a--; b--;
        G[a].push_back(Edge(b, l));
        G[b].push_back(Edge(a, l));
    }

    fill(d, d + MAX, INF);
    
    int src;
    for (int i = 0; i < K; i++) {
        cin >> src; src--;
        dijkstra(src);
    }
    
    int res = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int)G[i].size(); j++) {
            int k = G[i][j].to;
            int C = G[i][j].cost;            
            for (double c = 0; c <= C; c += 0.5) {
                int cc = ceil(c), cc2 = floor(c);
                res = max(res, min(d[i] + cc, d[k] + (C - cc2)));
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5972
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
const char nl = '\n';
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
ll power(ll x, unsigned int y) {ll res = 1;	while (y > 0) { if (y & 1) res = res*x%mod; y = y>>1; x = x*x;} return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void solve(){
    int n;
    cin>>n;
    if(n>=400&&n<=599){
    	cout<<8;
    }
    if(n>=600&&n<=799){
    	cout<<7;
    }
    if(n>=800&&n<=999){
    	cout<<6;
    }
    if(n>=1000&&n<=1199){
    	cout<<5;
    }
    if(n>=1200&&n<=1399){
    	cout<<4;
    }
    if(n>=1400&&n<=1599){
    	cout<<3;
    }
    if(n>=1600&&n<=1799){
    	cout<<2;
    }
    if(n>=1800&&n<=1999){
    	cout<<1;
    }
    
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


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

bool sortbysec(const pair<string, int> &a, const pair<string, int> &b) {
    if (a.second == b.second) {
        return a.first < b.first;
    } else {
        return a.second > b.second;
    }
}
int main() {
    int N;
    cin >> N;

    vector<pair<string, int>> stock;
    map<string, int> ex;
    for (int i=0; i<N; i++) {
        string s;
        cin >> s;
        if (ex.find(s) == ex.end()) {
            long long size = stock.size();
            ex[s] = size;
            stock.push_back(make_pair(s, 1));
        } else {
            int idx = ex[s];
            stock[idx].second += 1;
        }
    }
    sort(stock.begin(), stock.end(), sortbysec);

    auto p = stock.begin();
    int M = p->second;
    cout << p->first << endl;
    p++;
    for ( ; p != stock.end(); p++) {
        if (M == p->second) {
            cout << p->first << endl;
        } else {
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 29036
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int coins = 0;
        
        for (int i = 0; i < 2; i++ ) {
        	if (a >= b) {
        		coins += a;
        		a--;
        	} else {
        		coins += b;
        		b--;
        	}
        }
        
        System.out.println(coins);
	}	
}

Measured memory_bytes: 22868
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> D;

  invec<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  for (auto&& i : s)
    for (auto&& j : i)
      cin >> j;
  vector<int> t(D);
  int last[26] = {0};
  ll r = 0, cost = 0;

  constexpr int BEAM = 8;
  using node = tuple<int, int>;
  REP(i, 26)
    cost += c[i];
  const int tier = cost;
  REP(i, D) {
    pair<int, int> cand = {-999999999, 0};
    
    REP(j, 26)
      cand = max(cand, make_pair(s[i][j] + c[j] * (i + 1 - last[j]), j));
    t[i] = cand.second + 1;
    
    const int plan = t[i] - 1;
    r += s[i][plan];
    cost -= c[plan] * (i + 1 - last[plan]);
    last[plan] = i + 1;
    r -= cost;
    cost += tier;
    cout << t[i] << endl;
  }
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



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

int main()
{
   int d,n;
    cin>>d>>n;
    if (d == 0)
    {
        if (n<100)
        cout<<n<<endl;
        else 
            {
               cout<<"101"<<endl; 
            }
    }
        
    else if (d == 1)
    {
        if (n == 100)
            cout<<"10100"<<endl;
        else
         cout<<n*100<<endl;
    }
       
    else if (d == 2)
    {
        if (n == 100)
            cout<<"1010000"<<endl;
        else 
        cout<<n*10000<<endl;
    }
        
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
#define N 1000
int p1[N],p2[N],p3[N];

void swap(int *a,int *b){
    int t;
    t=*a,*a=*b,*b=t;
}
void trace(int n){
    int i;
    for(i=0;i<n;i++){
	printf("%d,%d,%d\n",p1[i],p2[i],p3[i]);
    }
    printf("--------\n");
}
    
int main(void){
    int n,i,j;
    int ans,cnt;

    scanf("%d",&n);
    for(i=0;i<n;i++){
	scanf("%d%d%d",&p1[i],&p2[i],&p3[i]);
	if(p2[i]>p3[i]) swap(&p2[i],&p3[i]);
	if(p1[i]>p2[i]) swap(&p1[i],&p2[i]);
	if(p2[i]>p3[i]) swap(&p2[i],&p3[i]);

    }

    ans=0;
    for(i=0;i<n-1;i++){
	cnt=0;
	for(j=i+1;j<n;j++){
	    if(p1[j]!=-1 && p1[i]==p1[j] && p2[i]==p2[j] && p3[i]==p3[j]){
		cnt++;
		p1[j]=p2[j]=p3[j]=-1;
	    }
	}
	ans+=cnt;
    }

    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 608
N = int(input())
total = 0
i = 0
idx_list = []

if N == 0:
  print(0)
  exit()

if N < 0:
  while total > N:
    total += (-2) ** (2 * i + 1)
    idx_list.append(2 * i + 1)
    i += 1
  diff = abs(total - N)
  flip_str = str(bin(diff))[2:]
else:
  while total < N:
    total += (-2) ** (2 * i)
    idx_list.append(2 * i)
    i += 1
  diff = abs(total - N)
  flip_str = str(bin(diff))[2:]

i = 0
ans = ''
while i <= max(idx_list):
  if i in idx_list:
    ans = '1' + ans
  else:
    ans = '0' + ans
  i += 1

print(bin(int(ans, 2) ^ int(flip_str.zfill(len(ans)), 2))[2:])
    
    

    

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    int c = 0;
    for(int i = 1; i <= N; ++i) {
        int a;
        cin >> a;
        if(i % 2 + a % 2 == 2) ++c;
    }
    cout << c << endl;
    return 0;

}



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

int main(void)
{
	int n,m,a=0,x=0;
	
	cin >> n ;
	while(n != 0){
		for(int i = 0;i < 9;i++){
			cin >> m ;
			a += m ;
		}
		x = n - a;
		cout << x << endl;
		a = 0;
		cin >> n ;
	}
	
	return 0;
}

Measured memory_bytes: 3048
x, n = list(map(int, input().split()))

if n == 0:
  print(x)
  exit(0)
else:
  arr = list(map(int, input().split()))

arr.sort()
if x in arr:
  i = arr.index(x)
else:
  print(x)
  exit(0)

if not i and i != 0:
  print(x)
  exit(0)

j = 1
for _ in range(n):
  row = i - j
  high = i + j
  if x - j not in arr:
    print(x - j)
    exit(0)
  elif x + j not in arr:
    print(x + j)
    exit(0)
  j += 1

print(x-1)


Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    int tmp = 10;
    if(b<100&&b>=10)tmp = 100;
    if(b==100)tmp = 1000;
    int check = a*tmp+b;
    for(int i=1;i<check;i++){
        if(check==i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int a[3];
  rep(i,3) cin >> a[i];
  sort(a,a+3);
  cout << ( a[0]+a[1] == a[2] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = a/100;
        int c = a/10;
        int d = a%c;
        if(b==d){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
	}
}

Measured memory_bytes: 21716
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
Ss = sl()

seen = set()
for S in Ss:
    seen.add(S)

if len(seen) == 3:
    print('Three')
else:
    print('Four')


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





int main() {
  
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  string x,y,z,w;

  x=toupper(s1.at(0));
  y=toupper(s2.at(0));
  z=toupper(s3.at(0));

  cout<<x+y+z<<endl;
  

  
}










Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


int main() {
	int N;
	cin>>N;
	vector<int>as(N+2);
	for (int i = 0; i < N; ++i) {
		cin>>as[i+1];
	}
	int ans=0;
	int now=0;
	for (int i = 0; i < N; ++i) {
		if (as[i + 1]) {
			now++;
		}
		else {
			now=0;
		}
		ans=max(ans,now);

	}
	cout<<ans+1<<endl;
	return 0;
}




Measured memory_bytes: 3104
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<ll>> a(n, vector<ll>(m + 1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m + 1; j++)cin >> a[i][j];
	}
	ll ans = INT64_MAX;
	for (int i = 0; i < (1 << n); i++) {
		vector<ll> cnt(m);
		ll temp = 0;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				temp += a[j][0];
				for (int l = 1; l < m + 1; l++) {
					cnt[l - 1] += a[j][l];
				}
			}
		}
		bool ok = true;
		for (int j = 0; j < m; j++) {
			if (cnt[j] < k)ok = false;
		}
		if (ok)ans = min(ans, temp);
	}
	cout << (ans == INT64_MAX ? -1 : ans);
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <list>

using namespace std;

struct P{
	string p;
	int t;
	
	
	P(string &name, int time) : p(name), t(time){}
};

int main(){
	list<P> Q;
	int n, i ,time, total = 0;
	
	cin >> n >> time;
	string name;
	int a;
	for(i=0;i<n;++i){
		cin >> name >> a;
		Q.emplace_back(name, a);
	}
	
	while(Q.size()){
		for(auto itr = Q.begin(); itr != Q.end();){
			if(itr->t > time){
				total += time;
				itr->t -= time;
				++itr;
			}
			else {
				total += itr->t;
				itr->t = 0;
				cout << itr->p << " " << total << endl;
				itr = Q.erase(itr);
			}
		}
	}
	return 0;
}


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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int inf = 1000500;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

void solve() {
	int n;
	cin >> n;
	cout << n * (n + 1) / 2 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; ll C,K; cin >>N >>C >>K;
  vector<ll> T(N); rep(i, N) cin >>T[i];
  N++; T.push_back(1001001001001001);
  sort(all(T));
  ll bustime = T[0];
  ll busindi = 1;
  int res = 0;
  for (int i=1; i<N; i++){
    if (busindi == C || T[i] - bustime > K){
      res++;
      bustime = T[i];
      busindi = 1;
    }else{
      busindi++;
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
 char s[2];
  
  scanf("%c",s);
  
  if(s[0] == 'A'){
   printf("T\n");
  }else{
  if(s[0] == 'T'){
   printf("A\n");
  }else{
  if(s[0] == 'G'){
   printf("C\n");
  }else{
   if(s[0] == 'C'){
    printf("G\n");
   }
  }
  }
  }
  
  return 0;
}

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

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 10000007

int main()
{
    FastIO
    int k, n;
    cin >> k >> n;
    int a[n];
    for(int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a+n);
    int ans = INF;
    for(int i=0; i<n-1; i++)
        ans = min(ans, k - (a[i+1] - a[i]));
    ans = min(ans, a[n-1] - a[0]);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
// ver1.8
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n;
  cin >> n;
  cout << n*n*n << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 10010;
const int MAXM = 10;
const int MAXK = 510;

int n, m, a[MAXM], f[MAXM], dp[MAXN], trace[MAXN];
int sticks[10] = {0,2,5,5,4,5,6,3,7,6};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) cin >> a[i];
    sort(a+1, a+m+1);
    dp[0] = 0;
    FOR(i,1,n) {
        dp[i] = -1000000000;
        FORE(j,m,1)
            if (i - sticks[a[j]] >= 0) {
                if (dp[i - sticks[a[j]]] + 1 > dp[i]) {
                    dp[i] = dp[i - sticks[a[j]]] + 1;
                    trace[i] = a[j];
                }
            }
    }
    int now = n;
    vector<int> res;
    while (now) {
        res.emplace_back(trace[now]);
        now = now - sticks[trace[now]];
    }
    FOR(i,0,SZ(res)-1) cout << res[i];
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+100;
const int inf=0x3f3f3f3f;
const int m=2019;
typedef pair<int,int> P;

int a[maxn];
int k[maxn];
int num[3000];
int main()
{
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    k[0]=1;
    for(int i=1;i<=s.size();i++)
        a[i]=(a[i-1]+(s[i-1]-'0')*k[i-1])%m,k[i]=k[i-1]*10%m;//,printf("%d\n",a[i]);
    int sum=0;
    ll ans=0;
    num[0]=1;
    for(int i=1;i<=s.size();i++)
    {
        sum=a[i];
        //sum=(sum+a[i])%m;
        ans+=num[sum];
        num[sum]++;
        //if(!sum)
          //  ans++;
    }
    printf("%lld\n",ans);
    return 0;
}
/*

*/


Measured memory_bytes: 5380
A, B, C, D = gets.split.map(&:to_i)
data = Hash.new()

(A..B).each do |i|
  if !data.key?(i)
    data[i] = 1
  end
end

(C..D).each do |j|
  if data[j] == 1
    data[j] += 1
  end
end

#p data
count = 0

data.each do |k, v|
  if v == 2
    count += 1
  end
end

if count == 0
  p 0
else
  p count - 1
end

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

const int INF = (int)1.01e9;
const int K = 17;
const int N = 1 << K;

int n;
vector<pair<int, int> > e[N];
int sz[N];
ll sumlen[N];

void dfs1(int v, int pr) {
    sz[v] = 1;
    sumlen[v] = 0;
    for (auto o : e[v]) {
        int to = o.first;
        if (to == pr) continue;
        dfs1(to, v);
        sz[v] += sz[to];
        sumlen[v] += sumlen[to] + 1LL * o.second * sz[to];
    }
}

ll ans;

void dfs2(int v, int pr) {
    bool ok = 1;
    for (auto o : e[v]) {
        int to = o.first;
        int s1 = sz[to];
        int s2 = n - sz[to];
        if (s1 > s2 + 1) ok = 0;
    }

    if (ok) {
        int mn = INF;
        ll csum = 0;
        for (auto o : e[v]) {
            mn = min(mn, o.second);
            int to = o.first;
            csum += sumlen[to] + 1LL * sz[to] * o.second;
        }
        int vert = -1;
        for (auto o : e[v]) {
            int to = o.first;
            if (sz[to] >= n - sz[to]) {
                //vert = to;
                mn = o.second;
                if (sz[to] > n - sz[to]) vert = to;
            }
        }
        if (vert != -1) {
            int cmn = INF;
            for (auto o : e[vert]) {
                if (o.first != v) {
                    cmn = min(cmn, o.second);
                }
            }
            mn = 2 * mn + cmn;
        }
        ans = max(ans, 2 * csum - mn);
    }

    int m = e[v].size();
    vector<ll> pref(m + 2), suf(m + 2);
    for (int i = 1; i <= m; i++) {
        int to = e[v][i - 1].first;
        pref[i] = pref[i - 1] + sumlen[to] + 1LL * sz[to] * e[v][i - 1].second;
    }
    for (int i = m; i >= 1; i--) {
        int to = e[v][i - 1].first;
        suf[i] = suf[i + 1] + sumlen[to] + 1LL * sz[to] * e[v][i - 1].second;
    }

    for (int i = 1; i <= m; i++) {
        int to = e[v][i - 1].first;
        if (to == pr) continue;

        int oldSz = sz[v];
        ll oldSumlen = sumlen[v];

        sz[v] = n - sz[to];
        sumlen[v] = pref[i - 1] + suf[i + 1];
        dfs2(to, v);

        sz[v] = oldSz;
        sumlen[v] = oldSumlen;
    }
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif


    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n; i++) {
            e[i].clear();
        }

        for (int i = 0; i < n - 1; i++) {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            --u; --v;
            e[u].push_back({v, w});
            e[v].push_back({u, w});
        }

        dfs1(0, -1);
        ans = -1;
        dfs2(0, -1);
        printf("%lld\n", ans);
    }


#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll MOD=1000000007;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   ll x;
   cin>>x;
   ll i=2.0*x/11.0;
   
   if(x%11==0){}
   else if(x%11>6) i++;  
   else if(x%11<6) i++;
   cout<<i;

   return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main()
{
    int i, n, a[100], judge = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        if (a[i] % 2 == 1 || (a[i] % 2 == 0 && (a[i] % 3 == 0 || a[i] % 5 == 0)))
            judge++;
    }
    if (judge == n)
        printf("APPROVED");
    else
        printf("DENIED");
}

Measured memory_bytes: 128
N, W = map(int, input().split())

dp = [0] * (W+1)

for i in range(N):
    w, v = map(int, input().split())
    tmp = dp[:]
    for j in range(1, W+1):
        if j  >= w and tmp[j] < tmp[j-w] + v:
            dp[j] = tmp[j-w] + v
        else:
            dp[j] = tmp[j]
    
print(dp[-1])

Measured memory_bytes: 58760
#include <iostream>
using namespace std;
 
int main() {
    int X, A, B;
    cin >> X >> A >> B;
    if (B - A <= 0){
      cout << "delicious" << endl;
    } else if (B - A <= X){
      cout << "safe" << endl;
    } else {
      cout << "dangerous" << endl;
    }
}

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

bool isPalindrome(string v){
  string s = v;
  reverse(s.begin(), s.end());
  return s == v;
}

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

  if(
      isPalindrome(s) &&
      isPalindrome(s.substr(0, (s.size()-1)/2)) &&
      isPalindrome(s.substr((s.size()+3)/2 - 1, s.size()))
    )
    cout << "Yes";
  else
    cout << "No";

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    long long int n ;
    scanf("%lld",&n);
    if(n & 1)printf("0\n");
   
    else
    {   long long int sum=0;
         n/=2;
        while(n>0)
        {
            sum+=n/5 ;
            n/=5;
            
        }
        printf("%lld\n",sum);
    }
    return 0 ;
}

Measured memory_bytes: 128
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val s = sc.nextInt()
    val nonSValue = if (s == 1) 2 else s - 1
    val nonSLength = n - k

    val ans1 = Array.fill(k)(s)
    val ans2 = Array.fill(nonSLength)(nonSValue)
    val ans = ans1 ++ ans2

    println(ans.mkString(" "))
  }
}


Measured memory_bytes: 41040
#include<bits/stdc++.h>
using namespace std;
int N, M, x, y;
vector <int> adj[100005];
int dis[100005];
using namespace std;
int dfs(int cur){
	if(dis[cur] != 1) return dis[cur];
	int maxtemp = 0;
	for(auto j : adj[cur]){
		maxtemp = max(maxtemp, dfs(j));
	}
	dis[cur] += maxtemp;
	return dis[cur];
}
int main(){
	scanf("%d%d", &N, &M);
	for(int i = 0 ; i<M ;  i++){
		scanf("%d%d", &x, &y);
		adj[x].push_back(y);
	}
	fill(dis,dis+N+1,1);
	int maxdis = 0;
	for(int i = 1 ; i<=N ; i++){
		maxdis = max(maxdis, dfs(i));
	}
	cout << maxdis -1 <<endl;
}

Measured memory_bytes: 11560
function check(A,B,h,k)
	cnt=0
	for a=h
		cnt+=cld(max(a-B*k,0),A-B)
	end
	cnt<=k
end
function main()
	N,A,B=map(x->parse(Int,x),split(readline()))
	h=map(x->parse(Int,x),readlines())
	L=0
	R=10^9
	while R-L>1
		M=div(L+R,2)
		if check(A,B,h,M)
			R=M
		else
			L=M
		end
	end
	println(R)
end
main()


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

using namespace std;

int main() {
    ios :: sync_with_stdio(0);
    cin.tie(nullptr);
    int n; cin >> n;
    string s;
    cin >> s;
    int x = 0, maxx = 0;

    for(auto c : s) {
        if (c == 'I')
            ++x;
        else --x;
        if (x > maxx)
            maxx = x;
    }
    cout << maxx;
    return 0;
}


Measured memory_bytes: 256
#include<cassert>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
ll n;
vector<ll> g[200010];
vector<ll> v[2];
void dfs(ll x,ll from,ll d){
	v[d%2].push_back(x);
	for(auto y:g[x])if(y!=from){
		dfs(y,x,d+1);
	}
}
vector<ll> ids[3];
bool used[200010];
ll p[200010];
int main(){
	cin>>n;
	rep(i,n-1){
		ll a,b; cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1,0,0);
	ll r1=n/3+(n%3>=1);
	ll r2=n/3+(n%3>=2);
	//cerr<<r1<<" "<<r2<<" "<<v[0].size()<<" "<<v[1].size()<<endl;
	if(v[0].size()<v[1].size())swap(v[0],v[1]);
	if(v[0].size()>=r1+r2){
		for(int i=0;i<r1;i++)ids[1].push_back(v[0][i]);
		for(int i=r1;i<r1+r2;i++)ids[2].push_back(v[0][i]);
	}
	else{
		if(r1>r2){
			assert(r1<=v[0].size());
			assert(r2<=v[1].size());
			for(int i=0;i<r1;i++)ids[1].push_back(v[0][i]);
			for(int i=0;i<r2;i++)ids[2].push_back(v[1][i]);
		}
		else{
			assert(r1<=v[1].size());
			assert(r2<=v[0].size());
			for(int i=0;i<r1;i++)ids[1].push_back(v[1][i]);
			for(int i=0;i<r2;i++)ids[2].push_back(v[0][i]);
		}
	}
	for(int i=1;i<=n;i++)used[i]=0;
	for(auto t:ids[1])used[t]=1;
	for(auto t:ids[2])used[t]=1;
	for(int i=1;i<=n;i++){
		if(used[i]==0)ids[0].push_back(i);
	}
	rep(k,3){
		ll base=k; if(k==0)base=3;
		//sort(all(ids[k]));
		for(auto t:ids[k]){
			p[t-1]=base;
			//assert(1<=base&&base<=n);
			base+=3;
		}
	}
	rep(i,n)cout<<p[i]<<endl;
	
}


Measured memory_bytes: 24428
N = int(input())
MOD = 10**9 + 7
C = [int(input()) for i in range(N)]

dp = [0] * (N+1)
dp[0] = 1
last_idx = {}
for i, c in enumerate(C, 1):
  dp[i] = dp[i-1]
  if c in last_idx:
    idx = last_idx[c]
    if idx != i - 1:
      dp[i] += dp[idx]
      dp[i] %= MOD
  last_idx[c] = i

print(dp[-1]%MOD)

Measured memory_bytes: 36548