akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  int n, k; cin >> n >> k;
  ll r, s, p; cin >> r >> s >> p;
  map <char, char> lose;
  lose['s'] = 'r', lose['p'] = 's', lose['r'] = 'p';
  string S; cin >> S;
  S = "#" + S;
  string t = "#";
  ll score = 0;
  for(int i = 1; i <= n; i++) {
    if(i <= k) {
      t += lose[S[i]];
      if(lose[S[i]] == 'r') score += r;
      if(lose[S[i]] == 's') score += s;
      if(lose[S[i]] == 'p') score += p;
    }
    else {
      if(t[i - k] == lose[S[i]]) {
        char P = '4';
        if(i + k <= n) P = lose[S[i + k]];
        for(auto c : {'r', 's', 'p'}) {
          if(c != t[i - k] and c != P) {
            t += c;
            break;
          }
        }
      }
      else {
        t += lose[S[i]];
        if(lose[S[i]] == 'r') score += r;
        if(lose[S[i]] == 's') score += s;
        if(lose[S[i]] == 'p') score += p;
      }
    }
  }
  cout << score << '\n';
}

Measured memory_bytes: 512
import sys
def ink(x,y,size):
    global P
    P[y][x]+=1
    for d in [-1,1]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        P[y+d][x+d]+=1
        P[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    return

R=range(14)
P=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Measured memory_bytes: 4268
N = int(input())
H = list(map(int,input().split()))
L = []
M = [0]
t = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        L.append(1)
    else:
        L.append(0)

for i in range(N-1):
    if L[i]==1:
        t += 1
        M.append(t)
    else:
        t = 0
if not M:
    print(0)
else:
    print(max(M))

Measured memory_bytes: 14252
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;


int main(){
    int x, t; cin >> x >> t;
    cout << max(0, x-t) << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long i = sc.nextLong();
		long money = 100;
		int count = 0;

		while (money < i) {
			money += money * 0.01;
			count++;
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 35776
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

X = ii()

if X >= 30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9096
// ABC103
// A - Task Scheduling Problem
#include<bits/stdc++.h>

using namespace std;

int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    cout << a[2]-a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
ans = 0
if a >= n:
    ans = n
else:
    c  = n // (a+b)
    d = (n % (a+b))
    if d >= a:
        ans = c*a + a
    else:
        ans = c*a + d
print(ans)


Measured memory_bytes: 2940
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    ans = 0
    temp = 0
    for _ in range(n):
        d1, d2 = MI()
        if d1 == d2:
            temp += 1
        else:
            temp = 0
        ans = max(ans, temp)
    if ans >= 3:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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

int main() {
  int a,b;
  string c,d,e;
  cin>>c>>d>>a>>b>>e;
  if(c==e){
    a--;
  }
  else{
    b--;
  }
  cout<<a<<' '<<b<<endl;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  ll n;
  cin >> n;
  vector<ll> a(n);
  scan(a);

  vector<ll> ans(n);
  ans[0] = accumulate(all(a), 0LL);
  for (int i = 1; i < n; i += 2) {
    ans[0] -= 2 * a[i];
  }

  rep(i, 1, n) { ans[i] = 2 * a[i - 1] - ans[i - 1]; }

  string s;
  for (ll num : ans) {
    s += to_string(num) + " ";
  }
  s.pop_back();
  cout << s << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[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;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 4096
import math

n, d = map(int, input().split())
x = []
for i in range(n): x.append(list(map(int, input().split())))

def is_int(num):
    if total - int(total) == 0: return True
    else: False

ans = 0
for i in range(n):
    for k in range(i, n-1):
        
        total = 0
        if d == 1:
            total += abs(x[i][0])**2
        else:
            for j in range(d):
                total += abs(x[i][j] - x[k+1][j])**2
            total = math.sqrt(total)
        if is_int(total): ans += 1

print(ans)

Measured memory_bytes: 3064
/**
 *    author:  tourist
 *    created: 18.12.2019 11:32:59       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int ns = (int) s.size();
  int nt = (int) t.size();
  vector<vector<int>> dp(ns + 1, vector<int>(nt + 1));
  for (int i = 0; i < ns; i++) {
    for (int j = 0; j < nt; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
      }
    }
  }
  string u = "";
  int i = ns, j = nt;
  while (i > 0 && j > 0) {
    if (s[i - 1] == t[j - 1]) {
      u += s[i - 1];
      --i; --j;
    } else {
      if (dp[i][j] == dp[i - 1][j]) {
        --i;
      } else {
        --j;
      }
    }
  }
  reverse(u.begin(), u.end());
  cout << u << '\n';
  return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"

signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,anss=0,start=0,end=0,r=0,qq=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    int reqd=0;
    
    cin>>r;
    double ab;
    double pi=3.14159265358979323846264338328;
    ab=2*pi*r;
    cout<<setprecision(30)<<ab<<endl;
    
    
    
    
}

Measured memory_bytes: 3800
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String b = sc.nextLine();
    if (b.equals("A")) {
      System.out.println("T");
    } else if (b.equals("T")) {
      System.out.println("A");
    } else if (b.equals("C")) {
      System.out.println("G");
    } else {
      System.out.println("C");
    }
  }
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n, x, q;
	ll sum = 0;
	map<int, int> cnt;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		cnt[x]++;
		sum += x;
	}
	
	cin >> q;
	for(int i = 0; i < q; i++){
		int a, b;
		
		cin >> a >> b;
		
		x = cnt[a];
		sum -= (ll) x * a;
		sum += (ll) x * b;
		cnt[a] -= x;
		cnt[b] += x;
		
		cout << sum << endl;
	}
	
	return 0;
}

Measured memory_bytes: 7988
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

#define repAll(n) (n).begin(), (n).end()
#define repConAll(n) (n).cbegin(), (n).cend()

using namespace std;

namespace {

}
int main()
{
	int N = 0;
	cin >> N;

	vector<int> vctA(N);
	vector<int> vctB(N);
	vector<int> vctC(N);

	for (auto& elem : vctA) {
		cin >> elem;
	}
	for (auto& elem : vctB) {
		cin >> elem;
	}
	for (auto& elem : vctC) {
		cin >> elem;
	}

	sort(vctA.begin(), vctA.end());
	sort(vctB.begin(), vctB.end());
	sort(vctC.begin(), vctC.end());

	// Bに対してAの個数のBによるループ
	vector<long long> vctSumBa(N, 0);
	long long sumA = 0;
	for (int i = 0; i < N; ++i) {
		auto itr = lower_bound(repAll(vctA), vctB[i]);
		if (itr == vctA.begin()) {
			continue;
		}
		int numA = 0;

		numA = itr - vctA.begin();// itr == vctA.end() の場合も含む。
		sumA += numA;
		vctSumBa[i] = sumA;
	}

	// Cに対してBの個数のCによるループ
	long long sumBAll = 0;
	for (int i = 0; i < N; i++) {
		auto itr = lower_bound(repAll(vctB), vctC[i]);
		if (itr == vctB.begin()) {
			continue;
		}
		long long curSumB = 0;
		
		curSumB = vctSumBa[itr - vctB.begin() - 1]; // itm == vctB.end() の場合も含む。
		sumBAll += curSumB;
	}

	// 全体の合計
	cout << sumBAll;

	return 0;
}

Measured memory_bytes: 2304
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = long.Parse(Console.ReadLine());
            while (!IsPrime(num))
            {
                num = num + 1;
            }
            Console.WriteLine(num);
        }

        public static bool IsPrime(long num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }
}

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

const int N = 200000 + 10;
int n, a[N], np[N], b1[N];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	vector <int> v;
	for(int b = n; b >= 1; b--) {
		ll sum = 0;
		for(int d = b * 2; d <= n; d += b) sum += b1[d];
		if(a[b] % 2 != sum % 2) {
			v.push_back(b);
			b1[b] = 1;
		}
	}
	for(int i = 1; i <= n; i++) {
		ll sum = 0;
		for(int j = i; j <= n; j += i) sum += b1[j];
		if(sum % 2 != a[i] % 2) {
			puts("-1");
			return 0;
		} 
	}
	cout << v.size() << endl;
	for(auto t: v) cout << t << endl;
	return 0;
}



Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int k;
    cin >> k;
  	string s;
  	cin >> s;
  	if((int)s.length() <= k){
    	cout << s;
    }
  	else {
    	s = s.substr(0, k) + "...";
      	cout << s ;
    }
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n,w;
        cin >> n >> w;
        int i,j,val[n+1],wei[n+1];
        int dp[n+1][w+1];
        for(i=0; i<n; i++){
            cin >> wei[i] >> val[i];
        }
        for(i=0; i<=n; i++){
            for(j=0; j<=w; j++){
                if(i==0 || j==0) dp[i][j]=0;
                else if(wei[i-1] <=j){
                    dp[i][j]=max(dp[i-1][j],dp[i-1][j-wei[i-1]]+val[i-1]);
                }
                else{
                    dp[i][j]=dp[i-1][j];
                }
            }
        }

        cout << dp[n][w] << '\n';

        

}

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

template <int mod = (int)(1e9 + 7)>
struct ModInt {
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  constexpr ModInt &operator+=(const ModInt &p) noexcept {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &p) noexcept {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &p) noexcept {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  constexpr ModInt &operator/=(const ModInt &p) noexcept {
    *this *= p.inverse();
    return *this;
  }
  constexpr ModInt operator-() const { return ModInt(-x); }
  constexpr ModInt operator+(const ModInt &p) const noexcept {
    return ModInt(*this) += p;
  }
  constexpr ModInt operator-(const ModInt &p) const noexcept {
    return ModInt(*this) -= p;
  }
  constexpr ModInt operator*(const ModInt &p) const noexcept {
    return ModInt(*this) *= p;
  }
  constexpr ModInt operator/(const ModInt &p) const noexcept {
    return ModInt(*this) /= p;
  }
  constexpr bool operator==(const ModInt &p) const noexcept { return x == p.x; }
  constexpr bool operator!=(const ModInt &p) const noexcept { return x != p.x; }
  constexpr ModInt inverse() const noexcept {
    int a = x, b = mod, u = 1, v = 0, t = 0;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  constexpr ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend constexpr ostream &operator<<(ostream &os, const ModInt &p) noexcept {
    return os << p.x;
  }
  friend constexpr istream &operator>>(istream &is, ModInt &a) noexcept {
    int64_t t = 0;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  constexpr int get_mod() { return mod; }
};

int n;
vector<int> a, t;

ModInt<> solve();

int main() {
  cin >> n;
  t.assign(n + 1, 0);
  for (int i = 0; i < n; ++i) cin >> t[i + 1];
  a.assign(n + 1, 0);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res = 1;
  if (t[n] != a[0]) return 0;
  reverse(a.begin(), a.end());
  int lid, rid;
  lid = t.end() - lower_bound(t.begin(), t.end(), t[n]);
  rid = a.end() - lower_bound(a.begin(), a.end(), a[n]);
  if (lid + rid < n + 1) return 0;
  res *= ModInt<>(t[n]).pow(max(lid + rid - n - 2, 0));
  auto cnt = [](vector<int> &v) {
    ModInt<> res = 1;
    int now = 0;
    for (int i = 1; v[i] < t[n]; ++i) {
      if (now == v[i])
        res *= now;
      else
        now = v[i];
    }
    return res;
  };
  return res * cnt(t) * cnt(a);
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi a(n); cin >> a;
	sort(ALL(a));
	int lb = 0, ub = n;
	while (ub - lb > 1)
	{
		int mid = (ub + lb) / 2;
		ll tmp = 0;
		REP(i, mid) tmp += a[i];
		bool f = true;
		FOR(i, mid, n)
		{
			if (a[i] > tmp * 2)
			{
				f = false;
				break;
			}
			else tmp += a[i];
		}
		if (f) ub = mid;
		else lb = mid;
	}
	cout << n - lb << endl;
	return 0;
}

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

int main(void){
	double x1, y1, x2, y2, x3, y3, px, py;
	double a, b, c, ap, bp, cp;
	double tmp;
	double s2, sa2, sb2, sc2;
	double s, sa, sb, sc;

	while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>px>>py){
		a = sqrt(fabs((x2-x3) * (x2-x3) + (y2-y3) * (y2-y3)));
		b = sqrt(fabs((x1-x3) * (x1-x3) + (y1-y3) * (y1-y3)));
		c = sqrt(fabs((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2)));
		ap = sqrt(fabs((x1-px) * (x1-px) + (y1-py) * (y1-py)));
		bp = sqrt(fabs((x2-px) * (x2-px) + (y2-py) * (y2-py)));
		cp = sqrt(fabs((x3-px) * (x3-px) + (y3-py) * (y3-py)));
		
		tmp = (a+b+c) / 2;
		s2 = tmp * (tmp-a) * (tmp-b) * (tmp-c);
		s = sqrt(s2);
		tmp = (a+bp+cp) / 2;
		sa2 = tmp * (tmp-a) * (tmp-bp) * (tmp-cp);
		sa = sqrt(sa2);
		tmp = (b+ap+cp) / 2;
		sb2 = tmp * (tmp-b) * (tmp-ap) * (tmp-cp);
		sb = sqrt(sb2);
		tmp = (c+ap+bp) / 2;
		sc2 = tmp * (tmp-c) * (tmp-ap) * (tmp-bp);
		sc = sqrt(sc2);
		if(fabs(sa+sb+sc-s) < 1e-9) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

const int N = 1e5 + 5;

const int mod = 1e9 + 7;

const int M = 1e9;

int n, m, a[N], b[N], cnt = 1;

map<int, int> bit;

void update(int pos, int val) {
    while(pos <= M) {
        bit[pos] = (1ll * bit[pos] + val) % mod;
        pos += pos & (-pos);
    }
}

int get(int pos) {
    int ans = 0;
    while(pos > 0) {
        ans = (1ll * ans + bit[pos]) % mod;
        pos -= pos & (-pos);
    }
    return ans;
}

vector<ii> pos;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];
    for(int i = 1; i <= n; i++) {
        while(cnt < m && b[cnt + 1] < a[i])
            cnt++;
        if(cnt < m && b[cnt] < a[i] && a[i] < b[cnt + 1])
            pos.pb({a[i] - b[cnt], b[cnt + 1] - a[i] + 1});
    }
    sort(pos.begin(), pos.end());
    update(1, 1);
    for(int i = 0; i < pos.size(); i++) {
        if(i > 0 && pos[i - 1] == pos[i])
            continue;
        int total = get(pos[i].se - 1);
        if(i > 0 && pos[i - 1].fi == pos[i].fi)
            total = (1ll * total - get(pos[i - 1].se - 1)) % mod;
        total = (1ll * total + mod) % mod;
        update(pos[i].se, total);
    }
    cout << get(M) << "\n";
}


Measured memory_bytes: 56432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define irep(i,a,b) for(typeof(i) i = (a); i < (b); ++i)
#define itrep(it,c) for(auto it = (c).begin(); it != (c).end(); ++it)

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

	ll N;
	cin >> N;
	multiset<pair<ll, ll> > D;
	multiset<ll> DC;
	char* S = new char[1000001];
	ll allD = 0;
	ll closure = 0;
	ll starter = 0;
	for (ll i = 0; i < N; i++) {
		cin >> S;
//		cout << S << endl;
		char* p = S;
		ll d = 0;
		ll md = 0;
		ll pd = 0;
		while (*p != '\0') {
			if (*p == 40) {
				d++;
			}
			else if (*p == 41){
				d--;
			}
			else {
				break;
			}
			if (md > d) md = d;
			if (pd < d) pd = d;
			p++;
		}
		ll x = - md;
		ll y = d + x;
		if (y == 0) {
			closure += x;
//			cout << "closure " << x << endl;
		}
		else if (x == 0) {
			starter += y;
//			cout << "starter " << y << endl;
		}
		else{
			D.insert(pair<ll, ll>(d, md));
//			cout << d << "," << md << endl;
		}
		allD += d;
	}
	if (allD != 0) {
		cout << "No" << endl;
		return(0);
	}
	ll cur = starter;
	while (D.size() > 0) {
		bool f = false;
		for (auto it = D.rbegin(); it != D.rend(); it++) {
			if (cur + it->second >= 0) {
//				cout << "E " << it->first << "," << it->second << endl;
				cur += it->first;
				D.erase((++it).base());
				f = true;
				break;
			}
		}
		if (!f) {
			cout << "No" << endl;
			return(0);
		}
	}
	cout << "Yes" << endl;
	return(0);
}


Measured memory_bytes: 16364
#include<stdio.h>

int main()
{
    float m,n,ar[200005],sum=0.0;
    scanf("%f %f",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%f",&ar[i]);
        sum+=ar[i];
    }
    float a=sum/(m*4);
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(ar[i]>=a)
            cnt++;
    }
    if(cnt>=m)
        printf("Yes\n");
    else
        printf("No\n");
}

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

int main()
{
	int n, m; cin >> n >> m;
	
	if (m == 1) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}

	vector<bool> can_1_to_i(n + 1, false), can_i_to_n(n + 1, false);
	
	for (int i = 0; i < m; i++) {
	
		int tmp_a, tmp_b; cin >> tmp_a >> tmp_b;
		
		if (tmp_a == 1) can_1_to_i[tmp_b] = true;

		if (tmp_b == n) can_i_to_n[tmp_a] = true;
	}

	string ans = "IMPOSSIBLE";
	
	for (int i = 1; i <= n; i++) {
		
			if (can_1_to_i[i] && can_i_to_n[i]) ans = "POSSIBLE";
	
	}

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

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

using LL = long long;

int main() {
#ifdef LOCAL_EXEC
	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

    LL t1, t2; cin >> t1 >> t2;
    LL a1, a2; cin >> a1 >> a2;
    LL b1, b2; cin >> b1 >> b2;

    LL v1 = b1 - a1, v2 = b2 - a2;
    if (v1 < 0) {
        v1 *= -1;
        v2 *= -1;
    }

    LL delta = v1 * t1 + v2 * t2;
    if (delta > 0) {
        cout << "0\n";
        return 0;
    }
    if (delta == 0) {
        cout << "infinity\n";
        return 0;
    }
    delta *= -1;
    LL h = v1 * t1;
    LL ans = 2 * (h / delta);
    if (h % delta) ++ans;
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
  int N, K;
  std::cin >> N >> K;

  std::vector<int> A(N);

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

  std::cout << (N - 1 + K - 2) / (K - 1) << std::endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define inf 1000000007;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

double t, x;

signed main() {
	cin >> t >> x;
	cout << t / x << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;


public class Main {
	Scanner sc;
	
	boolean solve(double[][] point){
		double[][] v=new double[3][2];
		for(int i=0;i<3;++i){
			for(int j=0;j<2;++j){
				v[i][j]=point[i][j]-point[3][j];
			}
		}
		double theta=0;
		for(int i=0;i<3;++i){
			double ip=(v[i][0]*v[(i+1)%3][0]+v[i][1]*v[(i+1)%3][1]);
			theta+=Math.acos(ip/Math.hypot(v[i][0],v[i][1])/Math.hypot(v[(i+1)%3][0],v[(i+1)%3][1]));
		}
		return theta>=Math.PI*2-1e-7;
	}
	
	double nd(){
		return sc.nextDouble();
	}
	
	void io(){
		sc=new Scanner(System.in);
		double[][] point=new double[4][2];
		while(sc.hasNext()){
			for(int i=0;i<4;++i){
				for(int j=0;j<2;++j){
					point[i][j]=nd();
				}
			}
			System.out.println(solve(point)?"YES":"NO");
		}
	}
	
	public static void main(String[] args){
		new Main().io();
	}
}

Measured memory_bytes: 23120
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int A, B, C, D;
        cin >> A >> B >> C >> D;

        int ans = 0;
        ans += min(A, B);
        ans += min(C, D);
        cout << ans << endl;

        return 0;
}


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

int main() {
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if (e-a<=k) puts("Yay!");
  else puts(":(");
  
}


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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int a,b,C;
    double S,L,h,rad,cs;
    scanf("%d %d %d",&a,&b,&C);
    rad=C*pai/180;
    cs=sqrt(a*a+b*b-2*a*b*cos(rad));
    h=b*sin(rad);
    printf("%.8lf\n%.8lf\n%.8lf\n",h*a/2,a+b+cs,h);
    return 0;
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e5 + 100;

int N, Q, D, Ds[MAX_N];
int Dis[MAX_N], minV[MAX_N];

int main() {
	cin >> N >> D;
	for(int i=1; i<=N; i++) scanf("%d", &Ds[i]);

	Dis[0] = D;
	for(int i=1; i<=N; i++) Dis[i] = min(Dis[i-1], abs(Dis[i-1] - Ds[i]));
	minV[N+1] = 1;
	for(int i=N; i>=1; i--) minV[i] = (Ds[i]/2 >= minV[i+1] ? minV[i+1] : Ds[i] + minV[i+1]);

	cin >> Q;
	while(Q--) {
		int q; scanf("%d", &q);
		if(Dis[q-1] >= minV[q+1]) puts("YES"); else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
int M = 1e9 + 7;
#define PI 3.14159265
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int x = n % 10;
  if (x == 1 || x == 0 || x == 6 || x == 8)
    cout << "pon";
  else if (x == 3)
    cout << "bon";
  else
    cout << "hon";
}

Measured memory_bytes: 3648
#include <string>
    #include <vector>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <iostream>
    #include <sstream>
    #include <cstring>
    #include <numeric>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<pii, pii> tri;
    #define F0(i,n) for (int i = 0; i < n; i++)
    #define F1(i,n) for (int i = 1; i <= n; i++)
    #define CL(a,x) memset(x, a, sizeof(x));
    #define SZ(x) ((int)x.size())
    const double eps = 1e-10;
    const int inf = 1000000009;
    int i, j, k, m, n, l, W, H;
    int ans;
     
    tri v[100001];
    bool vis[100001];
    vector<int> adj[100001];
    ll dx[100001], dy[100001];
    int vx[100001], vy[100001];
    ll minx, miny;
     
    int done[100001];
     
    void failed() {
    	cout << "No" << endl;
    	exit(0);
    }
     
    void dfs(int i) {
    	done[i] = 1;
    	tri A = v[i];
    	if (dx[A.first.first] < minx) minx = dx[A.first.first];
    	if (dy[A.first.second] < miny) miny = dy[A.first.second];
    	for (int j : adj[i]) {
    		tri B = v[j];
    		if (A.first.first == B.first.first) {
    			if (!done[j]) {
    				vy[B.first.second] = 1;
    				dy[B.first.second] = dy[A.first.second] + B.second.second - A.second.second;
    				dfs(j);
    			}
    			else {
    				if (dy[B.first.second] != dy[A.first.second] + B.second.second - A.second.second) failed();
    			}
    		}
    		else {
    			if (!done[j]) {
    				vx[B.first.first] = 1;
    				dx[B.first.first] = dx[A.first.first] + B.second.second - A.second.second;
    				dfs(j);
    			}
    			else {
    				if (dx[B.first.first] != dx[A.first.first] + B.second.second - A.second.second) failed();
    			}
    		}
    	}
    }
     
    void add_edges() {
    	sort(v, v + n);
    	F0(i, n - 1) if (v[i].first.first == v[i + 1].first.first) {
    		adj[v[i].second.first].push_back(v[i + 1].second.first);
    		adj[v[i + 1].second.first].push_back(v[i].second.first);
    	}
    }
     
    int gx[1000000], gy[1000000];
     
    int main() {
    	//freopen("x.in", "r", stdin);
    	
    	cin >> W >> H >> n;
    	F0(i, n) {
    		cin >> v[i].first.first >> v[i].first.second >> v[i].second.second;
    		v[i].second.first = i;
    	}
     
    	CL(0, vx);
    	CL(0, vy);
     
    	add_edges();
    	F0(i, n) swap(v[i].first.first, v[i].first.second);
    	add_edges();
    	F0(i, n) swap(v[i].first.first, v[i].first.second);
     
    	F0(i, n) swap(v[i].first, v[i].second);
    	sort(v, v + n);
    	F0(i, n) swap(v[i].first, v[i].second);
    	F0(i, n) if (!done[i]) {
    		vx[v[i].first.first] = 1;
    		vy[v[i].first.second] = 1;
    		dx[v[i].first.first] = 0;
    		dy[v[i].first.second] = v[i].second.second;
    		minx = 0;
    		miny = v[i].second.second;
    		dfs(i);
    		if (minx + miny < 0) failed();
    	}
    	cout << "Yes" << endl;
     
    	return 0;
    }

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int mov = min(a-b,c);
    cout<<c-mov<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define INF 1000000;

using namespace std;

int main() {
    string s;
    int size;

    cin >> s;
    size = s.size();
    for (int i=0; i<size; i=i+2){
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 512
n,m=map(int,input().split())
P=[[] for _ in range(n+1)]
for i in range(m):
    p,y=map(int,input().split())
    P[p].append([y,i+1])
ans=[]
for j in range(n+1):
    if P[j]:
        P[j].sort()
        for i in range(len(P[j])):
            #print(P[j])
            ans.append([P[j][i][1],str((j*10**6+i+1)).zfill(12)])
ans.sort()
for i in range(m):
    print(ans[i][1])


Measured memory_bytes: 90272
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int n, m;
  cin >> n >> m;
  vector<P> ab(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    ab[i] = P(b, a);
  }

  sort(all(ab));
  int cur = 0, ans = 0;
  rep(i, m) {
    if (cur <= ab[i].second) {
      cur = ab[i].first;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int Gcd(int m, int n)
{
    int temp;
    while (m % n != 0)
    {
        temp = n;
        n = m % n;
        m = temp;
    }
    return n;
}

int Lcm(long m, long n)
{
    return m * n / Gcd(m, n);
}

int main()
{
    long long n, m;
    cin >> n >> m;
    vector<long long> nums;
    for (int i = 1; i * i <= m; i++)
    {
        if (m % i == 0)
            nums.push_back(i);
    }
    for (int i = nums.size() - 1; i >= 0; i--)
    {
        nums.push_back(m / nums[i]);
    }
    long long ans = 1;
    for (int i = 0; i < nums.size(); i++)
    {
        if (nums[i] * n <= m)
            ans = nums[i];
        else
            break;
    }
    cout << ans << endl;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, a[200001], result = 0;
  map<int, int> count;
  cin >> n;
  FOR(i, 0, n) cin >> a[i];
  FOR(i, 1, n) {
    a[i] += a[i - 1];
    count[a[i]]++;
  }
  count[a[0]]++;

  for(auto it = count.begin(); it != count.end(); it++) {
    if (it->second > 1) {
      FOR(i, 0, it->second - 1) result += i + 1;
    }
  }

  result += count[0];
  cout << result << endl;
}

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

#define N 100010
#define pii pair <int, int>
#define fi first
#define se second
int n, q; 
struct node {
	int u, v, w, id;
	node() {}
	node(int v, int w) : v(v), w(w) {}
	node (int u, int v, int w, int id = 0) : u(u), v(v), w(w), id(id) {}
};
vector <vector<node>> E, Q, G;  
int res[N];  

int fa[N], deep[N], dis[N], sze[N], son[N], top[N], in[N], cnt;
void DFS(int u) {
	sze[u] = 1;
	for (auto it : G[u]) if (it.v != fa[u]) {
		int v = it.v;
		fa[v] = u;
		deep[v] = deep[u] + 1;
		dis[v] = dis[u] + it.w;
		DFS(v);
		sze[u] += sze[v];
		if (son[u] == -1 || sze[v] > sze[son[u]]) son[u] = v;
	}
}
void gettop(int u, int sp) {
	top[u] = sp;
	in[u] = ++cnt;
	if (son[u] == -1) return;
	gettop(son[u], sp);
	for (auto it : G[u]) {
		int v = it.v;
		if (v == fa[u] || v == son[u]) continue;
		gettop(v, v);
	}
}
int querylca(int u, int v) {
	while (top[u] != top[v]) {
		if (deep[top[u]] < deep[top[v]]) {
			swap(u, v);
		}
		u = fa[top[u]];
	}
	if (deep[u] > deep[v]) swap(u, v);
	return u;
}

pii add(pii x, pii y) {
	return pii(x.fi + y.fi, x.se + y.se);
}
pii sub(pii x, pii y) {
	return pii(x.fi - y.fi, x.se - y.se);
}
struct BIT {
	pii a[N];
	void init() {
		memset(a, 0, sizeof a);
	}
	void update(int x, int s, int t) {
		for (; x < N; x += x & -x) {
			a[x] = add(a[x], pii(s, t));
		}
	}
	pii query(int x) {
		pii res = pii(0, 0);
		for (; x > 0; x -= x & -x) {
			res = add(res, a[x]);
		}
		return res;
	}
	pii query(int l, int r) {
		return sub(query(r), query(l - 1));
	}
}bit;

pii query(int u, int v) {
	pii res = pii(0, 0);
	while (top[u] != top[v]) {
		if (deep[top[u]] < deep[top[v]]) swap(u, v);
		res = add(res, bit.query(in[top[u]], in[u]));
		u = fa[top[u]];	
	}
	if (u == v) return res;
	if (deep[u] > deep[v]) swap(u, v);
	return add(res, bit.query(in[son[u]], in[v]));
}

void init() {
	bit.init();
	cnt = 0; dis[1] = 0; fa[1] = 0;
	E.clear(); E.resize(n + 1);
	Q.clear(); Q.resize(n + 1);
	G.clear(); G.resize(n + 1);
	memset(son, -1, sizeof son);
	memset(res, 0, sizeof res);
}
int main() {
	while (scanf("%d%d", &n, &q) != EOF) {
		init();
		for (int i = 1, u, v, c, d; i < n; ++i) {
			scanf("%d%d%d%d", &u, &v, &c, &d);
			G[u].push_back(node(v, d));
			G[v].push_back(node(u, d));
			E[c].push_back(node(u, v, d));
		}
		for (int i = 1, c, u, v, w; i <= q; ++i) {
			scanf("%d%d%d%d", &c, &w, &u, &v);
			Q[c].push_back(node(u, v, w, i));
		}
		DFS(1); gettop(1, 1);
	//	for (int i = 1; i <= n; ++i) printf("%d %d %d %d\n", i, fa[i], son[i], in[i]);
		for (int i = 1; i < n; ++i) {
			if (Q[i].empty()) continue;
			for (auto &it : E[i]) {
				if (fa[it.u] == it.v) swap(it.u, it.v);
				bit.update(in[it.v], 1, it.w);
			}
			for (auto it : Q[i]) {
				int u = it.u, v = it.v, w = it.w, id = it.id;
				int lca = querylca(u, v); 
			//	cout << u << " " << v << " " << lca << endl;
				pii tmp = query(u, v);
				res[id] = dis[u] + dis[v] - 2 * dis[lca] - tmp.se + w * tmp.fi;
			}
			for (auto it : E[i]) {
				bit.update(in[it.v], -1, -it.w);
			}
		}
		for (int i = 1; i <= q; ++i) printf("%d\n", res[i]);
	}
	return 0;
}


Measured memory_bytes: 25716
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int INF = 1000000000 + 8;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

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

    // dp[i][j]: 魔法iまで見たとき ダメージj以上を与えるのに必要な最小の魔力
    vector<vector<int>> dp(n + 1, vector<int>(h + 1, INF));
    dp[0][0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= h; j++)
        {
            // 魔法使った 使わなかった
            if (j - a[i] >= 0)
                dp[i + 1][j] = min(dp[i + 1][j - a[i]] + b[i], dp[i][j]);
            else
            {
                dp[i + 1][j] = min(dp[i + 1][0] + b[i], dp[i][j]);
            }
        }
    }

    cout << dp[n][h] << endl;
}


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

int main()
{
  int n, h, w;
  cin >> n >> h >> w;
  int ans = 0;
  for (auto i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a >= h && b >= w) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

  int ok = false;
  int start = 1;
  for(int i = 2; i <= 10000; i++){
    if(N == start){
      ok = true;
      break;
    }
    if(N < start){
      break;
    }
    start += i;
  }

  if(ok){

    int num = 1;
    vector<vector<int>> ans(2);
    ans[0].push_back(1);
    ans[1].push_back(1);
    for(int i = 2; i < 10000; i++){
      if(num==N){
        break;
      }
      ans.push_back({});
      int ind = 0;
      for(int j = num+1; j <= num + i; j++){
        ans[ind].push_back(j);
        ans[i].push_back(j);
        ind++;
      }
      num += i;
    }

    cout << "Yes" << endl;
    cout << ans.size() << endl;
    rep(i, ans.size()){
      cout << ans[i].size() << " ";
      rep(j, ans[i].size()){
        cout << ans[i][j] << " ";
      }
      cout << endl;
    }

  }else{

    cout << "No" << endl;
  }



  return 0;
}


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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
using Graph = vector<vector<char>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}
//各々のマスは一回のみ操作できる
//偶数枚のマスがmaxになるような操作を出力
//元々奇数のマス目のコインを、他の元々奇数のマス目に写す

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  /*同じ数字のカードが２枚以上あるものの枚数をカウントしつつ、
  奇数枚なら１枚に、偶数枚なら２枚にする 奇数枚のものをansにカウント
  */
 int c = 1;
 int even = 0;//偶数枚のものの数
 int odd = 0;//奇数枚 = 1枚のもの数
 int ans = 0;

 A.push_back(-1);
 rep(i,N){
   if(A[i] == A[i+1]) c++;
   else {
     if(c%2 == 0){
      even++;
      c = 1;
     }
     else if(c%2 == 1) {
      odd++;
      c = 1;
     }
   }
 }
 if(even%2 == 0){
   ans = even + odd;
 }
 else if(even%2 == 1){
   ans = even + odd -1;
 }
 cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

set<int>history;

int main() {
	int s; cin >> s;
	int cur = 1;
	while (true) {
		if (cur == 1) {

		}
		else if (s % 2 == 0) {
			s = s / 2;
		}
		else {
			s = 3 * s + 1;
		}
		if (history.count(s) == 1) {
			print(cur);
			return 0;
		}
		history.insert(s);
		cur++;
	}

	return 0;
}


Measured memory_bytes: 256
N = input()
A = input().split()

flag = True
for a in A:
  a = int(a)
  if a % 2 == 0:
    if a % 3 == 0 or a % 5 ==0:
      pass
    else:
      flag = False
if flag:
  print('APPROVED')
else:
  print('DENIED')


Measured memory_bytes: 2940
#include <stdio.h>

int main(void) {

  int h,w;
  scanf("%d %d", &h, &w);
  int c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%d", &c[i][j]);
    }
  }
  int a[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int flag;
  while (1) {
    flag = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (c[i][k]+c[k][j] < c[i][j]) {
            c[i][j] = c[i][k]+c[k][j];
            flag = 1;
          }
        }
      }
    }
    if (flag == 0) {
      break;
    }
  }
  long magic = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] != -1 && a[i][j] != 1) {
        magic += c[a[i][j]][1];
      }
    }
  }
  printf("%ld\n", magic);

  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int ans = 0;
    REP(i,3){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256