akhauriyash/Code-Regression huggingface dataset:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

def main():
    N,M=MI()
    AB=LLIN(N)
    AB.sort(reverse=True)

    ans = 0
    pri_work = []
    for date in range(1,M+1):
        while AB and AB[-1][0]<=date:
            heappush(pri_work, -AB.pop()[1])
        if pri_work:    
            ans += -heappop(pri_work)
    print(ans)
            


if __name__ == '__main__':
    main()

Measured memory_bytes: 30452
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd

sys.setrecursionlimit(10**7)
N, R = map(int, input().split())

if N >= 10:
    print(R)
else:
    print(R + 100*(10-N))




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

using namespace std;

void solve();

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

void solve() {
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    int minA = a[0];
    int maxA = a[0];
    int maxA_B = b[0];
    for(int i = 0; i < n; i++) {
        if(minA > a[i]) {
            minA = a[i];
        }
        if(maxA < a[i]) {
            maxA = a[i];
            maxA_B = b[i];
        }
    }
    long long int ans = 0;
    ans += minA;
    ans += maxA - minA;
    ans += maxA_B;

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll A[20][20];
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M, X;
  cin >> N >> M >> X;
  llvec C(N);
  //vector<llvec> A;
  rep(i, N){
    cin >> C[i];
    llvec a(N);
    rep(j, M){
      cin >> A[i][j];
    }
  }
  ll ans = 1e18;
  rep(i, pow(2, N)){
    ll tmpc=0;
    llvec ab(M, 0);
    rep(j, N){
      if(i>>j & 1 == 1){
        tmpc += C[j];
        rep(k, M){
          ab[k] += A[j][k];
        }
      }
    }
    bool flg = true;
    rep(i, M){
      flg = flg and ab[i]>=X;
    }
    if(flg)ans = min(ans, tmpc);
  }

  if(ans == 1e18){
    cout << -1;
  }else{
    cout << ans;
  }
  
  return 0;
}


Measured memory_bytes: 3892
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
# from copy import deepcopy


def bfs(h, w, board, start_list, dx, dy):

    # キュー
    task_deque = deque()
    # キューにスタート地点リストを追加
    task_deque.append(start_list)
    next_task_list = deque()
    turn_count = 0

    while task_deque:
        next_task_list.clear()
        task_list = task_deque.popleft()


        # タスクリストからそれぞれの座標を取り出す
        for x, y in task_list:

            for i in range(len(dx)):
                nx = x + dx[i]
                ny = y + dy[i]

                # 条件に合う座標をnext_task_listに追加
                if 0 <= nx < w and 0 <= ny < h and board[ny][nx] == ".":
                    board[ny][nx] = "#"
                    next_task_list.append([nx, ny])


        # 一つもnext_task_listに入っていなければ終了
        if len(next_task_list) == 0:
            return turn_count

        # タスクリストが全部終わったらキューに追加
        turn_count += 1
        lst = []
        for task in next_task_list:
            lst.append(task)
        task_deque.append(lst)



h, w = map(int, input().split())
board = [list(input().rstrip()) for j in range(h)]

start_list = deque()

# すべてのスタート地点を記録
for i in range(w):
    for j in range(h):
        if board[j][i] == "#":
            start_list.append([i, j])

# dx,dy
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


print(bfs(h, w, board, start_list, dx, dy))


Measured memory_bytes: 169220
# coding: utf-8
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# ダイクストラ法、自分の部屋から行けるところの中から最小の距離の部屋
N, M = lr()
graph = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(M):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)

INF = 10 ** 15

def dijkstra(start):
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for next in graph[prev]:
            d1 = d + 1
            if dist[next] > d1:
                dist[next] = d1
                heappush(que, (d1, next))
    return dist

dist = dijkstra(1)
if INF in dist[1:]:
    print('No'); exit()

answer = [None] * (N+1)
for i in range(2, N+1):
    a = INF
    for c in graph[i]:
        if dist[c] < a:
            a = dist[c]
            answer[i] = str(c)

print('Yes')
print('\n'.join(answer[2:]))


Measured memory_bytes: 42112
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  int ans=0;
  repi(i,k+1,n+1){
    ans+=(n/i)*(i-k)+max((int)0,(n%i)-k+1);
    //cout<<ans<<endl;
  }
  if(k==0) ans=n*n;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

typedef struct pp{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue();
int head=0,teal,n;
P NAME[1000005];

int main(){

  int z,q;
  int i,total=0;
  P u;

  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",NAME[i].name,&NAME[i].t);
}


  teal=n;

  for(i=head;i!=teal;i++){
    u=dequeue();
    /*if(u.t>q){
      u.t-=q;
      total+=q;
    }
    else{
      total+=u.t;
      u.t=0;
      } */
    if(u.t>q)z=q;
    else z=u.t;
    u.t-=z;
    total+=z;
    if(u.t>0){
      enqueue(u);
    }
    else printf("%s %d\n",u.name,total);

}

  return 0;
}

void enqueue(P a){
  NAME[teal]=a;
  teal++;
}

P dequeue(){
  head++;
return NAME[head-1];

}



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

int main() {
    int N, K, S;
    cin >> N >> K >> S;

    rep(i, K) cout << S << " ";
    ll num;
    if (S > 10e6)
        num = 1;
    else
        num = 10e8;
    rep(i, N - K) cout << num << " ";
}

Measured memory_bytes: 3636
S = input()
T = input()
ans = 100000000
for i in range(len(S) - len(T)+1):
    val = 0
    #print(i)
    for j in range(len(T)):
        if S[i+j] != T[j]:
            val += 1
    ans = min(ans,val)
print(ans)


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

int main() {
  int a,b,c; cin>>a>>b>>c;
  if (b-a==c-b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 384
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int main()
{
	int a,b,c;
	std::cin >> a >> b >> c;
	if (c >= a and c <= b)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}

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

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

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int main(){
    int N, X;
    cin >> N >> X;
    create_mod_tables(6010);

    static int64_t dp[3001][6010], dp2[3001][6010];
    dp[0][0] = 1;
    dp2[0][0] = 1;
    for(int i=0; i<N; i++) for(int j=0; j<=2*N; j++){
        for(int k=0; k<=2; k++) add(dp[i+1][j+k], dp[i][j]);
        for(int k=1; k<=2; k++) add(dp2[i+1][j+k], dp2[i][j]);
    }
    int64_t ans = 0;
    for(int j=0; j<X; j++) add(ans, dp[N][j]);

    for(int y=1; X+y<=2*N; y+=2){
        if(y+1 < X-1){
            for(int n=1; n+y+1<=N; n++){
                int64_t result = dp2[n][X-y-2];
                mul(result, comb_mod(N, n+y+1));
                add(ans, result);
            }
        }else{
            if(X%2) add(ans, comb_mod(N, (X+y)/2));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 282112
from math import gcd
def lcm(a,b):
    return a//gcd(a,b)*b
def lcm(ab):
    l=len(ab)
    ret=ab[0]
    for i in range(1,l):
        ret=ret//gcd(ab[i],ret)*ab[i]
    return ret
def count2(a):
    ret=0
    while a%2==0:
        a//=2
        ret+=1
    return 2**ret
n,m=map(int,input().split())
A=list(map(int,input().split()))
if any(i%2 for i in A):
    exit(print(0))
A=[i//2 for i in A]
#全体の最小公倍数
p=lcm(A)
c=count2(p)
#2で割り切れる回数が同じでないものがある場合
#違うじゃん
if any(i%c for i in A):
    exit(print(0))
x=m//p
#print(p//c)
if x%2==0:
    print(x//2)
else:
    print(x//2+1)

Measured memory_bytes: 20712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll N,M,C;
    cin>>N>>M>>C;
    VVL a(N,VL (M,0));
    VL  b(M,0);
    rep(i,0,M)cin>>b[i];
    rep(i,0,N) rep(j,0,M)  cin>>a[i][j];

    ll ans=0;
    rep(i,0,N){
        ll tmp=0;
        rep(j,0,M){
            tmp+=b[j]*a[i][j];
        }
        tmp+=C;
        if(tmp>0)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall Educational_DP_A.cpp -o .\out\Educational_DP_A.out
.\out\Educational_DP_A.out
*/

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

typedef long long ll;

int h[100005];
int dp[100005];

constexpr int INF = 1e9;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  for (int i = 0; i <= n; ++i) {
    dp[i] = INF;
  }
  dp[0] = 0;
  for (int i = 1; i <= n - 1; ++i) {
    dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
    if (i > 1) {
      dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp[n - 1] << "\n";
//  cout << dp[n] << "\n";
}


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

int main() {
  int m1,d1,m2,d2;
  cin >> m1  >> d1 >> m2 >> d2;
  if(m1 < m2)   cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
weight, value = [0]*N, [0]*N
for i in range(N):
  weight[i], value[i] = map(int, input().split())

dp = [[-float('inf')]*(W+1) for _ in range(N+1)]
for w in range(W+1):
  dp[0][w] = 0

  
for i in range(0, N):
  for w in range(0, W+1):
    if w >= weight[i]:
      dp[i+1][w] = max(dp[i][w], dp[i][w-weight[i]]+value[i])
    else:
      dp[i+1][w] = dp[i][w]

print(dp[N][W])

Measured memory_bytes: 309768
// 15 puzzle

#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<cassert>
 
using namespace std;
 
#define N 4
#define N2 16
#define LIMIT 100
 
static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
 
int MDT[N2][N2];
 
struct Puzzle
{
  int f[N2];
  int space;
  int MD;
};
 
Puzzle state;
int limit;
int path[LIMIT];
 
int getAllMD(Puzzle pz);
bool isSolved();
bool dfs(int depth,int prev);
string iterative_deepening(Puzzle in);
 
int main(void)
{
  for(int i=0;i<N2;i++)
    {
      for(int j=0;j<N2;j++)
    {
      MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
    }
    }
     
  Puzzle in;
     
  for(int i=0;i<N2;i++)
    {
      cin>>in.f[i];
      if(in.f[i]==0)
    {
      in.f[i]=N2;
      in.space=i;
        }
    }
     
  string ans=iterative_deepening(in);
     
  cout<<ans.size()<<endl;
     
  return 0;
}
 
int getAllMD(Puzzle pz)
{
  int sum=0;
  for(int i=0;i<N2;i++)
    {
      if(pz.f[i]==N2)
    {
      continue;
    }
     
      sum+=MDT[i][pz.f[i]-1];
    }
     
  return sum;
}
 
bool isSolved()
{
  for(int i=0;i<N2;i++)
    {
      if(state.f[i]!=i+1)
    {
      return false;
    }
    }
     
  return true;
}
 
bool dfs(int depth,int prev)
{
  if(state.MD==0)
    {
      return true;
    }
     
  if(depth+state.MD>limit)
    {
      return false;
    }
     
  int sx=state.space/N;
  int sy=state.space%N;
     
  Puzzle tmp;
     
  for(int r=0;r<4;r++)
    {
      int tx=sx+dx[r];
      int ty=sy+dy[r];
     
      if(tx<0||ty<0||tx>=N||ty>=N)
    {
      continue;
    }
     
      if(max(prev,r)-min(prev,r)==2)
    {
      continue;
    }
     
      tmp=state;
     
      state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
      state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
     
      swap(state.f[tx*N+ty],state.f[sx*N+sy]);
     
      state.space=tx*N+ty;
     
      if(dfs(depth+1,r))
    {
      path[depth]=r;
      return true;
    }
     
      state = tmp;
    }
     
  return false;
}
 
string iterative_deepening(Puzzle in)
{
  in.MD=getAllMD(in);
     
  for(limit=in.MD;limit<=LIMIT;limit++)
    {
      state=in;
      if(dfs(0,-100))
    {
      string ans="";
         
      for(int i=0;i<limit;i++)
        {
          ans += dir[path[i]];
        }
         
      return ans;
        }
    }
     
  return "unsolvable";
}


Measured memory_bytes: 3216
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()
a = l()
dp = [[0,0] for i in range(2*(10**5)+1)]
po = s(sorted(a))

su = 0
for i in range(len(po)):
    dp[po[i][0]] = [po[i][1],po[i][1]*(po[i][1]-1)//2]
    su += dp[po[i][0]][1]



for i in range(n):
    ppp = dp[a[i]][1]
    print(su - ppp + (dp[a[i]][0]-1)*(dp[a[i]][0]-2)//2)




Measured memory_bytes: 117628
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	ll l,r;
	cin>>l>>r;
	if(r-l+1>=2019){ 
		cout<<0;
		return; 
	} 
	ll ans = 1e9;
	for(int i=l;i<=r;i++){
		for(int j=i+1;j<=r;j++){
			ans = min(ans,(1LL*j*i)%2019);
		}
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

//positionbit目が立っているか判定
bool contain(int mask, int position){
    if((mask & (1 << position)) != 0) return true;
    else return false;
}

int main(void){
    string s; cin >> s;
    int n = s.size() - 1;
    
    ll sum = 0;
    for(int mask = 0; mask < (1 << n); ++mask){
        int l = 0;//左端
        ll tmp = 0;
        int r;//右端
        for (r = 0; r < n; ++r){
            if(contain(mask, r)){
                string t = s.substr(l, r - l + 1);
                ll num = stoll(t);
                tmp += num;
                l = r + 1;
            }
        }
        string t = s.substr(l, r - l + 1);
        ll num = stoll(t);
        tmp += num;
        sum += tmp;
    }
    printf("%lld\n", sum);
    return 0;
}

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

using namespace std;

int main(){

    int N;
    cin >> N;

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

    sort(a, a + N, greater<int>());

    int Alice=0, Bob=0;

    for (int i=0; i<N; i++){
        if (i%2==0) Alice += a[i];
        else Bob += a[i];
    }

    cout << (Alice - Bob) << "\n";

    return 0;
}

Measured memory_bytes: 256
mod stdin_reader {
  use std::io::stdin;
  use std::io::Read;

  pub struct StdinReader {
    pub buf: Vec<String>,
    pub cursor: usize,
  }

  pub fn new() -> StdinReader {
    StdinReader::new()
  }

  impl StdinReader {
    pub fn new() -> Self {
      let mut s = String::new();
      let stdin = stdin();
      stdin.lock().read_to_string(&mut s).unwrap();
      let buf = s.split_whitespace().map(|s| s.to_string()).collect();
      return StdinReader { buf: buf, cursor: 0 }
    }

    pub fn read_all(&self) -> Vec<String> {
      return self.buf.clone()
    }

    pub fn next(&mut self) -> Option<String> {
      let val = self.buf.get(self.cursor).cloned();
      self.cursor += 1;
      return val
    }

    pub fn as_i64(&mut self) -> Option<i64> {
      self.next().and_then(|s| s.parse::<i64>().ok())
    }

    pub fn as_f64(&mut self) -> Option<f64> {
      self.next().and_then(|s| s.parse::<f64>().ok())
    }

    pub fn as_usize(&mut self) -> Option<usize> {
      self.next().and_then(|s| s.parse::<usize>().ok())
    }
  }
}

mod utils {
  pub fn is_int(n: f64) -> bool {
    let trunc = (n.trunc() as i64) as f64;
    return (n - trunc) < 0.0001
  }
}

fn main() {
  let m = 2019;
  let mut reader = stdin_reader::new();
  let l = reader.as_i64().unwrap();
  let r = reader.as_i64().unwrap();

  let mut cnt = 0;
  let max_cnt = m * (m-1) / 2;
  let mut min = None;
  for i in l..(r+1) {
    for j in (i+1)..(r+1) {
      cnt += 1;
      let val = (i % m) * (j % m) % m;
      if !(min.is_some() && min.unwrap() < val) {
        min = Some(val);
      }
      if cnt > max_cnt {
        break
      }
    }
    if cnt > max_cnt {
      break
    }
  }

  println!("{}", min.unwrap());
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define LL long long 
using namespace std;
int main(void){
	LL a,b,c;
	LL x,y;
	cin>>a>>b>>c;
	x=b/c;
	y=a/c;
	if(a%c==0)	y--;	
	//cout<<x<<" "<<y<<endl;
	cout<<x-y<<endl;
	return 0;
}
	
	

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    set<string> st;
    rep(i, (int)s.size()) {
        for (int j = 1; j <= 5; ++j) {
            st.emplace(s.substr(i, j));
        }
    }
    int idx = 0;
    for (auto p : st) {
        if (idx==k-1) {
            cout << p << endl;
            return 0;
        }
        ++idx;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

ll n,m;

ll comb[3252][3252];  // combination
ll dstr[3252][3252];  // n items into k groups (distinct, may not use all n items)

// a^b mod m
ll modpow(ll a, ll b, ll m){
  ll r=1ll;
  while(b){
    if(b&1)r=r*a%m;
    a=a*a%m;
    b>>=1;
  }
  return r;
}
// 2^(2^n) mod m
ll pow2pow2(ll n, ll m){
  ll ret = 2ll;
  while(n--){
    ret = ret*ret % m;
  }
  return ret;
}

int main(){
  cin>>n;
  cin>>m;
  // m = 1000000007ll;

  REP(i,3252)REP(j,3252){
    comb[i][j] = j>i ? 0ll : (j==i || j==0 ? 1ll : (comb[i-1][j-1] + comb[i-1][j])%m);
  }
  REP(i,3252)dstr[i][0] = 1ll;
  FOR(i,1,3252)FOR(j,1,3252){
    dstr[i][j] = (dstr[i-1][j]*(j+1) + dstr[i-1][j-1]) % m;
  }

  ll ans = 0;
  FOR(k,0,n+1){
    ll add = 0;
    ll ramens = modpow(2ll, n-k, m);
    ll ramenspowx = 1ll;  // ramens^x mod m
    FOR(x,0,k+1){
      add = (add + dstr[k][x] * ramenspowx) % m;
      ramenspowx = ramenspowx * ramens % m;
    }
    add = add * comb[n][k] % m;
    add = add * pow2pow2(n-k, m) % m;
    if(k%2==0){
      ans += add;
    }else{
      ans += m-add;
    }
    if(ans>=m)ans-=m;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 165504
#include <bits/stdc++.h>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
// clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
// debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main() {
    ll m, n; cin >> n >> m;
    ll x = m;
    for (ll k = 1; k*k <= m; k++) {
        if (m % k == 0) {
            ll l = m / k;
            if (k >= n && k < x) x = k;
            if (l >= n && l < x) x = l;
        }
    }
    cout << (m / x) << endl;
    return 0;
}

// https://atcoder.jp/contests/abc112/tasks/abc112_d
// 約数を知りたいとき，わざわざ素因数分解をしなくても
// kを1から\sqrt{M}まで動かして，mがkで割り切れるかどうかを調べれば良い
// ことがある

// 知りたいのは, Mの約数であってN以上の最小のもの

Measured memory_bytes: 256
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<ll,ll>, null_type,greater_equal<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
ll ans[100005],cnt=0,vis[100005];
void dfs(ll ind,vector<ll>v[],ll c[])
{
	vis[ind]=1;
	for(ll i=0;i<v[ind].size();i++)
	if(!vis[v[ind][i]])
	dfs(v[ind][i],v,c);
	ans[ind]=c[cnt];
	cnt++;
}
int main()
{
	sync;
	ll n;
	cin>>n;
	vector<ll>v[n+1];
	ll c[n];
	for(ll i=0;i<n-1;i++)
	{
		ll x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	input(c,n);
	sort(c,c+n);
	dfs(1,v,c);
	ll sum=0;
	for(ll i=0;i<n-1;i++)
	sum+=c[i];
	cout<<sum<<endl;
	for(ll i=1;i<=n;i++)
	cout<<ans[i]<<" ";
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);
const double pi = acos(-1);

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b,a%b);
}
int main() {
	cin.sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	int g;
	int mx = 0;
	rep(i,0,n) {
		if(i == 0) {
			cin >> g;
			mx = max(g,mx);
		}
		else {
			int num;
			cin >> num;
			mx = max(mx,num);
			g = gcd(g,num);
		}
	}
	if(k % g == 0 && k <= mx) {
		cout << "POSSIBLE" << endl;
	} else cout << "IMPOSSIBLE" << endl;
	return 0;
}



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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    int a,b;
    cin>>a>>b;
    if(a>=1 && a<=9&& b>=1 && b<=9)
    {
        cout<<a*b<<endl;
    }
   else
   {
       cout<<"-1"<<endl;
   }


















    return 0;

}














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

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	while (1) {
		c -= b;
		if (c<=0) break;
		a -= d;
		if (a<=0) break;
		//cout << "(" << a << "," << c << ")\n";
	}
	if (a >= c) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3596
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# (と)の数は同じ、最下点に注目
N = ir()
S = [[1 if x == '(' else -1 for x in list(sr())] for _ in range(N)]
pos = []
neg = []
for s in S:
    temp = 0
    mi = 0
    for x in s:
        temp += x
        if temp < mi:
            mi = temp
    if temp >= 0:
        pos.append((mi, temp))
    else:
        neg.append((mi-temp, -temp))

pos.sort(reverse=True)
neg.sort(reverse=True)
cur_p = 0; cur_n = 0
bl = True
for m, p in pos:
    if cur_p + m < 0:
        bl = False
    cur_p += p

for m, n in neg:
    if cur_n + m < 0:
        bl = False
    cur_n += n

if cur_p != cur_n:
    bl = False

print('Yes' if bl else 'No')


Measured memory_bytes: 231832
require("fs").readFileSync("/dev/stdin","utf8").split('\n').some(function(i){c=i.split(' ');m=c[0],d=c[1];if(m!=0)console.log(['Sun','Mon','Tues','Wednes','Thurs','Fri','Satur'][new Date(2004,m-1,d).getDay()]+'day')})

Measured memory_bytes: 7624
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
	int rectangle = 0;
	int rhombus   = 0;

	string line;
	while(getline(cin, line))
	{
		int a, b, c;
		sscanf(line.c_str(), "%d,%d,%d", &a, &b, &c);

		if(a * a + b * b == c * c)
			rectangle++;
		if(a == b)
			rhombus++;
	}

	cout << rectangle << endl;
	cout << rhombus << endl;

	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

struct point{
    int x,y;
};

struct line{
    point s,t;
};
struct bec{
    int x,y;
};
struct circle{
    point p;
    int r;
};



void solve(circle o, line l){
    double d;
    bec p1p,p1p2;
    p1p.x=o.p.x-l.s.x; p1p.y=o.p.y-l.s.y;
    p1p2.x=l.t.x-l.s.x; p1p2.y=l.t.y-l.s.y;
    double c,dp,dp2,k,ansx,ansy;
    dp=sqrt((double)p1p.x*(double)p1p.x+(double)p1p.y*(double)p1p.y);
    dp2=sqrt((double)p1p2.x*(double)p1p2.x+(double)p1p2.y*(double)p1p2.y);
    if(dp==0){
        d=0;
        ansx=o.p.x;
        ansy=o.p.y;
    }
    else{
    c=((double)p1p.x*(double)p1p2.x+(double)p1p.y*(double)p1p2.y)/(dp*dp2);
    k=dp*c;
    ansx=l.s.x+k*(p1p2.x/dp2);
    ansy=l.s.y+k*(p1p2.y/dp2);
    d = sqrt((o.p.x-ansx)*(o.p.x-ansx)+(o.p.y-ansy)*(o.p.y-ansy));
    }
    
    
    double co = sqrt(1-(d/o.r)*(d/o.r));
    double ansx1,ansx2,ansy1,ansy2;


    ansx1 = ansx-(o.r*co)*(p1p2.x/dp2);
    ansx2 = ansx+(o.r*co)*(p1p2.x/dp2);
    ansy1 = ansy-(o.r*co)*(p1p2.y/dp2);
    ansy2 = ansy+(o.r*co)*(p1p2.y/dp2);
    if(ansx1<ansx2) printf("%.8f %.8f %.8f %.8f\n",ansx1,ansy1,ansx2,ansy2);
    else if(ansx1==ansx2){
        if(ansy1<ansy2) printf("%.8f %.8f %.8f %.8f\n",ansx1,ansy1,ansx2,ansy2);
        else printf("%.8f %.8f %.8f %.8f\n",ansx2,ansy2,ansx1,ansy1);
    }
    else printf("%.8f %.8f %.8f %.8f\n",ansx2,ansy2,ansx1,ansy1);
}

int main(){
    int cx,cy,x1,x2,y1,y2,n,r;
    point p,s,t;
    line l;
    circle o;

    cin>>cx>>cy>>r;
    p.x=cx;
    p.y=cy;
    o.p=p; o.r=r;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x1>>y1>>x2>>y2;
        s.x=x1; s.y=y1;
        t.x=x2; t.y=y2;
        l.s=s; l.t=t;
        solve(o,l);
    }
}


Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int A=sc.nextInt();
		int B=sc.nextInt();

		if(12>=A && A>=6) B=B/2;
		else if(A<=5) B=0;
		else ;

		System.out.println(B);

		sc.close();
	}

}


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

using namespace std;

int n;
vector<double> p;
vector<vector<double>> dp;

int main(){
    cin>>n;
    p.resize(n + 1);
    dp.resize(n + 1, vector<double>(n + 1));
    for(int i = 1; i <= n; i++){
        cin>>p[i];
    }
    vector<double> pp(n + 1);
    pp[0] = 1.0;
    for(int i = 1; i <= n; i++){
        pp[i] = pp[i-1] * (1 - p[i]);
    }
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= i; j++){
            if(j == 0){
                dp[i][0] = pp[i];
            }else{
                dp[i][j] = p[i] * dp[i-1][j-1] + (1 - p[i]) * dp[i-1][j];
            }
        }
    }
    auto res = 0.0;
    for(int i = n/2 + 1; i <= n; i++){
        res += dp[n][i];
    }
    cout<<setprecision(15)<<endl;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main(void){
    int N, M, L; cin >>  N >> M >> L;
    vector<vector<int>> dist(N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) 
        dist[i][i] = 0;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = dist[b][a] = c;
    }

    // Warshall–Floyd Algorithm
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    vector<vector<int>> dist2(N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if(dist[i][j] <= L)
                dist2[i][j] = 1;
        }
    }

    // Warshall–Floyd Algorithm
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);
            }
        }
    }

    int Q; cin >> Q;
    vector<int> ans(Q);
    for (int i = 0; i < Q; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        ans[i] = dist2[s][t] - 1;
        if(dist2[s][t] == INF)
            ans[i] = -1;       
    }
    for (int i = 0; i < Q; i++)
        cout << ans[i] << endl;
    
    return 0;
}


Measured memory_bytes: 1664
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int main() {
	vector<int> A(5);
	cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
	vector<int> P = { 0, 1, 2, 3, 4 };
	int final_answer = inf;
	do {
		int ans = 0;
		for (int i = 0; i < 5; ++i) {
			while (ans % 10 != 0) ans += 1;
			ans += A[P[i]];
		}
		final_answer = min(final_answer, ans);
	} while (next_permutation(P.begin(), P.end()));
	cout << final_answer << endl;
	return 0;
}


Measured memory_bytes: 3564
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )

class UnionFind {
public:
	UnionFind( ll n ) : par( n ), siz( n, 1LL )
	{
		rep( i, n )
		{
			par[i] = i;
		}
	}

	ll find( ll x )
	{
		if ( par[x] == x )
		{
			return ( x );
		}
		else
		{
			return ( par[x] = find( par[x] ) );
		}
	}

	ll size( ll x )
	{
		return ( siz[find( x )] );
	}

	void unite( ll x, ll y )
	{
		x = find( x );
		y = find( y );

		if ( x == y ) return;

		if ( siz[x] < siz[y] )
		{
			par[x] = y;
			siz[y] += siz[x];
		}
		else
		{
			par[y] = x;
			siz[x] += siz[y];
		}
	}

private:
	vector<ll> par;
	vector<ll> siz;
};

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

	vector<Pll> v;
	rep( i, M )
	{
		ll a, b;
		cin >> a >> b;
		v.eb( mp( a - 1, b - 1 ) );
	}

	UnionFind uf( N );
	vector<ll> ans( M, 0 );
	ans[M - 1] = ( N * ( N - 1 ) ) / 2;

	for ( int i = M - 1; i >= 1; --i )
	{
		ll n1 = uf.size( v[i].F );
		ll n2 = uf.size( v[i].S );

		if ( uf.find( v[i].F ) == uf.find( v[i].S ) )
		{
			ans[i - 1] = ans[i];
		}
		else
		{
			ans[i - 1] = ans[i] - n1 * n2;
			uf.unite( v[i].F, v[i].S );
		}
	}

	rep( i, M )
	{
		cout << ans[i] << endl;
	}

	return ( 0 );
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	string A,B,C; cin >> A >> B >> C;
	int ans = 0;
	repp(i,0,N){
		if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) ans += 2;
		else if(A[i] == B[i] && B[i] == C[i]) ans += 0;
		else ans += 1;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef pair<int, int> pr;
typedef vector<int> vec;
typedef long long int lli;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define TEST int T; cin >> T; while(T--)


int main() {
    lli n, d;
    cin >> n >> d;

    lli x, y, cnt = 0;
    for(int i=0; i<n; i++) {
        cin >> x >> y;
        if(x*x + y*y <= d*d) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    print(max(0LL, min(b,d) - max(a,c)));

}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a , mod-2 , mod);
}

struct CustomCompare
{
    bool operator()(const pair<int,int>& l, const pair<int,int>& r)
	{
	    return  l.S < r.S;
	}
};

void solve() 
{
	int n , m , p;
	
	cin >> n >> m >> p;
	
	vector<pair<int,int>> a(p);
	
	for(int i = 0; i < p; ++i) {
		cin >> a[i].F >> a[i].S;
	}
	
	sort(ALL(a));
	
	map<int,int> f;
	
	multiset<int> mt;
	
	for(int i = 0; i < p; ++i) {
		f[a[i].S]++;
	}
	
	for(auto u : f) {
		mt.insert(u.S);
	}
	
	int mx = 0;
	
	for(int i = 0; i < p; ++i) {
		int j = i;
		
		while(j < p && a[i].F == a[j].F) {
			mt.erase(mt.find(f[a[j].S]));
			mt.insert(f[a[j].S]-1);
			j++;
		}
		
		auto tm = mt.end();
		tm--;
		
		mx = max(mx , j - i + (*tm));
		
		for(int z = i; z < j; ++z) {
			mt.erase(mt.find(f[a[z].S]-1));
			mt.insert(f[a[z].S]);
		}
		
		i = j-1;
	}
	
	cout << mx;
}

signed main() {
    fast;

    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 40664
n,q=[int(i) for i in input().split(" ")]
S=[[] for i in range(n)]

for _ in range(q):
    query=[int(i) for i in input().split(" ")]
    if query[0]==0:
        S[query[1]].append(query[2])
    elif query[0]==1:
        if len(S[query[1]])>0:
            print(S[query[1]][-1])
    else:
        if len(S[query[1]])>0:
            S[query[1]].pop(-1)



Measured memory_bytes: 13644
#![allow(non_snake_case, unused_assignments, unused_mut, dead_code)]
use proconio::fastout;
use proconio::input;
//use proconio::marker::Usize1;
use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;
//use std::collections::BTreeSet;

#[fastout]
fn main() {
    input! {
       N: usize,
       S:Chars
    }
    let mut a = vec![0; N];
    let mut cnt = vec![0i64; 3];
    for i in 0..N {
        a[i] = ((S[i] as u8) % 3) as i64;
    }
    for i in 0..N {
        cnt[a[i] as usize] += 1;
    }
    let mut ans = 1;
    for i in 0..3 {
        ans = ans * cnt[i];
    }

    for i in 0..(N - 1) {
        for j in (i + 1)..N {
            let k = 2 * j - i;
            if k >= N {
                continue;
            }
            //        println!("{},{},{}", i, j, k);
            if S[i] != S[j] && S[j] != S[k] && S[k] != S[i] {
                ans -= 1;
            }
        }
    }
    println!("{}", ans);
}


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

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() {
  int n, k;
  while (cin >> n >> k) {
    int ans = INT_MAX;
    int a = 1;
    for (int i = 0; i <= n; ++i) {
      int tmp = a;
      int tot = 0;
      for (int j = i + 1; j <= n; ++j) {
        tmp += k;
        tot ++;
      }

      ans = min(ans, tmp);
      a *= 2;
    }

    a = 1;
    for (int i = 0; i <= n; ++i) {
      int tmp = a;
      for (int j = i + 1; j <= n; ++j) {
        tmp *= 2;
      }
      ans = min(ans, tmp);
      a += k;
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(),v.end()
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
vector<int> a(n),b(n),c(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
for(int i=0;i<n;i++){
cin>>c[i];
}
sort(ALL(a)),sort(ALL(b)),sort(ALL(c));
long long cnt=0;
for(int i=0;i<n;i++){
  long long x = (long long)(lower_bound(ALL(a),b[i])-a.begin());
  long long y = (long long)(c.end()-upper_bound(ALL(c),b[i]));
  cnt+=x*y;
}
cout<<cnt<<endl;


}

Measured memory_bytes: 1408
// いちいち全部ソートしなくてもいいのでは？（＞Д＜）

import java.util.*;

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

        int n = sc.nextInt();

        int[] a = new int[100010];
        int[] b = new int[100010];
        int[] numA = new int[2];
        int[] numB = new int[2];
        int[] cntA = new int[2];
        int[] cntB = new int[2];

        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            if (i % 2 == 0) {
                a[tmp] += 1;
                if (cntA[0] < a[tmp]) {
                    cntA[0] = a[tmp];
                    numA[0] = tmp;
                } else if (cntA[1] < a[tmp]) {
                    cntA[1] = a[tmp];
                    numA[1] = tmp;
                }
            } else {
                b[tmp] += 1;
                if (cntB[0] < b[tmp]) {
                    cntB[0] = b[tmp];
                    numB[0] = tmp;
                } else if (cntB[1] < b[tmp]) {
                    cntB[1] = b[tmp];
                    numB[1] = tmp;
                }
            }
        }

        int ans = n;
        if (numA[0] != numB[0]) {
            ans -= cntA[0] + cntB[0];
        } else {
            if (cntA[0] - cntA[1] > cntB[0] - cntB[1])
                ans -= cntA[0] + cntB[1];
            else
                ans -= cntA[1] + cntB[0];
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 58124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
namespace AOJ {
    internal class Program {
        public static void Main(string[] args) { new Program().solve(); }
        void solve() {
            Func <int, bool> isFin = (input) => input == 0;
            Func <double, double> second = (value) => value * value;
            Func <double[], double> dispersion = (arr) => {
                var m = arr.Average();
                var n = arr.Count();
                return arr.Aggregate(0D, (v, next) => v + second(next - m)) / n;
            };
            Func <double[], double> standardDeviation = (arr) => Math.Sqrt(dispersion(arr));

            var ans=new List <double>();
            while(true) {
                var n = int.Parse(Console.ReadLine());
                if(isFin(n))break;
                var arr = Console.ReadLine().Split().Select(v => double.Parse(v)).ToArray();
                ans.Add(standardDeviation(arr));
            }
            foreach(var v in ans) {
                Console.WriteLine(v);
            }
        }
    }
}



Measured memory_bytes: 9868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, query, k;
  cin >> n;
  vector<vector<pair<ll, ll>>> g(n);
  rep(i, n - 1) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].push_back(P(b, c));
    g[b].push_back(P(a, c));
  }
  cin >> query >> k;
  k--;
  vl x(query), y(query);
  rep(i, query) cin >> x[i] >> y[i];
  queue<ll> q;
  vl d(n, -1);
  d[k] = 0;
  q.push(k);
  while(!q.empty()) {
    ll i = q.front();
    q.pop();
    for(auto v : g[i]) {
      ll ni = v.first;
      ll dist = v.second;
      if(d[ni] != -1) continue;
      d[ni] = d[i] + dist;
      q.push(ni);
    }
  }
  rep(i, query) cout << d[--x[i]] + d[--y[i]] << endl;
}

Measured memory_bytes: 12288