akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double ans = 0;
        for(int i = 0; i < n; i++) ans += 1 / Double.parseDouble(sc.next());
        ans = 1 / ans;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int a[100001];
    cin >> N;
    int dpl[100001],dpr[100001];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    dpl[0] = a[0];
    dpr[N-1] = a[N-1];
    for (int i = 1; i < N - 1; i++){
       dpl[i] = __gcd(dpl[i-1],a[i]);
       dpr[N-i-1] = __gcd(dpr[N-i],a[N-i-1]);
    }
    int ans = 1;
    for (int i = 1; i < N - 1; i++){
        ans = max(ans,__gcd(dpl[i-1],dpr[i+1]));
    }
    ans = max({ans,dpl[N-2],dpr[1]});
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
N, M = map(int, input().split())
PY = [list(map(int, input().split())) + [i] for i in range(M)]

PY.sort(key=lambda x: (x[0], x[1]))

prev_p, i = PY[0][0], PY[0][2]
out = [None] * len(PY)
out[i] = str(prev_p).zfill(6) + str(1).zfill(6)

cnt = 1
for p, y, idx in PY[1:]:
    if p != prev_p:
        cnt = 0

    cnt += 1
    prev_p = p
    out[idx] = str(p).zfill(6) + str(cnt).zfill(6)


for x in out:
    print(x)


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

int main()
{
	int k, n, dp=0;
	cin >> k >> n;
	vector<int> a(n);
	for (int i=0; i<n; i++) cin >> a.at(i);
	for (int i=0; i<n-1; i++) {
		dp = max(dp, abs(a.at(i+1) - a.at(i)));
	}
	dp = max(dp, k + a.at(0) - a.at(n-1));
	cout << k - dp << endl;
}

Measured memory_bytes: 1024
c = %{.,!? abc def ghi jkl mno pqrs tuv wxyz}.split
c[0] += ' '
gets.to_i.times do
  arr = []
  gets.chomp.split('').push('/').each_cons(2).reduce(1) do |t, (a, b)|
    if a != b
      arr << [a.to_i, t]
      t = 1
    else t += 1
    end
  end
  arr.each{|a, b| print c[a-1][(b - 1) % (c[a-1].size)] if a != 0 }
  puts
end

Measured memory_bytes: 8796
#include <iostream>
#include <numeric>

using namespace std;

long long gcd(long long c, long long d) {
  while (c != d) {
	if (d > c) {
      swap(c, d);
    }
    
    long long x = c % d;
    if (x == 0) {
      break;
    }
    
    c = x;
  }
  
  return d;
}

long long lcm(long long c, long long d) {
  return c / gcd(c, d) * d;
}

long long not_devide(long long n, long long c, long long d) {
  long long x,y,z;
  x = n / (lcm(c, d));
  y = n / c;
  z = n / d;
  
  return n - y - z + x;
}

int main() {
  long long a,b,c,d;
  
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  
  cout << (not_devide(b, c, d) - not_devide((a-1), c, d)) << endl;
}

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

int main()
{
  int n,i;
  cin>>n;
  int array[n];
  for(i=0;i<n;i++)
    cin>>array[i];
  int max1 = 0;
  int max2 = 0;
  
  for(int i=0;i<n;i++)
  {
    if (array[i]>=max1)
	{
		max2=max1;
		max1=array[i];
	}
	
	else if (array[i]>max2 && array[i]<max1)
	{
		max2=array[i];
	}
  }
  
  for(int i=0;i<n;i++)
  {
	  if(array[i]==max1)
		  cout<<max2<<endl;
	  else
		  cout<<max1<<endl;
  }
}

Measured memory_bytes: 2432
using System;

namespace TestSpace
{
    class Test
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++) 
            {
                for (int j = 1; j < 10; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        }
    }
}



Measured memory_bytes: 15796
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

vector<int> divisor(int x){
    vector<int> res;
    for(int i = 1; (ll)i * i <= x; ++i){
        if(x % i == 0){
            res.push_back(i);
            if(i * i != x)  res.push_back(x / i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

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

    int x;
    cin >> x;
    vector<int> div = divisor(x);
    int sz = div.size();

    for(int i = 0; i < sz; ++i){
        for(ll a = max(-1000, -x); a <= min(1000, x); ++a){
            ll b = a - div[i];
            ll sum = a * a * a * a + a * a * a * b + a * a * b * b;
            sum += a * b * b * b + b * b * b * b;
            if(sum == x / div[i]){
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1000000007;//1e9 + 7;

int main(){
    ll ans=0;
    ll n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    bool w[101010]={};
    ll K=0;
    rep(i,n){
        if(i>=k)K=k;
        switch(t[i]){
            case 'r':
                if(!(w[i-K]&&t[i-K]==t[i])){
                    ans+=p;
                    w[i]=1;
                }
                break;
            case 's':
                if(!(w[i-K]&&t[i-K]==t[i])){
                    ans+=r;
                    w[i]=1;
                }
                break;
            case 'p':
                if(!(w[i-K]&&t[i-K]==t[i])){
                    ans+=s;
                    w[i]=1;
                }
                break;
                
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    X = int(input().strip())
    if X==1:
        print(1)
        return
    ans=0
    for i in range(2,32):
        for j in range(2,100000):
            if i**j>X:
                break
            else:
                ans=max(ans,i**j)
    print(ans)


if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  int N;
  int M;
  cin >> N >> M;
  
  int all_date=0;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
   cin >> A.at(i);
    all_date+=A.at(i);
  }
  
  int remaining_date=N-all_date;
  if (remaining_date>=0) {
    cout << remaining_date << endl;
  } else {
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 7164
#include <bits/stdc++.h>
using namespace std;
/*******************??????********************/
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {//??????
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {//??????
	return real(conj(a)*b);
}

struct L : public vector<P> {//??????
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};

typedef vector<P> G;
struct C {//???
	P p; double r;
	C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {//??????????????????
	b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L& l,const L& m){
	//non-parallel || sameline
	return abs(cross(l[1]-l[0],m[1]-m[0])) > EPS || abs(cross(l[1]-l[0],m[0]-l[0])) < EPS;
}
bool intersectLS(const L& l,const L& s){
	// s[0] is left of l,s[1] is right of l
	return cross(l[1]-l[0],s[0]-l[0]) * cross(l[1]-l[0],s[1]-l[0]) < EPS;
}
bool intersectLP(const L& l,const P& p){
	return abs(cross(l[1]-p,l[0]-p)) < EPS;
}
bool intersectSP(const L& s,const P& p){
	return abs(s[0]-p)+abs(s[1]-p) - abs(s[1]-s[0]) < EPS;// triangle inequality
}

P projection(const L& l,const P& p){
	double t = dot(p-l[0],l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}
P reflection(const L& l,const P& p){
	return p + 2. * (projection(l,p) - p);
}
double distanceLP(const L& l,const P& p){
	return abs(p - projection(l,p));
}
double distanceLL(const L& l,const L& m){
	return intersectLL(l,m) ? 0 : distanceLP(l,m[0]);
}
double distanceLS(const L& l,const L& s){
	if(intersectLS(l,s)) return 0;
	return min(distanceLP(l, s[0]),distanceLP(l, s[1]));
}

int main(void){
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	P p0(x1,y1),p1(x2,y2);

	int q;
	cin >> q;
	for(int i=0;i<q;i++){
		int x,y;cin >> x >> y;
		P p2(x,y);
		L l(p0,p1);
		int cw = ccw(p2,p0,p1);
		if(cw == 1)cout << "COUNTER_CLOCKWISE" << endl;
		else if(cw == -1)cout << "CLOCKWISE" << endl;
		else if(intersectSP(l,p2))cout << "ON_SEGMENT" << endl;
		else if(cw == -2)cout << "ONLINE_BACK" << endl;
		else cout << "ONLINE_FRONT" << endl;
	}

	return 0;
}

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

int main() {
	// your code goes here
	int n,m,c,i,j,a[30],b[30],ans=0; cin >> n >> m >> c;
	for(i=1;i<=m;i++) cin >> b[i];
	for(i=1;i<=n;i++){
		int sum=0;
		for(j=1;j<=m;j++){
			cin >> a[j];
			sum+=a[j]*b[j];
		}
		if(sum+c>0) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	string* sa=new string[n+1];
	string* sz=new string[n+1];
	for(int i=0;i<n;i++){
		cin>>sa[i];
		sz[i]=sa[i];
		for(int j=0;j<sa[i].size();j++){
			if(sa[i][j]=='?'){
				sa[i][j]='a';
				sz[i][j]='z';	
			}
		}
		
	}

	string t;
	cin>>t;
	
	sa[n]=sz[n]=t;
	sort(sa,sa+n+1);
	sort(sz,sz+n+1);
	int pre=lower_bound(sz,sz+n+1,t)-sz+1;
	int post=upper_bound(sa,sa+n+1,t)-sa;
	for(int i=pre;i<post;i++){
		cout<<i<<" ";
	}
	cout<<post<<endl;
}

Measured memory_bytes: 1408
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] A = new int[N];
        HashMap<Integer, Integer> map = new HashMap<>();
        ArrayList<Integer> list = new ArrayList<>();

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            if(map.containsKey(A[i])){
                map.put(A[i], map.get(A[i]) + 1);
            }
            else{
                map.put(A[i], 1);
                list.add(A[i]);
            }
        }

        Collections.sort(list, Collections.reverseOrder());
        int[] x = new int[2];
        x[0] = 0;
        x[1] = 0;
        int k = 0;
        long ans = 0;
        for(int i : list){
            if(map.get(i)>=2){
                x[k] = i;
                if(k==0){
                    k++;
                }
            }
            if(map.get(i)>=4 && x[k]==0){
                x[k] = i;
            }
            if(x[1]!=0){
                break;
            }
        }
        System.out.println((long)x[0] * x[1]);
    }
}

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

int main() {
  int N;
  std::cin >> N;
  std::vector<int> t(N + 1, 0);
  std::vector<int> x(N + 1, 0);
  std::vector<int> y(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    std::cin >> t[i+1] >> x[i+1] >> y[i+1];
  }

  bool success = true;
  for (int i = 0; i < N; ++i) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) success = false;
    if (dist % 2 != dt % 2) success = false;
  }

  if (success) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

struct state {
  int cost, use, pos;
  state(int c, int u, int p) : cost(c), use(u), pos(p){}
};

vector<int> bfs(vector<vector<pair<int, bool>>>& G, int s, int t, int& shortestLen) {
  vector<int> dist(G.size(), inf), d2cnt(G.size()+1);
  dist[s] = 0;

  queue<state> q;
  q.emplace(0, 0, s);

  while(!q.empty()) {
    const state s = q.front(); q.pop();
    d2cnt[s.cost]++;
    for(auto& e: G[s.pos]) {
      const int next = e.first;
      if(dist[next] > s.cost + 1) {
        dist[next] = s.cost + 1;
        q.emplace(dist[next], 0, next);
      }
    }
  }

  shortestLen = dist[t];
  return move(d2cnt);
}

int main() {

  int N, M, s, t; cin >> N >> M >> s >> t; s--, t--;
  vector<vector<pair<int, bool>>> G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    G[x-1].emplace_back(y-1, false);
    G[y-1].emplace_back(x-1, false);
  }

  int shortestLen;
  auto d2cnt1 = bfs(G, s, t, shortestLen);
  auto d2cnt2 = bfs(G, t, s, shortestLen);

  ll ans = 0;

  rep(i, N) {
    if(shortestLen-i-2 >= 0)
      ans += (ll)d2cnt1[i] * d2cnt2[shortestLen-i-2];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;
ll max(ll x,ll y){if(x>y)return x;return y;}
ll min(ll x,ll y){if(x<y)return x;return y;}
/////////////////////////////////////////////////////////////////////////////////////////

int main()
{
  ll a,b,c;cin>>a>>b>>c;
  string res;
  if(a+b+c>21)res="bust";
  else res="win";
  cout<<res<<endl;
  return 0;
}

//cout<<setprecision(20)<<2*sum/n<<endl;


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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
        }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <string.h>
using namespace std;

int main()
{
  int d = 0;
  int t = 0;
  int s = 0;
  scanf("%d %d %d", &d, &t, &s);
  if(d <= t * s){
    printf("Yes");
  }else{
    printf("No");
  }
}


Measured memory_bytes: 3820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		boolean isContainsWidth = false;
		boolean isContainsHeight = false;

		if ((x - r) >= 0 && (x + r) <= W)
			isContainsWidth = true;

		if ((y - r) >= 0 && (y + r <= H))
			isContainsHeight = true;

		if (isContainsWidth && isContainsHeight) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

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

uint64_t dfs(const vector<uint64_t>& a, vector<vector<uint64_t>>& dp, const uint32_t l, const uint32_t r){
	if(dp[l][r] != 0) return dp[l][r];

	if(l == r) {
		dp[l][r] = a[l];
		return dp[l][r];
	}
		
	uint64_t ans = UINT64_MAX;
	
	for(uint32_t d=l; d<r; d++) ans = min(ans, dfs(a, dp, l, d) + dfs(a, dp, d+1, r));
	
	//cout << l << "-" << r << ":" << ans << endl;
	dp[l][r] = ans + accumulate(a.begin() + l, a.begin() + r + 1, (uint64_t)0);
	return dp[l][r];
}


int main() {
	uint32_t N;
	cin >> N;
	
	vector<uint64_t> a(N);
	uint64_t asum = 0;
	
	for(uint32_t i=0; i<N; i++) {
		cin >> a[i];
		asum += a[i];
	}
	
	vector<vector<uint64_t>> dp(N, vector<uint64_t>(N));
		
	cout << dfs(a, dp, 0, N-1) - asum;
	return 0;
}

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

int main(){
    // vector<vector<int>> a(3,vector<int>(3));
    int a[3][3];
    int d[3][3];
    int n;
    rep(i,3)rep(j,3)cin >> a[i][j];
    cin >> n;
    bool ans = false;
    rep(i,n){
        int k; 
        cin >> k;
        rep(j,3)rep(l,3){
            if(a[j][l]==k){
                d[j][l]=1;
            }
        }        
    }
    
    rep(i,3){
        if(d[0][i]==1 && d[1][i]==1 && d[2][i]==1)ans=true;
    }
    
    rep(i,3){
        if(d[i][0]==1 && d[i][1]==1 && d[i][2]==1)ans=true;
    }
    
    if(d[1][1]==1&&d[2][2]==1&& d[0][0]==1)ans = true;
    if(d[2][0]==1&&d[1][1]==1&& d[0][2]==1)ans = true;
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s0 = [list(str(input())) for i in range(n)]
s1 = []
t = []
p = ""
for i in range(n):
    s1 = s1 + s0[i]
s2 = list(set(s1))
s2.sort()
for i in range(len(s2)):
    r = []
    for j in range(n):
        r.append(s0[j].count(s2[i]))
    t.append(min(r))
for i in range(len(s2)):
    p = p + s2[i] * t[i]

print(p)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N,Z,W; cin >> N >> Z >> W;
  vector<ll> a(N);
  REP(i,N) cin >> a[i];
  if(N==1){
    cout << abs(a[0]-W) << endl;
    return 0;
  }

  cout << max(abs(a[N-1]-a[N-2]), abs(a[N-1]-W)) << endl;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
    int N;
    cin >> N;
    vector<string>S(N);
    vector<int>A(N);
    REP(i, N){
        cin >> S.at(i) >> A.at(i);
    }
    string X;
    cin >> X;
    bool flag = false;
    ll ans = 0;
    REP(i, N){
        if(flag) ans += A.at(i);
        if(S.at(i) == X) flag = true;
    }
    print(ans);
}



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


int h,w;
	char arr[2000][2000];
	int  ans[2000][2000];
int main(){
	cin>>h>>w;

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>arr[i][j];
		}
	}
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			ans[i][j]=0;
		}
	}
	ans[1][1]=1;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(arr[i][j]=='.')
				ans[i][j]+=(ans[i-1][j]%1000000007+ans[i][j-1]%1000000007)%1000000007;
		}
	}
	cout<<ans[h][w]%1000000007;
}


Measured memory_bytes: 12544
# https://atcoder.jp/contests/abc054/tasks/abc054_b

n, m = gets.split.map(&:to_i)

img = []
tmpl = []


n.times do
  row = gets.chomp.split('')
  img << row
end

m.times do
  row = gets.chomp.split('')
  tmpl << row
end

matched = false
n.times do |i|
  n.times do |j|
    current = img[i][j]
    if current == tmpl[0][0]
      matched = true
      m.times do |x|
        m.times do |y|
          scan_current_x = i + x
          scan_current_y = j + y
          if scan_current_x >= n || scan_current_y >= n
            matched = false
            break
          end
          scan_img_current = img[scan_current_x][scan_current_y]
          scan_tmpl_current = tmpl[x][y]
          unless scan_img_current == scan_tmpl_current
            # puts "(#{scan_current_x}, #{scan_current_y})(#{scan_img_current}) != template(#{x}, #{y})"
            matched = false
            break
          end
        end
        break unless matched
      end
    end
    break if matched
  end
  break if matched
end
puts matched ? "Yes" : "No"

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL way[3003], way2[3003][3003];
LL C[3003][3003], f[3003][3003];

LL qpow(LL a, LL b, LL mod) {
    LL ret = 1LL;
    while (b) {
        if (b & 1) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}

LL pow_mod[3003], pow_mod_1[3003];
int main() {
    LL N, mod;
    scanf("%lld %lld", &N, &mod);
    pow_mod[0] = pow_mod_1[0] = 1;
    for(int i = 1; i < 3003; ++i) pow_mod[i] = pow_mod[i-1] * 2 % mod;
    for(int i = 1; i < 3003; ++i) pow_mod_1[i] = pow_mod_1[i-1] * 2 % (mod - 1);

    for (int i = 0; i < 3003; ++i) C[i][0] = C[i][i] = 1;
    for (int i = 2; i < 3003; ++i)
        for (int j = 1; j < i; ++j)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;

    f[0][0] = f[1][0] = f[1][1] = 1;
    for (int i = 2; i <= N; ++i) {
        f[i][0] = 1;
        for (int j = 1; j <= N; ++j) {
            f[i][j] = (f[i - 1][j] + f[i - 1][j] * j + f[i - 1][j - 1]) % mod;
        }
    }

    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= i; ++j) {
            way2[i][j] = f[i][j] * qpow(pow_mod[N - i], j, mod) % mod * qpow(2, pow_mod_1[N - i], mod) % mod;
            way[i] = (way[i] + way2[i][j]) % mod;
        }
    }

    LL ans = 0;
    for(int i = 0; i <= N; ++i){
        if(i % 2 == 0) ans = (ans + C[N][i] * way[i]) % mod;
        else ans = (ans - C[N][i] * way[i] % mod + mod) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 211584
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> v;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    v.push_back(make_pair(b,a));
  }
  sort(v.begin(),v.end());
  int h[n+1]={};
  h[v[0].first-1]=1;
  int l=v[0].first-1;
  for(int i=1;i<m;i++){
    if(v[i].second>l){
      h[v[i].first-1]=1;
      l=v[i].first-1;
    }
  }
  int sum=0;
  for(int i=0;i<=n;i++){
    sum+=h[i];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 1524
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    for(int i = 0; i < s.length(); i++){
      s = s.charAt(s.length() - 1) + s.substring(0, s.length()-1);
      if(s.equals(t)){
        System.out.println("Yes");
        System.exit(0);
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <iostream>
#include <string>
using namespace std;

int check(long long a, long long b, int X){
	return ( pow(a, 5) - pow(b, 5) - X) ;
}

int main(int argc, char* argv[]){
	long long X;

	cin >> X;

	long long a=0, b=0;
	double u, v;
	while(true){
		if(a==0){
			u = 0 - X;
		}
		else{
			u = pow((double)a, 5) - X ;
		}
		if(u<0){
			v = pow(0-u, 0.2);
			b = (long long)(0-v);
		}
		else{
			v = pow(u, 0.2);
			b = (long long)v;
		}
		int ret = check(a, b, X);
		if(ret==0) break;
		a++;
	}
	printf("%lld %lld\n", a, b);
	return 0;

}


Measured memory_bytes: 4152
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll n,i;
    cin>>n;
    ll ans=n+1,tp;
    for (i=0;i<=n;i++)
    {
        tp=0;
        ll k=i;
        while (k)
        {
            tp+=k%6;
            k/=6;
        }
        k=n-i;
        while (k)
        {
            tp+=k%9;
            k/=9;
        }
        ans=min(ans,tp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef pair<long long int, int> P;
vector<P> PF(long long int n){
	vector<P> vec;
	long long int np=n,count;
	for(long long int i=2;i<=np/i;i++){
		if(n%i!=0)continue;
		count=0;
		while(n%i==0){n/=i;count++;}
		vec.push_back(P(i,count));
	}
	if(n>1)vec.push_back(P(n,1));
	return vec;
}
int main(){
	long long int N,ans=0;
	vector<P> vec;
	cin>>N;
	vec = PF(N);
	for(P p:vec){
		for(int i=1;p.second-i>=0;i++){
			ans++;
			p.second-=i;
		}
	}
	cout<<ans;
	return 0;
}

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

void solve(int n, int l, int r) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int now_a = l; now_a <= r; now_a++) {
        bool is_ok = true;
        bool is_continue = true;
        for (int i = 0; i < n; i++) {
            if (now_a % a[i] == 0 && i % 2) {
                is_ok = false;
                break;
            }
            else if (now_a % a[i] == 0 && i % 2 == 0) {
                is_continue = false;
                break;
            }
        }
        if (!is_ok) continue;
        if (!is_continue) {
            ans++;
            continue;
        }
        if (n % 2 == 0) ans++;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, L, R;
    while (true) {
        cin >> N >> L >> R;
        if (N == 0 && L == 0 && R == 0) break;
        solve(N, L, R);
    }
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vector<int> H(N+1);
    for (int i = 1; i <= N; ++i) {
        cin >> H[i];
    }
    unordered_set<int> notgood;
    for (int i = 0; i < M; ++i) {
        int A,B;
        cin >> A >> B;
        if (H[A] < H[B]) {
            notgood.insert(A);
        } else if (H[A] > H[B]){
            notgood.insert(B);
        } else {
            notgood.insert(A);
            notgood.insert(B);
        }
    }
    cout << N - notgood.size() << endl;
}



Measured memory_bytes: 5996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////




int main(){
    
    ll n;cin>>n;
    ll a[n][3];rep(i,0,n-1)rep(j,0,2)cin>>a[i][j];
    ll dp[n][3];rep(i,0,n-1)rep(j,0,2)dp[i][j]=0;
    rep(j,0,2)dp[0][j]=a[0][j];
    rep(i,1,n-1){
        rep(j,0,2){
            rep(k,0,2){
                if(j==k)continue;
                Max(&dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }
    }
    ll ans=0;
    rep(i,0,2)ans=max(ans,dp[n-1][i]);
    cout<<ans<<endl;
    
    return 0;
}




Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
    
    int N,i,j,d[51];
    
    long long int sum=0;
    
    scanf("%d",&N);
    
    for(i=0; i<N; i++){
        scanf("%d",&d[i]);
    }
    
    for(i=0; i<N; i++){
        for(j=i; j<N; j++){
            if(i != j){
                sum += d[i]*d[j];
            }
        }
    }
    
    
    printf("%lld\n",sum);
        
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100005;

int n, q, k;
vector<pair<ll, ll>> conn[N];

ll dist[N];

void dfs(int v, int p) {
    for (auto& u : conn[v]) {
        if (u.first != p) {
            dist[u.first] = dist[v] + u.second;
            dfs(u.first, v);
        }
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        conn[a].push_back({b, c});
        conn[b].push_back({a, c});
    }

    cin >> q >> k;
    --k;
    dfs(k, -1);
    
    for (int qi = 0; qi < q; qi++) {
        int i, j;
        cin >> i >> j;
        --i; --j;
        cout << dist[i] + dist[j] << '\n';
    }
}



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

int main(){
	string s;
	cin>>s;
	string sarr[1000];
	int index=0;
	while(s!="-"){
		int m;
		cin>>m;
		int h;
		for(int i=0;i<m;++i){
			cin>>h;
			s=s.substr(h,s.length())+s.substr(0,h);
		}
		sarr[index]=s;
		index++;
		cin>>s;
	}
	for(int j=0;j<index;++j){
		cout<<sarr[j]<<endl;
	}
}


Measured memory_bytes: 3152
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;


int main() {


	int n;

	int w[101];

	int s1=0, s2=0;
	int temp = 100000000;
	cin >> n;

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

	for (int i = 0; i < n-1; i++) {
		s1 += w[i];
		s2 = 0;

		
		for (int j = i+1; j < n; j++) {
			s2 += w[j];
		}

		temp = min(temp, abs(s1-s2));
	}

	cout << temp << endl;
	
	

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

vector<int> res, tmp;
vector<vector<int>> bra;

void dfs(int par, int now);

int main(){
    int n, q;
    cin >> n >> q;
    rep(i, n){
        res.push_back(0);
        bra.push_back(tmp);
    }
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        bra[a-1].push_back(b-1);
        bra[b-1].push_back(a-1);
    }
    rep(i, q){
        int p, x;
        cin >> p >> x;
        res[p-1] += x;
    }

    dfs(-1, 0);

    rep(i, n){
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

void dfs(int par, int now){
    int len = bra[now].size();
    if(par!=-1){
        res[now] += res[par];
    }
    rep(i, len) {
      if (bra[now][i] != par) {
        dfs(now, bra[now][i]);
      }
    }
    return;
}

Measured memory_bytes: 24356
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        long l = scanner.nextInt();
        long r = scanner.nextInt();
        if (l / 2019 != r / 2019) {
            System.out.println(0);
        } else {
            l %= 2019;
            r %= 2019;
            if (l > r) {
                long t = l;
                l = r;
                r = t;
            }
            long min = Long.MAX_VALUE;
            for (long i = l; i <= r; i++) {
                for (long j = i + 1; j <= r; j++) {
                    min = Math.min(min, i * j % 2019);
                }
            }
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int left = 0;
    int right = N - 1;
    System.out.println(0);
    char t1 = scanner.next().charAt(0);
    if (t1 == 'V') return;
    System.out.println(N - 1);
    char t2 = scanner.next().charAt(0);
    if (t2 == 'V') return;
    while (right - left > 1) {
      int mid = (right + left) / 2;
      System.out.println(mid);
      char r = scanner.next().charAt(0);
      if (r == 'V') return;
      if ((mid % 2 == 0 && r == t1) || (mid % 2 == 1 && r == t2)) {
        left = mid;
      } else {
        right = mid;
      }
    }
  }
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  string s; cin>>s;
  string t = s;
  reverse(t.begin(), t.end());
  if (t == s) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3616
s=input()
res=[]
for i in s:
	#print(i)
	if i=='0':
		res+=i
		#print(res)
	elif i=='1':
		res+=i
		#print(res)
	else:
		if res!=[]:
			res.pop(len(res)-1)
		#print(res)
print(''.join(res))

Measured memory_bytes: 3060
N = int(input())
B = list(map(int,input().split(" ")))

o = []
for i in range(N):
    for j in range(N-i-1,-1,-1):
        if j+1 == B[j]:
            o.append(B[j])
            B.pop(j)
            break

if len(B) != 0:
    print("-1")
else:
    print("\n".join(map(str,o[::-1])))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int a,b,c;
    int x,y;
    cin>>a>>b>>c>>x>>y;
    ll minn_1=a*x+b*y;
    ll cx=2*x;
    ll cy=2*y;
    ll maxn=max(cx,cy);
    ll minn=min(cx,cy);
    ll minn_2=c*maxn;
    ll minn_3=c*minn;
    if(x<y)
        minn_3+=(y-x)*b;
    else if(x>y)
        minn_3+=(x-y)*a;
    ll res=min(minn_1,min(minn_2,minn_3));
    cout<<res<<endl;
    return 0;
}

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

bool check(int n) {
  int count=0;
  if (n % 2 == 0) return false;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) count++;
  }
  if (count == 8) return true;
  else
    return false;
}

int main() {
  int n, out=0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (check(i) == true) out++;
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    cout<<"x";
    
    
    
    return 0;
}


    
    
    
    
    
    
    
    

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in a:
    dic[i] += 1

t = sorted(set(a), reverse=True)
rec = []
flag = False
for k in t:
    if dic[k] >= 4 and len(rec) == 1:
        print(k * rec[0])
        flag = True
        break
    elif dic[k] >= 4:
        print(k * k)
        flag = True
        break
    elif dic[k] >= 2 and len(rec) == 1:
        print(k * rec[0])
        flag = True
        break
    elif dic[k] >= 2:
        rec.append(k)

if not flag:
    print(0)

Measured memory_bytes: 20772
#include<iostream>
#include<algorithm>
using namespace std;
int A[200001];

int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++)
		cin >> A[i];

	for (int i = 1; i <= N; i++)
		A[i] -= i;

	sort(A + 1, A + N + 1);

	int b = A[N / 2 + 1];
	
	long long sum = 0;
	for (int i = 1; i <= N; i++)
		sum += abs(A[i] - b);

	cout << sum << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '1')
                ans += "9";
            else
                ans += "1";
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 22740
n,k = map(int, input().split(" "))
s = list(input())

if s[0] == "0":
    s_num = [0]
else:
    s_num = []
pre = s[0]
num = 0

for i in s:
    if pre == i:
        num += 1
    else:
        s_num.append(num)
        num = 1
        pre = "1" if pre == "0" else "0"
else:
    s_num.append(num)

sums = [0]

for i,e in enumerate(s_num):
    sums.append(sums[i] + e)

ret = 0
sums_len = len(sums)-1
for i in range(0,len(sums),2):
    ret = max(ret,(sums[min(i+k*2+1,sums_len)] - sums[i]))
 
print(ret)

Measured memory_bytes: 8616
import math
a,b,n = map(int,input().split())

x = math.floor(a*n/b)-( a*math.floor(n/b))
y = math.floor(a*b/b)-( a*math.floor(b/b))
z = math.floor(a*(b-1)/b)-( a*math.floor((b-1)/b))

if b == 1:
    print(0)
elif n < b:
    print(x)
else:
    print(z)

Measured memory_bytes: 9196
#include<cstdio>
#include<iostream>
#include <memory>
#include<vector>
#include<algorithm>
using namespace std;

int calc(int a, int b, int ope) {
	if (ope == 0) return a + b;
	else return a - b;
}

int main(void) {
	string S;
	cin >> S;
	char ope[] = {'+', '-'};
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int ans = calc(S[0] - '0', S[1] - '0', i);
				ans = calc(ans, S[2] - '0', j);
				ans = calc(ans, S[3] - '0', k);
				if (ans == 7) {
					cout << S[0] << ope[i] << S[1] << ope[j] << S[2] << ope[k] << S[3] << "=7\n";
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=0;
  cin>>N;
  vector<int> A(N-1);
  cin>>A.at(0);
  ans+=A.at(0);
  for(int i=1;i<N-1;i++){
    cin>>A.at(i);
    ans+=min(A.at(i),A.at(i-1));
  }
  ans+=A.at(N-2);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int N = 100010;
typedef pair<int,int> Point;
#define x first
#define y second
 
int n, r, c;
Point p1[N], p2[N];
vector < pair<Point, int> > vec;
 
bool inBoundary(Point a) {
	return (a.x == 0 || a.y == 0 || a.x == r || a.y == c);
}
 
long long dist(Point a, Point b) {
	return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y);
}
 
bool ccw(Point O, Point A, Point B) {
	A.x -= O.x; A.y -= O.y;
	B.x -= O.x; B.y -= O.y;
	double angleA = atan2(A.y, A.x);
	double angleB = atan2(B.y, B.x);
	if (angleA != angleB) return angleA < angleB;
	else {
		if (angleA == 0) return dist(O,A) < dist(O,B);
		else return dist(O,A) > dist(O,B);
	}
}
 
Point pivot;
 
bool cmp(Point a, Point b) {
	return ccw(pivot, a, b);
}
 
bool cmp_big(pair<Point,int> a, pair<Point,int> b) {
	return cmp(a.first, b.first);
}
 
bool in[N];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> r >> c >> n;
	int m = 1;
	for (int i = 1; i <= n; ++i) {
		cin >> p1[m].x >> p1[m].y >> p2[m].x >> p2[m].y;
		if (inBoundary(p1[m]) && inBoundary(p2[m])) {
			vec.push_back(make_pair(p1[m], m));
			vec.push_back(make_pair(p2[m], m));
			//printf("%d %d %d %d\n", p1[m].x, p1[m].y, p2[m].x, p2[m].y);
			++m;
		}
	}
	if (m == 1) return cout << "YES\n", 0;
 
 	pivot = Point(0,0);
 	sort(vec.begin(), vec.end(), cmp_big);

 	//for (auto cur : vec) printf("%d %d => %d\n", cur.first.x, cur.first.y, cur.second);

	stack <int> s;
	for (auto cur: vec) {
		int stt = cur.second;
		if (s.empty()) s.push(stt), in[stt] = 1;
		else {
			int t = s.top();
			if (t == stt) { s.pop(); in[t] = 0; continue; }
			else {
				if (in[stt]) return cout << "NO\n", 0;
				else in[stt] = 1, s.push(stt);
			}
		}
	}
 
	cout << "YES\n";
}

Measured memory_bytes: 6004
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    cnt = 0
    for _ in range(M):
        cnt += A[i][_] * B[_]
    if cnt+C > 0:
        ans += 1
print(ans)

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

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

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

    // start
    long long a, b, x, res;
    cin >> a >> b >> x;
    res = b / x - a / x;
    cout << (a % x == 0 ? res + 1 : res) << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
s = input()
p = "No"
a = 0
if len(s) % 2 == 0:
  for i in range(len(s)//2):
    if str(s[a]+s[a+1]) == "hi":
      p = "Yes"
      a = a + 2
    else:
      p = "No"
      break;
print(p)

Measured memory_bytes: 8976
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct COL{
  int n;
  string name;
};

const int c[8][3] = {{0, 0, 0}, {0, 0, 0xff}, {0, 0xff, 0}, {0, 0xff, 0xff}, {0xff, 0, 0}, {0xff, 0, 0xff}, {0xff, 0xff, 0}, {0xff, 0xff, 0xff}};

const string s[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

bool cmp(COL lhs, COL rhs)
{
  return (lhs.n < rhs.n);
}

signed main()
{
  //ios::sync_with_stdio(false);
  char sr[2], sg[2], sb[2];
  char sh;
    
  while (scanf("%1s", &sh), sh != '0'){
    COL col[8];
    scanf("%2s%2s%2s", sr, sg, sb);
    int r = strtol(sr, NULL, 16),
        g = strtol(sg, NULL, 16),
        b = strtol(sb, NULL, 16);

    REP(i, 8){
      col[i].n = (c[i][0] - r) * (c[i][0] - r) + (c[i][1] - g) * (c[i][1] - g) + (c[i][2] - b) * (c[i][2] - b);
      col[i].name = s[i];
    }

    sort(col, col + 8, cmp);
    print(col[0].name);
  }

  return (0);
}

Measured memory_bytes: 1192
#include <stdio.h>
#include <string.h>
 
int main(void)
{
  char str[25] = {0};
  int cx;

  fgets(str, sizeof(str), stdin);
  cx = strlen(str);

  for (int x=cx-2; x>=0; x--) {
    putchar(str[x]);
  }
  puts("");
 
  return 0;
}

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

int main()
{
    long long n,i,j,k;
    cin>>n;
    vector<int>a(n,0);
    for(i=0;i<n;i++)
    {
        cin>>j>>k;
        if(j==k)
            a[i]++;
    }
    k=0;
    for(i=0;i<n-2;i++)
    {
        if(a[i]&&a[i+1]&&a[i+2])
        {
            k=1;
            break;
        }
    }
    if(k)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
const int N = 3e5+5;
int a[N];
int amount[N];
int cnt[N];
long long sumValue[N];
int sumCnt[N];

//cnt[i], 第i种牌有几张
//amount[i], 数量等于i的牌有几种
//sumCnt[i], 数量小于等于i的有几种
//sumValue[i], 数量小于等于i的种类的cnt之和

//n错了
int judge(long long k,long long m,long long n){
    //printf("k = %lld, m = %lld\n",k,m);
    long long left = k-(n-sumCnt[m-1]);
    if(sumValue[m-1]>=left*m){ 
        //printf("sumValue[%d] = %lld, %lld*%lld = %lld\n",m-1,sumValue[m-1],left,m,left*m);
        //printf("Yep\n");
        return 1;
    }
    else{ 
        //printf("Nope\n");
        return 0;
    }
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        scanf("%d",&a[i]);  
        cnt[a[i]]++;
    }
    for(int i = 1; i <= n; i++) amount[cnt[i]]++;
    /*for(int i = 1; i <= n; i++){
        printf("amount[%d] = %d\n",i,amount[i]);   
    }*/
    sumCnt[0] = 0;
    for(int i = 1; i <= 300000; i++){
        sumCnt[i] = sumCnt[i-1]+amount[i];
        sumValue[i] = sumValue[i-1]+(long long)amount[i]*(long long)i;
    }
    int total = sumCnt[300000];
    for(int k = 1; k <= n; k++){
        int l = 1, r = n/k;
        int res = 0;
        while(l<=r){
            int m = (l+r)/2;
            if(judge(k,m,total)){
                res = m;
                l = m+1;
            }
            else r = m-1;
        }
        printf("%d\n",res);
    }
    return 0;
}

Measured memory_bytes: 7808
import collections

N, K = map(int,input().split())
A = list(map(int,input().split()))

cA = collections.Counter(A)

ans = 0
if len(cA) > K:
  _, counts = zip(*cA.most_common()[::-1])
  ans =sum(counts[:len(cA)-K])
else:
  ans = 0
print(ans)

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

typedef long long ll;

int n;

int main(){
    cin >> n;
    vector<int> v(n);

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

    sort(v.begin(), v.end());

    int sum = 0;

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

    sum += v[n-1] / 2;

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; int Q; 
	cin >> N >> Q; 
	long long black = (long long) N * N - N * 4 + 4; 
	int H[200010] = {}; 
	int V[200010] = {}; 
	int MH = N; int MV = N; 
	while(Q--){
		int t, x; cin >> t >> x; 
		if(t == 1){
			if(x > MV) black -= V[x] - 2; 
			else black -= MH - 2; 
			if(x < MV){
				for(int i = x; i < MV; i++) V[i] = MH; 
				MV = x; 
			}
		}
		if(t == 2){
			if(x > MH) black -= H[x] - 2; 
			else black -= MV - 2; 
			if(x < MH){
				for(int i = x; i < MH; i++) H[i] = MV; 
				MH = x; 
			}
		}
	}
	cout << black << "\n"; 	
}

Measured memory_bytes: 5200
n,q=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):a[i]-=1
queries=[[]for _ in range(n)]
for i in range(q):
  l,r=map(int,input().split())
  l-=1
  r-=1
  queries[r].append((l,i))
lastAppeared=[0]*n
bit=[0]*(n+1)
ans=[0]*q
for i in range(n):
  x=lastAppeared[a[i]]+1
  while x<=n+1:
    bit[x-1]-=1
    x+=x&-x
  x=i+2
  while x<=n+1:
    bit[x-1]+=1
    x+=x&-x
  lastAppeared[a[i]]=i+1
  for l,ind in queries[i]:
    x=i+2
    while x:
      ans[ind]+=bit[x-1]
      x-=x&-x
    x=l+1
    while x:
      ans[ind]-=bit[x-1]
      x-=x&-x
print(*ans)


Measured memory_bytes: 207464