akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 0;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, x, y;
H a[300000];
vector<int>b[300000];
int fact[300000];
signed main() {
	cin >> n >> x >> y;
	H mi = { Inf,0 }, mmi = { Inf,0 };
	for (int i = 0; i < n; i++) {
		cin >> a[i].x >> a[i].y;
		b[a[i].x].push_back(a[i].y);
		if (mi.x > a[i].y) {
			mi.x = a[i].y;
			mi.y = a[i].x;
		}
	}
	for (int i = 0; i < n; i++) {
		if (a[i].x != mi.y) {
			if (mmi.x > a[i].y) {
				mmi.x = a[i].y;
				mmi.y = a[i].x;
			}
		}
	}
	int ans = 0;
	int sum = 1;
	fact[0] = 1;
	for (int i = 1; i < 300000; i++) {
		fact[i] = fact[i - 1] * i%Mod;
	}
	for (int i = 1; i <= n; i++) {
		if (b[i].size() == 0) continue;
		sort(all(b[i]));
		int res = 0;
		if (i == mi.y) {
			res = 1;
			for (int j = 1; j < b[i].size(); j++) {
				if (b[i][0] + b[i][j] <= x || (mmi.y > 0 && mmi.x + b[i][j] <= y)) {
					res++;
				}
			}
			ans += res;
			sum = sum * mod_pow(fact[res], Mod - 2, Mod) % Mod;
		}
		else {
			if (b[i][0] + mi.x > y) continue;
			res = 1;
			for (int j = 1; j < b[i].size(); j++) {
				if (b[i][0] + b[i][j] <= x || b[i][j] + mi.x <= y) {
					res++;
				}
			}
			ans += res;
			sum = sum * mod_pow(fact[res], Mod - 2, Mod) % Mod;
		}
	}
	cout << fact[ans] * sum%Mod << endl;
}

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

int main() {
  string s;
  cin >> s;
  vector<int> res(26, 0);
  rep(i, s.size()){
    int a = s[i] - 'a';
    res[a]++;
  }
  rep(i, 26) {
    if(res[i] == 0){
      char c = 'a' + i;
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define cont continue  
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 2147483646;
const double pi = 3.141592653589793;

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int N;
  int arr[200001] = {};

  cin >> N;

  for(int i = 1 ; i <= N ; i++) {
    cin >> arr[i];
  }
  map<ll, ll> m;
  for(int i = 1 ; i <= N ; i++) {
    m[arr[i] + i]++;
  }

  ll ans = 0;
  for(int i = 1 ; i <= N ; i++) {
    ans += m[i - arr[i]];
  }
  cout << ans << endl;
} 


Measured memory_bytes: 26956
#include<iostream>
using namespace std;
int bubbleSort(int A[], int N){
int sw = 0;
bool flag = 1;
for(int i = 0; flag; i++){
flag = 0;
for(int j = N - 1; j >= i + 1; j--){
if(A[j] < A[j - 1]){
swap(A[j], A[j - 1]);
flag = 1;
sw++;
}
}
}
return sw;
}
int main(){
int A[100], N, sw;
cin >> N;
for(int i = 0; i < N; i++) cin >> A[i];
sw = bubbleSort(A, N);
for(int i = 0; i < N; i++){
if(i) cout << " ";
cout << A[i];
}
cout << endl;
cout << sw << endl;
return 0;
}



Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n+1];
		long[] b=new long[n];
		long sum=0;

		for(int i=0;i<=n;i++) a[i]=sc.nextLong();

		for(int i=0;i<n;i++) b[i]=sc.nextLong();

		for(int i=n-1;i>=0;i--) {
			sum+=Math.min(a[i+1], b[i]);
			b[i]=Math.max(0, b[i]-a[i+1]);
			sum+=Math.min(a[i], b[i]);
			a[i]=Math.max(0, a[i]-b[i]);
		}
		System.out.println(sum);
	}
}



Measured memory_bytes: 92232
N = int(input())
kireru = []
muri = []
summrize = 0
for i in range(N):
    inp = int(input())
    if inp % 10 == 0:
        kireru.append(inp)
    else:
        muri.append(inp)
    summrize += inp
k = sorted(muri)
if summrize % 10 == 0:
    if(len(k)>0):
        print(summrize - k[0])
    else:
        print(0)
else:
    print(summrize)

Measured memory_bytes: 3060
#include<stdio.h>
int main() {
    int h = 0, m = 0, s = 0;
    scanf("%d",&s);
    if(s >= 60){
        m = s / 60;
        s = s % 60;
    }
    if(m >= 60){
        h = m / 60;
        m = m % 60;
    }
    printf("%d:%d:%d\n", h, m, s);

    return 0;
}



Measured memory_bytes: 2136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
int main(){
	char s[10],c[10];
	cin>>s>>c;
	if(s[2]==c[0]&&s[1]==c[1]&&s[0]==c[2]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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 = 100000; 

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

    vector<int> a(m+1, 0);
    vector<int> b(m+1, 0);
    for(int i = 1; i <= m; i++) cin >> a[i] >> b[i];

    vector<int> load(n+1, 0);
    for(int i = 1; i <= m; i++){
        load[a[i]]++;
        load[b[i]]++;
    }

    for(int i = 1; i <= n; i++){
       cout << load[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
int main()
{
   int n;
   cin>>n;
   int a[n][3];
   for(int i=0;i<n;i++)
   cin>>a[i][0]>>a[i][1]>>a[i][2];
   int dp[n][3];
   dp[0][0]=a[0][0];
   dp[0][1]=a[0][1];
   dp[0][2]=a[0][2];

   for(int i=1;i<n;i++){
    dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
   }
  vector<int> v;
  for(int i=0;i<3;i++)
  v.pb(dp[n-1][i]);
  sort(v.begin(),v.end());
  cout<<v[2];
    return 0;
}

Measured memory_bytes: 2560
N, M = map(int, input().split())
cakes = []
for i in range(N):
    x, y, z = map(int, input().split())
    cakes.append([x, y, z])


if M == 0:
    print(0)
    quit()
score = [0]*8
s = sorted(map(lambda c: c[0]+c[1]+c[2], cakes))
score[0] = sum(s[-M:])
score[1] = -sum(s[:M])
s = sorted(map(lambda c: c[0]+c[1]-c[2], cakes))
score[2] = sum(s[-M:])
score[3] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]+c[2], cakes))
score[4] = sum(s[-M:])
score[5] = -sum(s[:M])
s = sorted(map(lambda c: c[0]-c[1]-c[2], cakes))
score[6] = sum(s[-M:])
score[7] = -sum(s[:M])
print(max(score))

Measured memory_bytes: 3316
from collections import deque


# 隣り合ったマスへ移動するためのテーブル
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

H, W = map(int, input().split())
maze = [input() for _ in range(H)]

# 全ての"."の地点からBFSしてスタートからの各地点への移動回数(深さ)を調べ、最大のものを出力する
def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            # スタートが壁の場合
            if maze[i][j] == "#":
                continue
        
            # BFSの初期化、初期条件
            dist = [[-1] * W for _ in range(H)]
            dist[i][j] = 0
            que = deque()
            que.append([i, j])

            # BFSループ
            while que:
                y, x = que.popleft()
                for k in range(4):
                    nx = x + dx[k]
                    ny = y + dy[k]

                    # 迷路から外れる場合
                    if nx >= W or nx < 0 or ny >= H or ny < 0:
                        continue
                    # 既に探索済みの場合
                    if dist[ny][nx] != -1:
                        continue
                    # 隣が壁の場合
                    if maze[ny][nx] == "#":
                        continue
                    dist[ny][nx] = dist[y][x] + 1
                    que.append([ny, nx])

            ans = max(ans, max(max(steps) for steps in dist))
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 74716
if __name__ == '__main__':
    N, A, B, C, D = map(int, input().split())
    S = str(input())

    answer = "-1"

    if C < D:
       if S[A:D:].count("##") >= 1:
           answer = "No"
       else:
           answer = "Yes"
    else:

        answer = "No"
        for x in range(B, D+1):
            if (S[x-2] == "." and S[x-1] == "." and S[x] == "."):
               answer = "Yes"

    print(answer)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    for(int i=1;i<=n;i++)
        cin>>A[i];

    for(int i=1;i<=n;i++)
        if(A[i]!=i)cnt++;

    if(cnt==2||cnt==0)cout<<"YES\n";
    else cout<<"NO\n";

    return 0;
}


Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  vector<ll> v(3); cin >> v;
  sort(all(v));
  cout << (v[0] == v[2]) << endl;
}


Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(n):
    arr.append(list(map(int, input().split())))
b = 0
for i in range(n):
    for j in range(n):
        b += ((arr[i][0] - arr[j][0]) ** 2 + (arr[i][1] - arr[j][1]) ** 2) ** 0.5
print(b / n)


Measured memory_bytes: 3060
n = int(input())
s = input()

key = [0]*(n+1)
for i in range(n):
  key[i+1] = key[i]
  if s[i] == "#":
    key[i+1] += 1

ans = n+1
for i in range(n+1):
  sub = 2*key[i]+n-i-key[-1]
  if ans > sub:
    ans = sub

print(ans)

Measured memory_bytes: 11240
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        int[] d = new int[n];

        for (int i = 0; i < n; i++) {
            d[i] = Integer.parseInt(sc.next());
        }

        int sum = 0;

        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                sum += d[i] * d[j];
            }
        }

        System.out.println(sum);
        sc.close();
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  ll N;cin>>N;
  vl dp(87);dp[0]=2;dp[1]=1;
  for(int i=2;i<87; i++){
    dp[i]=dp[i-1]+dp[i-2];
  }
  cout<<dp[N]<<endl;

}







Measured memory_bytes: 256
#include <stdio.h>
int main()
{
int ax ,ay;
ax=1 ;

do{ay=1 ;

do{
printf("%dx%d=%d\n", ax,ay,ax*ay); ay=ay+1 ;
} while (ay != 10);
ax=ax+1 ;
} while (ax != 10);

return(0);
}

Measured memory_bytes: 524
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
  int a[100][100];
  int b[100];
  int c;
  int row,col;
  cin >> row >> col;

  for(int i = 0; i < row ; i++)
  {
    for(int j = 0; j < col ; j++)
    {
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < col; i++)
  {
    cin >> b[i];
  }

  for(int i = 0;i < row; i ++)
  {
    c = 0;
    for(int j = 0; j < col ; j++)
    {
      c += (b[j]*a[i][j]);
    }
    cout << c << endl;
  }
  return 0;
}



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

struct Edge {
    int dir;
    long long cost;

    bool operator <(const Edge &another) {
        return cost < another.cost;
    }
};

int main() {
    int w, h;
    cin >> w >> h;
    vector<Edge> edges;
    //dir = 0: 横 dir = 1: 縦
    for (int i = 0; i < w; i++) {
        int c;
        cin >> c;
        edges.push_back(Edge{0, c});
    }
    for (int i = 0; i < h; i++) {
        int c;
        cin >> c;
        edges.push_back(Edge{1, c});
    }
    sort(edges.begin(), edges.end());

    //cnt[0]: 横 cnt[1]: 縦
    vector<int> cnt(2);
    cnt.at(0) = w + 1;
    cnt.at(1) = h + 1;
    long long ans = 0;
    for (int i = 0; i < h + w; i++) {
        ans += edges.at(i).cost *  max(0, cnt.at(edges.at(i).dir ^ 1));
        cnt.at(edges.at(i).dir)--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6512
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int):
    print(-(-N//2))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << '\n';
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll m;
map<ll,ll> ma;
Vi d,c;

bool ck(){
	ll sum = 0;
	rep(i,10){
		sum += ma[i];
		if(sum>=2)return true;
	}
	return false;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>m;
	d.resize(m);
	c.resize(m);
	rep(i,m){
		cin>>d[i]>>c[i];
		ma[d[i]] += c[i];
	}
	ll ans = 0;
	while(ck()){
		rep(i,10){
			ll sum = 0;
			if(i==0){
				if(ma[i]<2)continue;
				ans += ma[i]-1;
				ma[i] = 1;
			}else{
				while(ma[i]>1){
				if(ma[i]*i<10){
					sum = ma[i]*i;
					ans += ma[i]-1;
					ma[i] = 0;
					ma[sum]++;
				}else{
					ll tmp = 10/i;
					if(10%i==0){
						tmp--;
					}
					tmp++;
					ll ret = ma[i]/tmp;
					ma[i]%=tmp;
					sum = tmp*i;
					sum = sum%10 + sum/10;
					ans += tmp*ret;
					ma[sum]+=ret;
				}
				}
			}
		}
		rep(i,10){
			if(ma[i]==0)continue;
			repi(j,i+1,10){
				if(ma[i]==0)continue;
				if(ma[j]==0)continue;
				ll sum = i+j;
				ans++;
				if(sum>=10)ans++;
				sum = sum/10 + sum%10;
				ma[i]--;
				ma[j]--;
				ma[sum]++;
			}
		}
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

long long N,K;

int main(){
    cin >> N >> K;
    if(K%2 == 1){
        long long l = N / K;
        l = l * l * l;
        cout << l << endl;
    }else{
        long long l = N / K;
        l = l * l * l;
        if(N % K < K/2){
            cout << 2*l << endl;
        }else{
            long long r = N/K + 1;
            cout << l + r*r*r << endl;
        }
    }   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char nl = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<nl; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<nl;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show_(const T& t) {cout<<t;}
template<class T> void show_(const vector<T>& v) {cout<<joined(v);}
void show_(bool b) {cout<<(b?"Yes":"No");}
void show_(double d) {cout<<fixed<<setprecision(12)<<d;}
template<class T, class... TS> void show_(const T& t, TS... ts) {show_(t);cout<<' ';show_(ts...);}
template<class T> void show(const T& t) {show_(t);cout<<nl;}
template<class T, class... TS> void show(const T& t, TS... ts) {show_(t, ts...);cout<<nl;}

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<set<int>> tree(N);
    for (int i : irange(0, N-1)) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].emplace(b);
        tree[b].emplace(a);
    }
    vector<ll> values(N);
    for (int i : irange(0, Q)) {
        int p, x;
        cin >> p >> x;
        p--;
        values[p] += x;
    }
    vector<bool> visited(N, false);
    queue<int> q;
    q.push(0);
    visited[0] = true;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int w : tree[v]) {
            if (!visited[w]) {
                values[w] += values[v];
                q.push(w);
                visited[w] = true;
            }
        }
    }
    show(values);
}


Measured memory_bytes: 32768
#include <iostream>
using namespace std;
int main(){
	long long int n,m;
	long long int counter=0;
	cin >> n >> m ;
	if( n<m){
		counter=n;
		m=m-n*2;
		counter+=m/4;
	}
	else{
		counter=m/2;
	}
	cout << counter << endl;
}


Measured memory_bytes: 256
def main():
    N, T = map(int, input().split())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    u = [0] + [B[0]] * (T)
    v = [0] * A[0] + [B[0]] * (T - A[0] + 1)
    
    for i in range(1, N):
        a, b = A[i], B[i]
        for t in range(T, 0, -1):
            vv = b + v[t - 1]
            if t >= a:
                vv = max(vv, b + u[t - a])
            if u[t] < vv:
                u[t] = vv
        for t in range(T, a - 1, -1):
            vv = b + v[t - a]
            if v[t] < vv:
                v[t] = vv
    print(u[T])

            



main()


Measured memory_bytes: 46828
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
using namespace std;
 
int days[100000];
 
int main(void){
    // Here your code !
    int N, M;
    scanf("%d %d", &N, &M);
    int now;
    scanf("%d", &now);
    for (int i = 0; i<M - 1; i++){
        int next;
        scanf("%d", &next);
        if (now<next){
            days[now]++;
            days[next]--;
        }
        else{
            days[next]++;
            days[now]--;
        }
        now = next;
    }
    unsigned long long int ans = 0;
    for (int i = 1; i<N; i++){
        days[i]+=days[i-1];
        int A, B, C;
        scanf("%d %d %d", &A, &B, &C);
        ans += min(((unsigned long long)A)*days[i], ((unsigned long long)B)*days[i] + C);
    }
    printf("%lld\n", ans);
}


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

int N;
int arr[1010];

int main() {
    cin >> N; 
    for (int j = 0; j < N; ++j) {
        cin >> arr[j];
    }
    int val = -1;
    for (int j = 0; j < N; ++j) {
        for (int k = j+1; k < N; ++k) {
            int prod = arr[j] * arr[k];

            bool valid = true;
            int prev_dig = prod % 10;
            for (int tmp = prod/10; tmp > 0; tmp /= 10, --prev_dig) {
                int dig = tmp % 10;
                if (dig != prev_dig-1) {
                    valid = false;
                    break;
                }
            }

            if (valid) {
                val = max(val, prod);
            }
        }
    }
    cout << val << endl;
    return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int a,b,k;
    cin>>a>>b>>k;
    int cnt=0;
    for(int i=100;i>0;--i){
        if(a%i==0&&b%i==0)k--;
        if(k==0)
        {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		int a[]=new int[N];
		int xor=0;
		for(int i=0;i<N;i++){
			a[i]=nextInt();xor^=a[i];
		}
		for(int i=0;i<N;i++){
			out.println(xor^a[i]);
		}
		out.flush();
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}


Measured memory_bytes: 51132
#include <iostream>
using namespace std;
 
int main (){
	int N,L,ans,A,F,C;
  	int	T[N];
  	N = L = ans = A = F = C = 0;
  	cin >> N >> L; 
  	for (int i = 1;i<=N;i++){
    	T[i] = L + i -1;
      	if(T[i]<0){
        	T[i] = T[i]*-1;
          	F = 1;
        }
    }
  	A = T[1];
    for(int i = 2;i<=N;i++){
        if(A > T[i] || T[i] == 0){
        	A = T[i];
        }
    }
  	for (int i = 1;i<=N;i++){
      	if(T[i] == 0 && F == 1){
      	 	while (i>=1){
         		T[i] = T[i] * -1;
           		i--;
         	}
         	C = 1;
        	break;
      	}
    }
    for (int i = 1;i<=N;i++){
      	if(F == 1 && C == 0){
        	i = N;
      	 	while (i>=1){
         		T[i] = T[i] * -1;
           		i--;
         	}
      	}
      	break;
    }
  	for(int i = 1;i<=N;i++){
    	ans += T[i];
    }
	if(ans < 0){
    	ans = ans + A;
    }
    else{
  		ans = ans - A;
    }
  	cout << ans;
}

Measured memory_bytes: 256
n = int(input())
l =  list (map (int, input().strip().split()))
d={}
s = 0
for i in range(n):
    s+=l[i]
    if l[i] not in d:
        d[l[i]]  = 1 
    else:
        d[l[i]]+=1 
q = int(input())
for i in range(q):
    l2 =  list (map (int, input().strip().split()))
    b = l2[0]
    c = l2[1]
    x = 0
    y = 0
    if b not in d:
        x = 0
    else:
        x = d[b]
    if c not in d:
        y = 0
    else:
        y = d[c]
    test1 =  (c-b)*x
    s = s+test1
    print(s)
    d[b]=0
    d[c] = x+y

Measured memory_bytes: 23832
#include <iostream>
#include <map>
#include <string>

int main (){
    int N;
    std::map<std::string,bool> apper;
    bool judge=1;
    std::string tmp;
    std::cin >> N;
    std::cin >>tmp;
    apper[tmp] = 1;
    std::string prev=tmp;
    for (int i = 0; i < N-1; i++){
        std::cin >>tmp;
        if(apper[tmp]==0 && tmp[0]==prev[prev.size()-1]){
            apper[tmp] = 1;
            prev=tmp;
        }
        else{
            judge=0;
        }
    }
    if(judge) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 764
// Red_Ace

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mx=0, cnt=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='R') cnt++;
        else cnt=0;
        mx = max(mx, cnt);
    }
    cout<<mx<<endl;
}

Measured memory_bytes: 3632
import sys
import math

mymax = int(100/0.1)
#print(mymax)
A, B = map(int,input().split())

for i in range(mymax + 1):
    if math.floor(i*0.08) == A and math.floor(i*0.1) == B:
        print(i)
        sys.exit()
print(-1)

Measured memory_bytes: 3060
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll k,A,B,i;cin>>k>>A>>B;
	bool f=false;
	for(i=A;i<=B;i++)
		if(i%k==0){
			f=true;
			break;
		}
		if(f)
			cout<<"OK";
		else cout<<"NG";
	return 0;
} 

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    sort(a.begin(), a.end(), greater<int>());
    
    ll ans = 0, mxi = 0;
    for (int i = 1; i < n; i++) {
        ans += a[mxi];
        if (i % 2 == 1)
            mxi++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	vector<string> a(3);
	cin >> a[0] >> a[1] >> a[2];
	cout << a[0][0] << a[1][1] << a[2][2] << '\n';
 	return 0;
}


Measured memory_bytes: 256
S = input()
if S == "SAT":
    print(1)
elif S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
    


Measured memory_bytes: 2940
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    VV vec(m);
    rep(i, n)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        if(a>=m)continue;
        vec[a].push_back(b);
    }
    priority_queue<ll> q;
    ll sum = 0;
    rep(i,m){
        rep(j,vec[i].size()){
            q.push(vec[i][j]);
        }
        if(!q.empty()){
            sum += q.top();
            q.pop();
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <queue>
#define INF 1e9
using namespace std;

int main(){
    //declaration and input
    int n;
    cin >> n;
    int u, k;
    vector<vector<pair<int, int>>> graph(n);
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            graph[u].push_back(make_pair(c, v));
        }
    }
    vector<int> cost(n, INF);
    vector<bool> is_visit(n, false);
    vector<int> parent_of(n, -1);

    //dijkstra
    //init
    cost[0] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    que.push(make_pair(0, 0));

    //loop
    while (!que.empty()){
        pair<int, int> p = que.top();
        que.pop();
        int c = p.first; //cost
        int v = p.second; //vertax
        is_visit[v] = true;
        if (c > cost[v])
            continue;
        for (int i = 0; i < graph[v].size(); i++){
            if (!is_visit[graph[v][i].second]){
                if (cost[v] + graph[v][i].first < cost[graph[v][i].second]){
                    cost[graph[v][i].second] = cost[v] + graph[v][i].first;
                    que.push(make_pair(cost[graph[v][i].second], graph[v][i].second));
                    parent_of[graph[v][i].second] = v;
                }
            }
        }
    }

    //output
    for (int i = 0; i < n; i++){
        cout << i << ' ' << cost[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 7768
import sys
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline()
def read(): return int(input())
def reads(): return [int(i) for i in input().split()]

N, Y = reads()

x_max = min(N, Y//10000)
y_max = min(N, Y//5000)

ans = (-1, -1, -1)

for x in range(x_max+1):
	for y in range(N-x+1):
		if 10000*x + 5000*y + 1000*(N-x-y) == Y:
			ans = (x, y, N-x-y)
			break

print(str(ans[0])+' '+str(ans[1])+' '+str(ans[2]))

Measured memory_bytes: 40812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x;
    cin>>x;
    x-=400;
    cout<<8-x/200<<endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

vector<int> ans;
vector<vector<int> > G;

void dfs(int v, int p=-1) {
    for (int u : G[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main() {
    int n, q; cin >> n >> q;
    ans.resize(n);
    G.resize(n);
    int p, x;
    
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, q) {
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);
    rep(i, n) {
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 23552
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, r;
  scanf("%d%d", &n, &r);
  printf("%d\n", n >= 10 ? r : r + 100 * (10 - n));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n,u,v,a,b;
vector<int>tree[100010];
int flag1[100010];
int flag2[100010];
void dfs(int ud,int m,int flag[]){
    for(auto vd:tree[ud]){
        if(vd!=m){
            flag[vd]=flag[ud]+1;
            dfs(vd,ud,flag);
        }
    }
}

void solve()
{
    cin>>n>>u>>v;u--;v--;
    REP(i,n-1){
        cin>>a>>b;
        a--;b--;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    dfs(u,-1,flag1);
    dfs(v,-1,flag2);
    int ans=0;
    REP(i,n){
        if(flag2[i]>flag1[i])ans=max(ans,flag2[i]);
    }
    cout<<ans-1<<endl;
}

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



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

void swap( int& x, int& y )
{
    int temp = x;
    x = y;
    y = temp;
}

void reverse( int* a, int b, int e )
{
    int i = b, j = e - 1;
    while( i < j )
    {
        swap( a[i], a[j] );
        i++;
        j--;
    }
}

int main()
{
    int n, q;
    int b, e;

    cin >> n;

    int a[n];

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

    cin >> q;

    for( int i = 0; i < q; i++ )
    {
        cin >> b >> e;
        reverse( a, b, e );                                 //反転
    }
    
    for( int i = 0; i < n - 1; i++ )                        //presentationError処理の出力
        cout << a[i] << " ";
    cout << a[n-1] << endl;

    return 0;
}


Measured memory_bytes: 3072
D = int(input())
c = [int(_) for _ in input().split()]
s = [[int(_) for _ in input().split()] for _ in range(D)]

out = [int(input()) for _ in range(D)]

sat = 0
last = [0] * 26
for d in range(D):
    assert(1 <= out[d] and out[d] <= 26)
    j = out[d] - 1
    last[j] = d + 1
    for i in range(26):
        sat -= (d + 1 - last[i]) * c[i]
    sat += s[d][j]
    print(sat)


Measured memory_bytes: 9444
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std ;
typedef long long int ll ;


int main(){
	int n,a[20],b[20],c[20];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n-1;i++)cin>>c[i];
	
	ll sum=0;
	for(int i=0; i<n; i++){
		sum+=b[a[i]-1];
	//	cout<<b[a[i]-1]<<" ";
		if(a[i+1]-a[i]==1)sum+=c[a[i]-1];
		//	cout<<c[i]<<" ";
	}
	cout<<sum<<'\n';
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;
#define         rep(i,n)       for (int i = 0;i<(int)(n);i++)
#define         pi             3.14159265359
#define         nl             printf("\n")
#define         gcd(a,b)       __gcd(a,b)
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         pf             printf
#define         sf             scanf
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
typedef long long int ll;

int main()
{

    FIO;
    int i,j,k,temp,n,f=0,x;
    cin>>i>>j;
    cout<<(max((i-2*j),0))<<endl;
    return 0;

}


Measured memory_bytes: 256