akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include<bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#define inf  (int)1e18
#define EPS   1e-9
#define MOD 1000000007
#define all(k) k.begin(),k.end()
#define Pi 3.14159
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define ll  long long unsigned int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vi vector<int>
#define vc vector<char>
#define vvc vector<vc>
#define mi map<int,int>
#define ml map<ll,ll>
#define umap unordered_map<int,int>
using namespace std;

void sol() {
	int n;
	ll cnt = 0;
	cin >> n;
	repk(i, 1, n) {
		int res = n / i;
		if (n % i == 0)res--;

		cnt += res;
	}

	cout << cnt;
}



int main() {


	int t = 1;


	// for (cin >> t; t; t--)
	sol();


	return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int L, R, d;

int main() {
  //
  cin >> L >> R >> d;

  int ans = 0;
  repe(i, L, R) {
    if (i % d == 0) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3620
INF=10**10
def main():
  H,N=map(int,input().split())
  AB=[]
  for i in range(N):
    AB.append(list(map(int,input().split())))
  dp=[INF]*(H+1)
  dp[0]=0
  for a,b in AB:
    for k in range(H+1):
      tmp=k-a
      if tmp<0:
        tmp=0
      need_magic=dp[tmp]+b
      if need_magic<dp[k]:
        dp[k]=need_magic
  print(dp[H])
main()
      


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
const int M1 =  998244353;
const int M2 =  1000000007;

int dp[4][3000][3000];
int a[3000][3000];

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  for(int x = 0; x <= 3; x++)
    for(int i = 0; i < n; i++)
      for(int j = 0; j < m; j++)
        dp[x][i][j] = a[i][j] = 0;
  while(k--) {
    int x, y, z;
    cin >> x >> y >> z;
    a[--x][--y] = z;
  }
  for(int i = 0; i < n; i++) {
    if(i == 0) {
      for(int x = 1; x <= 3; x++)
        dp[x][0][0] = a[0][0];
    }
    else {
      for(int x = 0; x <= 3; x++) {
        dp[0][i][0] = dp[x][i - 1][0];
        dp[1][i][0] = max(dp[1][i][0], dp[x][i - 1][0] + a[i][0]);
      }
    }
    for(int j = 1; j < m; j++) {
      for(int x = 0; x <= 3; x++) {
        dp[x][i][j] = max(dp[x][i][j], dp[x][i][j - 1]);
        if(x)
          dp[x][i][j] = max(dp[x][i][j], dp[x - 1][i][j - 1] + a[i][j]);
      }
      if(i) {
        for(int x = 0; x <= 3; x++) {
          dp[0][i][j] = max(dp[0][i][j], dp[x][i - 1][j]);
          dp[1][i][j] = max(dp[1][i][j], dp[x][i - 1][j] + a[i][j]);
        }
      }
    }
  }
  int ans = 0;
  for(int i = 0; i <= 3; i++)
    ans = max(ans, dp[i][n - 1][m - 1]);
  cout << ans << "\n";
}
 
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}

Measured memory_bytes: 355108
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  vector<int> d1(n+1),d2(n);
  REP(i,n){
    cin>>a[i+1];
    d1[i]=abs(a[i+1]-a[i]);
  }
  d1[n]=abs(a[0]-a[n]);
  
  REP(i,n){
    if(i==n-1){
      continue;
    }
    d2[i]=abs(a[i]-a[i+2]);
  }
  d2[n-1]=abs(a[n-1]-a[0]);
  
  long long s=0;
  REP(i,n+1){
    s += d1[i];
  }
    
  long long ans;
  for(int i=1;i<=n;i++){
    ans = s-d1[i-1]-d1[i];
    ans += d2[i-1];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct UnionFind {
    int size_;
    vector<int> par;
    vector<int> rank;
    vector<int> sz;

    UnionFind(int size_) : size_(size_) {
        par.resize(size_);
        rank.resize(size_);
        sz.resize(size_);

        for (int i = 0; i < size_; i++) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[y] < rank[x]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;

        par[x] = y;
        sz[y] += sz[x];
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return sz[find(x)]; }
};
int N, M;
int K[100005];

int main() {
    cin >> N >> M;
    UnionFind uf(M);
    set<int> s;
    rep(i, N) {
        cin >> K[i];
        vector<int> vec;
        rep(j, K[i]) {
            int a;
            cin >> a;
            a--;
            s.insert(a);
            vec.push_back(a);
        }
        rep(j, vec.size()) if (j) { uf.unite(vec[j], vec[j - 1]); }
    }
    if (uf.size(*s.begin()) == s.size())
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 4480
#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=1e9+7;
const long long INF = 1LL<<60;

bool is_kaibun(string s){
    int n = (int) s.size();
    for(int i = 0;i<n/2;i++){
        if(s.at(i)!=s.at(n-1-i)){
            return false;
        }
    }
    return true;
}

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

    string answer = "Yes";
    for(int i = 0;i<((int)s.size())/2;i++){
        if(s.at(i)!=s.at(((int)s.size())-1-i)){
            answer = "No";
            cout << answer << endl;
            return 0;
        }
    }

    int n = (int) s.size();
    for(int i = 0;i<(n-1)/2/2;i++){
        if(s.at(i)!=s.at((n-1)/2-1-i)){
            answer = "No";
            cout << answer << endl;
            return 0;
        }
    }


    if(is_kaibun(s.substr((n+3)/2-1, n-(n+3)/2+1)) == false){
        answer = "No";
        cout << answer << endl;
        return 0;
    }

    cout << answer << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
void trace(int n, ll arr[]){for(int i = 0; i < n; i++){cout << arr[i] << " ";} cout << endl << endl;}
const ll mod = 1e9 + 7;
int main()
{
    Hello
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++){
        int crane = i, turtle = x - i;
        if(((crane * 2) + (turtle * 4)) == y)
            return cout << "Yes", 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3608
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if f[0]==e[0]and f[5]==e[5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return print('No')
 print('Yes')
f()


Measured memory_bytes: 5608
n = int(input())
arr = []

for i in range(n):
	s,p = input().split()
	a = {"i":i+1,"s":s,"p":int(p)}
	arr.append(a)

arr = sorted(arr, key=lambda x:x["p"], reverse=True)
#print(arr)
arr = sorted(arr, key=lambda x:x["s"])

for a in arr:
	print(a["i"])


Measured memory_bytes: 3060
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>


using namespace std;


int main(){
    int N, D;
    cin >> N >> D;
    cout << ceil(float (N) / float(2*D+1)) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>



#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
typedef long long int ll;
const ll MAXN = 1e18 + 2;
const ll MODU = 1e9 + 7;

ll dp[100][3][3][2];
// 0:  a_(i+1)^b_(i+1)<N_(i+1)
// 1:  a_(i+1)^b_(i+1)=N_(i+1)
// 2:  a_(i+1)^b_(i+1)>N_(i+1)
//
ll N;


int main(){
#ifdef L_JUDGE
	freopen("in.txt", "r", stdin);
	//		freopen("out.txt","w",stdout);
#endif
	scanf("%lld", &N);
	memset(dp, 0, sizeof(dp));
	dp[0][1][1][0] = 1;
	int i;
	for (i = 0; N; N >>= 1, i++){
		ll ni = N & 0x1;
		for (int ci = 0; ci<2; ci++){
			for (int xi = 0; xi<3; xi++){
				for (int yi = 0; yi<3; yi++){
					for (int ai = 0; ai<2; ai++){
						for (int bi = ai; bi<2; bi++){
							int tmpxi = xi;
							int tmp = (ai^bi);
							if (tmp>ni)tmpxi = 2;
							else if (tmp<ni)tmpxi = 0;
							int tmpyi = yi;
							tmp = (ai + bi + ci) % 2;
							if (tmp<ni)tmpyi = 0;
							else if (tmp>ni)tmpyi = 2;
							int tmpci = (ai + bi + ci) / 2;
							dp[i + 1][tmpxi][tmpyi][tmpci] += dp[i][xi][yi][ci];
							dp[i + 1][tmpxi][tmpyi][tmpci] %= MODU;
						}
					}
				}
			}
		}
	}
	ll ans = 0;
	for (int xi = 0; xi<2; xi++){
		for (int yi = 0; yi<2; yi++){
			ans += dp[i][xi][yi][0];
			ans %= MODU;
		}
	}
	printf("%lld\n", ans);

#ifdef L_JUDGE
	fclose(stdin);
	fclose(stdout);
	//		system("out.txt");
#endif

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include<utility>
using namespace std;
using ll = long long;

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();

        if (n % 500 <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
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; }

vector<vector<ll> > dp(401, vector<ll>(401, -1));
vector<vector<char> > mp(401, vector<char>(401));
int h, w;
vector<int> dx = {-1,1,0,0};
vector<int> dy = {0,0,1,-1};

ll bfs(int x, int y) {
    queue<pair<int, int> > que;
    ll black = 0, white = 0;
    que.push(make_pair(x, y));
    dp[x][y] = 0;
    if(mp[x][y] == '#') {
        black++;
    }
    else {
        white++;
    }
    while(que.size()) {
        pair<int, int> p = que.front();
        int a = p.first, b = p.second;
        que.pop();
        rep(i, 4) {
            int nx = dx[i] + a, ny = dy[i] + b;
            if(nx >= 0 && nx < w && ny >= 0 && ny < h && dp[nx][ny] == -1 && mp[nx][ny] != mp[a][b]) {
                dp[nx][ny] = dp[a][b] + 1;
                que.push(make_pair(nx, ny));
                if(mp[nx][ny] == '#') {
                    black++;
                }
                else {
                    white++;
                }
            }
        }
    }
    return black * white;
}

int main(){
    cin >> h >> w;
    ll ans = 0;
    rep(y, h) {
        rep(x, w) {
            cin >> mp[x][y];
        }
    }
    rep(y, h) {
        rep(x, w) {
            if(dp[x][y] == -1) {
                ans += bfs(x, y);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5032
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	if ri() == 1 {
		fmt.Println("Hello World")
	} else {
		fmt.Println(ri() + ri())
	}
}


Measured memory_bytes: 640
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N = readint()[1]
  a = readint()

  c = 0
  for i in 1:2:N
    if a[i]%2 == 1
      c += 1
    end
  end
  println(c)


end

main()

Measured memory_bytes: 186836
<?php
  
function dfs(&$paterns,$array,$m,$n){
  	if(count($array)==$n){
      $paterns[] = $array;
      return $array;
    }
  	count($array)==0 ? $index = 1 : $index = end($array);
  	for($i=$index;$i<=$m;$i++){
      $array[] = $i;
      dfs($paterns,$array,$m,$n);
      array_pop($array);
    }
}
      
$paterns = array();
fscanf(STDIN,"%d%d%d",$n,$m,$q);

dfs($paterns,[],$m,$n);

$abcd_li = array();
for($i=0;$i<$q;$i++){
  $abcd_li[] = explode(" ",trim(fgets(STDIN)));
}

$max =0;
$sum = 0;
foreach($paterns as $A){
  foreach($abcd_li as $abcd){
    if($A[$abcd[1]-1]-$A[$abcd[0]-1] == $abcd[2]){
      $sum += $abcd[3];
    }
  }
  $max = max($sum,$max);
  $sum = 0;
}
 

//print_r($paterns);

echo $max;


Measured memory_bytes: 82832
n,q = gets.split.map(&:to_i)
s = gets.chomp

count = [0,0]
1.upto(n-1) do |i|
    count << count.last + (s[i-1] + s[i] == "AC" ? 1 : 0)
end

q.times do
    l,r = gets.split.map(&:to_i)
    puts count[r] - count[l]
end

Measured memory_bytes: 3452
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (k + 1)
for i in range(k):
    if dp[i] == 0:
        for ai in a:
            if i + ai > k:
                break
            dp[i+ai] = 1
print('First' if dp[k] else 'Second')

Measured memory_bytes: 9656
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<tuple>
#include<utility>
#include<cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define enter "\n"

typedef long long ll;


int abc104_c(){
    //入力
    int a,b,c;
    cin >> a >> b >> c;
    int ans = 0;

    //処理
    
    //出力
    cout << max(max(a,b),c) - min(min(a,b),c) <<enter;
    return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
  return (x > y) ? y : x;
}
int gcd(int n1, int n2)
{
  if (n2 != 0) return gcd(n2, n1 % n2);
  else return n1;
}
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";}

bool isPerfectSquare(long double x)
{ long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}
int main()
{ fast;
  int n;
  double d;
  cin >> n >> d;
  int cnt = 0;

  for (int i = 0; i < n; i++)
  { double x, y;
    cin >> x >> y;
    double t = x * x + y * y;
    double r = sqrt(t);
    if (r <= d)
      cnt++;

  }
  cout << cnt;
}



Measured memory_bytes: 3724
from time import time
import random


def main():
    random.seed(145)

    now = time()

    MAX = 26

    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(d)]
    t = []
    for row in s:
        mxi = 1
        mx = 0
        for i, e in enumerate(row, 1):
            if e > mx:
                mx = e
                mxi = i

        t.append(mxi)

    last = [0] * MAX

    score = 0
    for day, e in enumerate(t, 1):
        score += s[day-1][e-1]
        last[e-1] = day

        for ec, elast in zip(c, last):
            score -= ec * (day - elast)

    d_li = []
    for i in range(1, d + 1):
        ln = max(1, (-(i - d // 2) ** 2 + d ** 2 // 4) // 500)
        d_li += [i] * ln

    di_max = len(d_li) - 1

    #c_sum = sum(c)
    #c_li = []
    #for i, e in enumerate(c, 1):
    #    c_li += [i] * e

    sc = []
    for row in s:
        app = []
        for i, (es, ec) in enumerate(zip(row, c), 1):
            app += [i] * max(1, (es + ec * d) // 20)
        sc.append(app)

    while time() - now <= 1.85:
        prev_score = score

        di = random.randint(0, di_max)
        ed = d_li[di]
        qi = random.randint(0, len(sc[ed-1]) - 1)
        eq = sc[ed-1][qi]

        q_old = t[ed-1]
        d_prev = {q_old: 0, eq: 0}

        c_old = c[q_old-1]
        c_new = c[eq-1]

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score += c_old * (day - d_prev[q_old])
            score += c_new * (day - d_prev[eq])

        score -= s[ed-1][q_old-1]
        score += s[ed-1][eq-1]

        t[ed-1] = eq

        d_prev = {q_old: 0, eq: 0}

        for day, e in enumerate(t, 1):
            if e in d_prev.keys():
                d_prev[e] = day

            score -= c_old * (day - d_prev[q_old])
            score -= c_new * (day - d_prev[eq])

        if prev_score > score:
            t[ed-1] = q_old
            score = prev_score

    print(*t, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 262836
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

vector<vector<ll>> g;

signed main() {
    ios::sync_with_stdio(false);
    ll n, u, v;
    cin >> n >> u >> v;
    u--;v--;
    g.resize(n);
    REP(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<ll> nt(n, -1);

    nt[v] = 0;
    queue<Pair> q;
    q.emplace(v, 0);

    while (q.size()) {
        auto c = q.front();q.pop();
        REP(i, sz(g[c.first])) {
            ll j = g[c.first][i];
            if(nt[j] != -1) continue;
            nt[j] = c.second + 1;
            q.emplace(j, nt[j]);
        }
    }

    q.emplace(u, 0);
    vector<ll> nv(n, -1);
    vector<ll> can(n);
    can[u] = 1;
    while(q.size()) {
        auto c = q.front();q.pop();
        REP(i, sz(g[c.first])) {
            ll j = g[c.first][i];
            if(nt[j] < c.second + 1|| can[j] == 1) continue;
            if(nt[j] == c.second + 1) {
                can[j] = 1;
                continue;
            }
            can[j] = 1;
            nv[j] = c.second + 1;
            q.emplace(j, c.second + 1);
        }
    }
    ll ans = 0;
    REP(i, n) {
        if(can[i]) {
            ans = max(ans, nt[i] - (sz(g[i]) == 1? 1: 0));
        }
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 8960
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    
    if(S.join("") !== S.reverse().join("")) {
        console.log("No");
        return;
    }
    
    let prefix = S.slice(0 , (S.length - 1) / 2);
    let suffix = S.slice(Math.ceil(S.length / 2), S.length);
    
    if(prefix.join("") !== prefix.reverse().join("")) {
        console.log("No")
        return;
    }

    if(suffix.join("") !== suffix.reverse().join("")) {
        console.log("No")
        return;
    }
    
    console.log("Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
upNum, firstNum, lastNum = map(int, input().split())
total = 0
digitNumSum = 0
for i in range(1, upNum + 1):
  digitNumSum = 0
  digitNumList = list(str(i))
  for j in range(len(digitNumList)):
    digitNumSum += int(digitNumList[j])
  if firstNum <= digitNumSum <= lastNum:
    total += i
print(total)

Measured memory_bytes: 9120
eval'A,B,*C=#'+`tr ' ' ,`;z=0;i=45;i=C.inject(A^B,:^)[i]>0?(z+=t=[A[0,i],(~B)[0,i]].min+1;A-=t;B+=t;45):i-1until i<0||A<1;p A>0?z:-1

Measured memory_bytes: 14380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC066A
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b, c, s;
			string[] word = Console.ReadLine().Split(' ');

			a = int.Parse(word[0]);
			b = int.Parse(word[1]);
			c = int.Parse(word[2]);

			int x = a + b;
			int y = b + c;
			int z = c + a;

			s = x;
			if (y < s) s = y;
			if (z < s) s = z;

            Console.WriteLine(s);

			//Console.ReadKey();


		}
	}
}


Measured memory_bytes: 27508
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
   
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

bool isPrime(int a){
	if (a<=1)return false;
	if (a==2)return true;
	for (int i = 2; i*i<=a ; i++) {
		if(a%i==0)return false;
	}
	return true;
}

int main(){
	int n,ans=0;
	cin >> n;
	rep(i,n){
		int tmp;
		cin >> tmp;
		if(isPrime(tmp))ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main() {
	char c;
	cin>>c;
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
		cout<<"vowel"<<endl;
	}
	else{
		cout<<"consonant"<<endl;
	}
}


Measured memory_bytes: 256
//-------------------------------------------
//-               Train Fare                -
//-                                         -
//-       autumn_eel niha katemasen!        -
//-------------------------------------------

#include<iostream>
#include<functional>
#include<queue>
#include<deque>
#include<vector>
#include<algorithm>
using namespace std;

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
inline void writeln(int x) {
	int s = 0, p; char f[7];
	while (x) {
		p = x; x /= 10;
		f[s++] = p - (x << 1) - (x << 3);
	}
	if (!s) f[s++] = 0;
	while (s--) putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}
#pragma warning(disable:4996)
int n, m, q, a[200003], b[200003], c[200003], d[200003], e[100003], f[100003], g[100003];
int h1[100003], h2[100003], h3[100003], h4[100003], dist[100003], E[200003];
vector<pair<int, int> > z[100003]; vector<int> x[100003];
vector<int>D[100003];
int Q1[110000], Q1L, Q1R;
int main() {
	reader(&n); reader(&m); reader(&q);
	fill(d, d + m + 1, 1 << 30);
	for (int i = 1; i <= m; i++) { reader(&a[i]), reader(&b[i]); f[a[i]]++; f[b[i]]++; }
	for (int i = 1; i <= q; i++) reader(&c[i]), d[c[i]] = i;
	for (int i = 1; i <= n; i++) { x[i].resize(f[i]); }
	for (int i = 1; i <= m; i++) {
		x[a[i]][g[a[i]]] = b[i]; g[a[i]]++;
		x[b[i]][g[b[i]]] = a[i]; g[b[i]]++;
	}
	fill(dist, dist + n + 1, -1); dist[1] = 0;
	Q1[0] = 1; Q1R = 1;
	while (Q1R > Q1L) {
		int a1 = Q1[Q1L]; Q1L++;
		for (int i : x[a1]) {
			if (dist[i] == -1) {
				dist[i] = dist[a1] + 1;
				Q1[Q1R] = i; Q1R++;
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) h1[a[i]]++;
		if (dist[b[i]] > dist[a[i]]) h1[b[i]]++;
	}
	for (int i = 1; i <= n; i++)z[i].resize(h1[i]);
	for (int i = 1; i <= m; i++) {
		if (dist[a[i]] > dist[b[i]]) { z[a[i]][h2[a[i]]] = make_pair(b[i], d[i]); h2[a[i]]++; }
		if (dist[b[i]] > dist[a[i]]) { z[b[i]][h2[b[i]]] = make_pair(a[i], d[i]); h2[b[i]]++; }
	}
	for (int i = 1; i <= n; i++) h3[dist[i]]++;
	for (int i = 0; i <= n; i++) D[i].resize(h3[i]);
	for (int i = 1; i <= n; i++) D[dist[i]][h4[dist[i]]] = i, h4[dist[i]]++;
	e[1] = (1 << 30);
	for (int i = 1; i < n; i++) {
		for (int j : D[i]) {
			for (pair<int, int>k : z[j]) {
				e[j] = max(e[j], min(e[k.first], k.second));
			}
		}
	}
	for (int i = 2; i <= n; i++) {
		if (e[i] < 300000) E[e[i]]++;
	}
	for (int i = 1; i <= q; i++) {
		E[i] += E[i - 1];
		writeln(E[i]);
	}
	return 0;
}

Measured memory_bytes: 25016
#include <bits/stdc++.h>
#define maxn 105
using namespace std;
int n,a[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    double res=0;
    for(int i=1;i<=n;i++){
        res+=1.0/a[i];
    }
    res=1.0/res;
    printf("%.10f\n",res);
    return 0;
}

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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 2e5 + 5;
using namespace std;

int main() {
    IO;
    int total, legs;
    cin >> total >> legs;
    for (int i = 0; i <= total; i++) {
        if (((2 * i) + (4 * (total - i))) == legs) return cout << "Yes", 0;
    }
    return cout << "No", 0;


}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 1000005;
ll A[MAX_N],Ac[MAX_N],c[MAX_N],D[MAX_N];
vector<ll> pri;

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

int main()
{
	int N;
	cin >> N;
	ll stwise = 0;
	rep(i,N)
	{
		cin >> A[i];
		Ac[A[i]]++;
		if (i == 0) stwise = A[i];
		else stwise = mygcd(stwise,A[i]);
		//cout << stwise << " ";
	}
	if (stwise != 1)
	{
		cout << "not coprime" << endl;
		return 0;
	}
	else
	{
		D[0] = 0;
		D[1] = 1;
		for (int i = 2; i < MAX_N; ++i)
		{
			if (D[i] == 0)
			{
				D[i] = i;
				for (int j = 2*i; j < MAX_N; j += i)
				{
					if (D[j] == 0) D[j] = i;
				}
			}
		}

		rep(i,N)
		{
			ll temp = A[i];
			while(temp > 1)
			{
				int d = D[temp];
				c[d]++;
				while(temp % d == 0)
				{
					temp /= d;
				}
			}
			//cout << "a";
		}

		for (int i = 2; i < MAX_N; ++i)
		{
			//cout << c[i] << " ";
			if (c[i] > 1)
			{
				cout << "setwise coprime" << endl;
				return 0;
			}
		}
		cout << "pairwise coprime" << endl;
	}
	return 0;
}

Measured memory_bytes: 34776
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int f(int x) {
	if (x == 1)return 300000;
	if (x == 2)return 200000;
	if (x == 3)return 100000;
	return 0;
}
signed main() {
	int x, y; cin >> x >> y; int ans = f(x) + f(y); if (x + y == 2)ans += 400000; cout << ans << endl;
}

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

int main(){
    int x; cin >> x;
    int n, m;
    for(n = x; n <= 100003; n++){
        for(m = 2; m < n; m++){
            if(n % m == 0) break;
        }
        if(n == m){
            cout << n << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc102/tasks/abc102_b
"use strict"
function Main(input) {
  const params = input.split('\n')
  const n = Number(params[0]);
  let max = 0;
  let min = Math.pow(10, 10);
  params[1].split(' ').forEach(val => {
    max = Math.max(max, Number(val));
    min = Math.min(min, Number(val));
  });
  console.log(max -　min);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7628
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N=1e5+5;
int n,m;
long long ans;
pair<int,int> p[N];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>p[i].F>>p[i].S;
	sort(p,p+n);
	for(int i=0;i<n;i++)
	{
		if(p[i].S>m)
		{
			ans+=(long long)p[i].F*m;
			cout<<ans;
			return 0;
		}
		else
		{
			m-=p[i].S;
			ans+=(long long)p[i].F*p[i].S;
		}
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll;

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

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vpll flag, D; vll path;
//***********//
vl bitList(ll n, ll k, ll f) {
	vl bitList(k);
	for (ll i = 0; i < k; i++) {
		bitList[i] = f % n;
		f /= n;
	}
	return bitList;
}
int main() {
	cin >> N;
	vll A(N);
	for (i = 0; i < N; i++) {
		A[i] = bitList(2, 10, i + 1);
	}
	for (i = 0; i < N-1; i++) {
		for (j = i+1; j < N; j++) {
			for (k = 0; k < 10; k++) {
				if (A[i][k] + A[j][k] == 1) {
					co3(k + 1);
					break;
				}
			}
		}
		cout << endl;
	}
}

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

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
        
    const int M = 1e9 + 10;
    int n, k;
    cin >> n >> k;
    vector<int> c(n, M), h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    c[0] = 0;
    for (int i = 1; i < n; i++) {
        //~ if (i - 1 >= 0) {
            //~ c[i] = min(c[i], c[i - 1] + abs(h[i - 1] - h[i]));
        //~ }
        //~ if (i - 2 >= 0) {
            //~ c[i] = min(c[i], c[i - 2] + abs(h[i - 2] - h[i]));
        //~ }
        for (int j = 1; j <= k; j++) {
            if (i - j >= 0) {
                c[i] = min(c[i], c[i - j] + abs(h[i - j] - h[i]));
            }
        }
    }
    cout << c[n - 1] << endl;

}


Measured memory_bytes: 1024
n = int(input())
dic = {}

for i in range(n):
    line = input().split()
    if line[0] == 'insert':
        if dic.get(line[1]):
            dic[line[1]] += 1
        else:
            dic[line[1]] = 1
    elif line[0] == 'find':
        if dic.get(line[1]):
            print('yes')
        else:
            print('no')

Measured memory_bytes: 37320
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void)
{
    int count = 0;
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    for (int i = 0; i <= A; ++i)
    {
        for (int j = 0; j <= B; ++j)
        {
            for (int k = 0; k <= C; ++k)
            {
                if (500 * i + 100 * j + 50 * k == X)
                    count++;
            }
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(N), sum(N+1);
    sum[0] = 0;
    for (int i = 0; i<N; i++) {
        cin >> A[i];
        sum[i+1] = sum[i] + A[i];
        sum[i+1] %= M;
    }
    map<int, long long> rem;
    for (auto _sum : sum) {
        rem[_sum]++;
    }
    for (auto _rem : rem) {
        for (long long i = 1; i < _rem.second; i++) {
            ans += i;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t root(int64_t n){
    int64_t ret = pow((long double)n, 0.5L);
    while(ret*ret > n) ret--;
    while((ret+1)*(ret+1) <= n) ret++;
    return ret;
}

int main(){
    int N, K;
    cin >> N >> K;
    int Q = root(N);
    int num[32000];
    num[1] = 1;
    for(int i=1; i<Q; i++){
        num[i] = N/i - N/(i+1);
    }
    num[Q] = N/Q - Q;

    static int64_t dp1[101][32000], dp2[101][32000];
    dp1[0][1] = 1;
    for(int i=0; i<K; i++){
        int64_t sum1 = 0;
        for(int j=1; j<=Q; j++) add(sum1, dp1[i][j]);
        for(int j=1; j<=Q; j++) add(dp1[i+1][j], sum1);

        int64_t sum2 = 0;
        for(int j=Q; j>=1; j--){
            add(sum2, dp2[i][j]);
            add(dp1[i+1][j], sum2);
        }

        int64_t sum3 = 0;
        for(int j=1; j<=Q; j++){
            add(sum3, dp1[i][j]);
            add(dp2[i+1][j], sum3 * num[j]);
        }
    }

    int64_t ans = 0;
    for(int j=1; j<=Q; j++) add(ans, dp1[K][j] + dp2[K][j]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 50816
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
int main()
{
	ll N, K; cin >> N >> K;
	ll c = 1;
	rep(i, 0, N) {
		c = ((2 * c > c + K) ? (c + K) : 2 * c);
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a=0  , b;
  string s, m={};
  cin >> s;
  if(s.at(5)=='0'){
    if(s.at(6)=='1' || s.at(6)=='2' || s.at(6)=='3' || s.at(6)=='4') co("Heisei");
    else co("TBD");
  }
  else co("TBD"); 
  
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll d;cin>>d;
  ll num=26;
  vector<ll>c(num);
  rep(i,0,num)cin>>c[i];
  auto s=vec(d,num,0LL);
  rep(i,0,d)rep(j,0,num)cin>>s[i][j];
  vector<ll>t(d);
  rep(i,0,d)cin>>t[i],t[i]--;
  auto score=[&](vector<ll>t){
    ll ret=0;
    vector<ll>last(num,-1);
    rep(i,0,d){
      ret+=s[i][t[i]];
      last[t[i]]=i;
      rep(j,0,num)ret-=c[j]*(i-last[j]);
      cout<<ret<<endl;
    }
    return ret;
  };
  score(t);
  return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<vi > vvi;
typedef std::vector<vll > vvll;
typedef std::pair<int,int> ii;
typedef std::pair< ll, ll > lp;
typedef std::vector<ii> vii;
typedef std::vector<vii > vvii;


#define pb push_back 
#define PB pop_back
#define pf push_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)
#define lb(a,b) lower_bound(all(a),b)
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) f(i,0,n-1)cin>>a[i]
#define in1(a,n) f(i,1,n)cin>>a[i]
#define out(a,n) f(i,0,n-1)cout<<fixed<<setprecision(20)<<a[i]<<" ";cout<<"\n"
#define ff first
#define ss second
#define f(i,a,b) for (int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,n) f(i,0,n-1)
#define clr(a) (a).clear()
#define rz resize
#define sqr(a) ((a) * (a))
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin() ,(a).rend()
#define endl '\n'

const int N=405;

ll dp[N][N];

ll a[N],pref[N];

int main(int argc, char const *argv[])
{
	crap;

	rep(i,N)
		rep(j,N)
			dp[i][j]=99999999999999;

	int n;
	cin>>n;
	in1(a,n);

	f(i,1,n)
		pref[i]=pref[i-1]+a[i];

	f(i,1,n)
		dp[i][i]=0;

	f(len,2,n)
	{
		f(i,1,n-len+1)
		{
			int j=i+len-1;
			f(k,i,j-1)
			{
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
			}
			// cout<<i<<":"<<j<<"="<<dp[i][j]<<endl;
			dp[i][j]+=pref[j]-pref[i-1];
		}
	}

	cout<<dp[1][n]<<endl;
	return 0;
}

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

using namespace std;

int main(){
	map<string,int> ma;
	
	int n,m;
	cin >> n;
	string tmp;
	
	for(int i=0;i<n;++i){
		cin >> tmp;
		if(ma.find(tmp) == ma.end()){
			ma[tmp] = 1;
		}else{
			ma[tmp]++;
		}
	}
	
	cin >> m;
	for(int i=0;i<m;++i){
		cin >> tmp;
		if(ma.find(tmp) == ma.end()){
			ma[tmp] = 0;
		}else{
			ma[tmp]--;
		}
	}
	
	int res = 0;
	for(auto val : ma){
		//cout << val.first << " " << val.second << endl;
		res = max(res,val.second);
	}
	cout << res <<endl;
	
	return 0;
}



Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush 
def main():
    N, M = map(int, readline().split())
    tasks = [[] for _ in range(M)]
    for _ in range(N):
        a, b = map(int, readline().split())
        if M-a<0:
            continue
        tasks[M-a].append(b)
    s = 0
    h = []
    for i in [i for i in range(M)][::-1]:
        for b in tasks[i]:
            heappush(h, -b)
        if len(h)>0:
            s-=heappop(h)
    print(s)
if __name__ == '__main__':
    main()


Measured memory_bytes: 22288
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a;
  char x;
  cin >> x;
  cin >> b;
  if (x == '+') {
    cout << a+b << endl;
  }
  else {
    cout << a-b << endl;
  }
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        int x = Integer.parseInt(scan.next());
        int a = Integer.parseInt(scan.next());
        if(x < a){
            System.out.println(0);
        }else{
            System.out.println(10);
        }
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

int main()
{
    long long n;
    scanf("%lld\n", &n);

    vector <int> digits;
    while(n > 0)
    {   
        digits.push_back(n%10);
        n /= 10;
    }

    reverse(all(digits));

    vector <int> sum_till(digits.size() + 1, 0);
    for(int i = 0; i < digits.size(); i++)
        sum_till[i] = (i == 0 ? digits[i] : digits[i] + sum_till[i - 1]);

    int answer = 0;

    for(int i = 0; i < digits.size(); i++)
    {
        int sum_till_here = (i == digits.size() - 1 ? sum_till[i] : sum_till[i] - 1);
        int sum_from_here = 9*(digits.size() - 1 - i);

        int answer_if_common_prefix_ended_here = sum_till_here + sum_from_here;

        answer = max(answer, answer_if_common_prefix_ended_here);
    }

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


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

int main(void){
    long long int X;
    cin >> X;

    long long int ans = (X/500) * 1000 + ((X%500)/5) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{       
   public static void main(String[] args){
     
      Scanner sc = new Scanner(System.in);                                            
  
      Deque<Integer> q = new ArrayDeque<Integer>();
      
      int n = sc.nextInt();
      
      int a[] = new int[n];
      for(int i = 0;i < n;i++){
          a[i] = sc.nextInt();
      }
      
      if(n%2 == 0){
          for(int i = 0;i < n;i++){
             if(i%2 == 1){
                 q.addFirst(a[i]);
             }else{
                 q.addLast(a[i]);
             }
          }          
      }else{
          for(int i = 0;i < n;i++){
              if(i%2 == 1){
                  q.addLast(a[i]);
              }else{
                  q.addFirst(a[i]);
              }
          }
      }
      
      while(!q.isEmpty()){
          System.out.print(q.poll());
          System.out.print(" ");
      }
     
      System.out.println();
       
      
   }
}
        
        


Measured memory_bytes: 97480
/*c++11*/
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <climits>

using namespace std;

void dp(set<int>& coins, vector<int>& ints, int pos);
template<typename T>
void show(T);

int main(int args, char *argc[]){

  int n, m;
  int tmp; 
  set<int> coins;
  vector<int> ints;

  cin >> n >> m;
  ints = vector<int>(n+1, 0);
  for(int i = 0; i < m; i++){
    cin >> tmp;
    coins.insert(tmp);
  }
  dp(coins, ints, 1);

  //cout << endl;
  cout << ints[n] << endl;

  return 0;
}

void dp(set<int>& coins, vector<int>& ints, int pos){
  if(pos == static_cast<int>(ints.size())) return;
  int min = INT_MAX;
  for(auto i = coins.begin(); i != coins.end(); i++){
    //cout << *i << " " ;//debug
    if(*i > pos) break;
    int tmp = ints[pos - *i] + 1;
    min = min < tmp ? min : tmp;
    //cout << "pos:" << pos;
    //show(ints);
    //cout << "tmp:" << tmp << " " ;//debug
  }
  ints[pos] = min;
  dp(coins, ints, pos + 1);
}

template<typename T>
void show(T a){
  cout << endl << "show:" << endl;
  for(auto i = a.begin(); i != a.end(); i++){
    cout << *i << " ";
  }
  cout << endl; 
}


Measured memory_bytes: 3164