akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

/* 約数の列挙 */
ll divisorExec(ll n)
{
	ll ans = 0;
	for (ll i = 1; i <= sqrt(n); i++){
		if ((n % i) == 0) {
			ans++;
			if ((i * i) != n) {
				ans++;
			}
		}
	}
	return ans;
}

void Solve()
{
	ll N;
	cin >> N;

	ll ans = 0;
	REPN(i, 1, N) {
		ll one = N - 1;
		ans += one / i;
	}

	cout << ans << endl;
}

// メインs
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int X, Y;
    cin >> X >> Y;
    cout << X + Y/2 << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        String brChange;
        while (true){
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            brChange = br.readLine();
            
            if(brChange.length() < 1200){
                break;
            }
        }
        //文字列反転(大文字に変換)
        String upChar = brChange.toUpperCase();
    
        // List<String> beforeChar = new ArrayList<String>();
        List<Character> afterCharList = new ArrayList<Character>();
        
        //文字列を文字としてリストに格納
        for(int i=0 ;i<upChar.length(); i++){
            char aaa = upChar.charAt(i);
            afterCharList.add(i,aaa);
        } 
        
        for(int i=0; i<brChange.length(); i++){
            if(brChange.charAt(i) == upChar.charAt(i)){
                String aaa = String.valueOf(brChange.charAt(i));
                String bbb = aaa.toLowerCase();     //小文字に変換
                char[] c = bbb.toCharArray();
                afterCharList.set(i,c[0]);
            }
        }
        
        String ABCDE = "";
        for(int a=0; a<afterCharList.size(); a++){
            ABCDE = ABCDE + afterCharList.get(a);
        }
        // System.out.println("\n\n" + "変更前の文字列→" + brChange);
        System.out.println(ABCDE );
    }
}



Measured memory_bytes: 30736
a = []
a += input()
a *= 2
b = []
b += input()
k = 0
for i in range(len(b)):
    t = []
    for j in range(i, i + len(b)):
        t += a[j]
    if t == b:
        print("Yes")
        k = 1
        break
if k == 0:
    print("No")

Measured memory_bytes: 3064
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

n,k = readInts()
p = readInts()

s = []
s.append((p[0]+1)/2)

for i in range(1,n):
	s.append(s[-1]+(p[i]+1)/2)

ans = s[k-1]
#print(s)
for i in range(n-k):
	ans = max(ans,s[i+k]-s[i])

print(ans)

Measured memory_bytes: 26624
import sys
input=lambda: sys.stdin.readline().rstrip()
h,w,k=map(int,input().split())
S=[input() for _ in range(h)]
ans=float("inf")
import bisect
for i in range(2**(h-1)):
  Cut=[]
  cur=0
  for ii in range(h-1):
    if i&(1<<ii):
      Cut.append(ii)
  p=len(Cut)+1
  Num=[0]*h
  for ii in range(h):
    Num[ii]=bisect.bisect_left(Cut,ii)

  A=[0]*p
  Chk=True
  for j in range(w):
    B=[0]*p    
    for jj in range(h):
      if S[jj][j]=="1":
        B[Num[jj]]+=1
    for jj in range(p):
      if B[jj]>k:
        Chk=False
      if A[jj]+B[jj]>k:
        cur+=1
        A=B
        break
      else:
        continue
    else:
      for jjj in range(p):
        A[jjj]+=B[jjj]
  if Chk:
    ans=min(ans,cur+p-1)
print(ans)


Measured memory_bytes: 47836
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
R,G,B,N = inputlist()
ans = 0
for r in range(N//R + 1):
    for g in range(N//G + 1):
        b = N -(r*R+g*G)
        if b < 0:
            continue
        if b % B == 0:
            ans +=1
print(ans)

Measured memory_bytes: 40812
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  string s;
  getline(cin, s);
  for(int i = 0; i < s.size(); i++){
    if('a' <= s[i] && s[i] <= 'z'){
      s[i] = s[i] - ('a' - 'A');
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 1172
import sys

n = int(input())
list_input = list(map(int, sys.stdin.readline().split()))

list_input.sort()

# 倍数判断用のリストを作成
list_div = [0]*(max(list_input))

for i in list_input:
    # print(i)
    a = list_div[i-1]
    # list_div[i-1::i] = [1]*(len(list_div[i-1::i]))
    list_div[i-1::i] = map(lambda x: x+1, list_div[i-1::i])
    if a == 1:
        pass
    else:
        # list_div[i-1] = 0
        pass

ans = 0
for i in list_input:
    if list_div[i-1] == 1:
        ans += 1

print(ans)


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

int main() {
  string N;
  int keta = 0, sum = 0;
  cin >> N;
  keta = N.size();

  rep(i, keta) {
    sum += N[i] - '0';
  }
  if(sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3756
#include<iostream>
using namespace std;
#define yeah ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
int main()
{ yeah;
  int n;
  cin>>n;
  int f=n%10;
  if(f==2||f==4||f==5||f==7||f==9)
    cout<<"hon"<<endl;
 else if(f==0||f==1||f==6||f==8)
	cout<<"pon"<<endl;
	else
	cout<<"bon"<<endl;
	return 0;
}

Measured memory_bytes: 3588
import sys
input = sys.stdin.readline

N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10**9

def DFS(cur, a, b, c):
    if cur == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a, b, c) > 0 else INF
    ret0 = DFS(cur+1, a, b, c)
    retA = DFS(cur+1, a+l[cur], b, c) + 10
    retB = DFS(cur+1, a, b+l[cur], c) + 10
    retC = DFS(cur+1, a, b, c+l[cur]) + 10
    return min(ret0, retA, retB, retC)

print(DFS(0, 0, 0, 0))

Measured memory_bytes: 43996
# -*- coding: utf-8 -*-
#与えられるパズルの数は1000以下です
from heapq import heappush,heappop
MOVE = [[1,4],[0,2,5],[1,3,6],[2,7],[0,5],[1,4,6],[2,5,7],[3,6]]
ans = {"01234567":0}
def swap(field,a,b):
    tmp = list(field)
    tmp[a],tmp[b] = tmp[b],tmp[a]
    return "".join(tmp)

def BFS():
    global ans
    q = [[0,"01234567"]]
    while len(q) != 0:
        g, field = q.pop(0)
        a = field.find("0")
        for b in MOVE[a]:
            tmp = swap(field,a,b)
            if not tmp in ans:
                ans[tmp] = g+1
                q.append([g+1,tmp])

BFS()
while True:
    try:
        print ans[raw_input().replace(" ","")]
    except:
        break

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

int number[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
long long int dp[10][10001];

long long int factorial(int x)
{
	long long int ret = 1;
	for (int i = 1; i <= x; i++) ret *= i;
	return ret;
}

int main()
{
	do
	{
		int sum = 0;
		for (int i = 0; i < 10; i++)
		{
			sum += number[i] * (i + 1);
			dp[i][sum]++;
		}
	} while (next_permutation(number, number + 10));

	int n, s;
	while (cin >> n >> s)
	{
		cout << dp[n - 1][s] / factorial(10 - n) << endl;
	}
	return 0;
}

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

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  string ret = "";
  for(int i=0; i<n; i++){
    if(s[i] == 'B'){
      if(ret.size() == 0) continue;
      ret.erase(ret.size() - 1, 1);
    }else{
      ret += s[i];
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b;
  cin >> a >> b;
  a--, b--;
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(20000000)
def prepare(n,arr):
    nodeArr = [[] for i in range(n)]
    for ar in arr:
        nodeArr[ar[0]-1].append([ar[1]-1,ar[2]])
        nodeArr[ar[1]-1].append([ar[0]-1,ar[2]])
    return nodeArr

def dfs(currentNode,distance):
    res[currentNode] = distance
    for next in nodeArr[currentNode]:
        nextNode = next[0]
        nextNodeDistance = next[1]
        if res[nextNode] == -1:
            dfs(nextNode,distance + nextNodeDistance)




n = int(input())

arr = []

for i in range(n-1):
    arr.append([int(s) for s in input().split(" ")])

nodeArr = prepare(n, arr)


if n == 1:
    print(1)
else:
    res = [-1 for i in range(n)]

    dfs(0,0)

    result = [(re % 2) for re in res]

    for re in res:
        print(re % 2)



Measured memory_bytes: 105672
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

s=SI()
n=len(s)
beki=[0 for i in range(n+1)]
beki[0]=1
for i in range(n):
    beki[i+1]=(beki[i]*10)%2019
#print(beki)

#k=int(s)
dp=[0 for i in range(n)]
dp[-1]=int(s[-1])
#print(dp[3])
for i in range(n-1):
    j=n-i-1
    #print((dp[j]+int(s[j-1])*beki[i+1])%2019)
    dp[j-1]=(dp[j]+int(s[j-1])*beki[i+1])%2019

#print(dp)
ans=0
u=Counter(dp)
#print(u)
for i in u:
    if i==0:
        ans+=(u[i]*(u[i]+1))//2
    else:
        ans+=(u[i]*(u[i]-1))//2
print(ans)

Measured memory_bytes: 24076
// https://atcoder.jp/contests/abc083/tasks/abc083_b
"use strict"
function Main(input) {
  const params = input.split(' ').map(Number);
  const n = params[0];
  const a = params[1];
  const b = params[2];
  let sum = 0;

  for (let i = 1; i <= n; i++) {
    const total = String(i).split('').reduce((acc, cur) => Number(acc) + Number(cur), 0);
    if (a <= total && total <= b) {
      sum += i;
    }
  }

  console.log(sum);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

long long H, W, h, w;
long long sarr[505];

int main(){
	cin >> H >> W >> h >> w;

	if(H%h == 0 && W%w == 0){
		cout << "No" <<endl;
	}else if(H%h != 0){
		cout << "Yes" <<endl;
		for(long long i = 0; i <= H; i++){
			long long num = i / h;
			if(i%h == 0){
				sarr[i] = -1 * num;
			}else{
				sarr[i] = 1000  + (-1 * num);
			}
		}

		for(long long i = 0; i < H; i++){
			for(long long j = 0; j < W; j++){
				cout << sarr[i+1] - sarr[i];
				if(j != W - 1){
					cout << " ";
				}
			}
			cout << endl;
		}
	}else{
		cout << "Yes" <<endl;
		for(long long i = 0; i <= W; i++){
			long long num = i / w;
			if(i%w == 0){
				sarr[i] = -1 * num;
			}else{
				sarr[i] = 1000  + (-1 * num);
			}
		}

		for(long long i = 0; i < H; i++){
			for(long long j = 0; j < W; j++){
				cout << sarr[j+1] - sarr[j];
				if(j != W - 1){
					cout << " ";
				}
			}
			cout << endl;
		}
	}
}


Measured memory_bytes: 1536
s = int(input())

mod = 10**9 + 7
ans = 0

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000, mod)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(10000, mod)

for i in range(1, s):
    t = s - i * 3
    if t >= 0:
        ans += comb(t+i-1, t)
        ans % mod
    else:
        break

print(ans % mod)


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

using namespace std;
int cnt=0;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		if(i%2==0&&j%2==1)
		cnt++;
	}
	cout<<cnt<<endl;
	//printf("Time used=%2.f\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        var T = Console.ReadLine();

        var length = S.Length;
        var count = 0;
        for(int i = 0; i < length; i++)
        {
            if(S[i] != T[i])
            {
                count++;
            }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 27544
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vec;
typedef vector<P> pvec;
typedef vector<vector<int>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<int> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<int,vector<int>,greater<int>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> DX = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> DY = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const ll INF = (1LL << 60); // 1152921504606846976
const double PI = (3.141592653589794);
const double EPS = (0.0000000001); // 10^(-10)

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec G(nmax);


P f(int &x,int &y){
  return P(x-y,x+y);
}


void solve4ts()
{
  
  
  int n;
  cin>>n;
  vector<P> a(n);
  rep(i,n){
    cin>>a[i].fs>>a[i].sc;
  }
  vec x(n);
  vec y(n);
  rep(i,n){
    x[i]=a[i].fs-a[i].sc;

    y[i]=a[i].fs+a[i].sc;
  }
  sort(all(x));
  sort(all(y));
  int ans=0;
  chmax(ans,abs(x[0]-x[n-1]));


  chmax(ans,abs(y[0]-y[n-1]));
  cout<<ans<<endl;


  
  
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
  int repeat = 1;
  // cin >> repeat;
  while(repeat--) solve4ts();
}

/*

g++ -std=c++1z code.cpp

./a.out

python3 expander.py code.cpp

*/

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ll gcd(ll a, ll b) {
    while (b) {
        ll t = a;
        a = b;
        b = t % b;
    }
    return a;
}

void oneCase() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << '\n';
    
}

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

    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i < n; ++i)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

void solve() {
  // main coding
  ll n,w; cin>>n>>w;
  vector<ll> W(n+1),V(n+1);
  rep1(i,n+1) cin>>W[i]>>V[i];
  vector<vector<ll>> dp(n+1,vector<ll>(w+1,-1));
  // memorize recursion
  function<ll(ll,ll)> memo=[&](ll i,ll c) {
    if(dp[i][c]!=-1) return dp[i][c];
    if(i==0) return dp[i][c]=0;
    if(c-W[i]>=0) return dp[i][c]=max(memo(i-1,c),memo(i-1,c-W[i])+V[i]);
    else return dp[i][c]=memo(i-1,c);
  };
  cout<<memo(n,w)<<endl;
}

int main() {
  cout << fixed << setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 80256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();
    let d: usize = read();
    println!("{}", if a + b > c + d { "Left" } else if a + b < c + d { "Right" } else { "Balanced" });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
vector<int> edge[100005];
bool checked[100005];

vector<int> st;
vector<int> val;
void dfs(int id) {
	checked[id] = true;
	st.push_back(id);
	val.push_back(arr[id]);
	for (auto i : edge[id]) {
		if (!checked[i]) dfs(i);
	}
}
int ans = 0;
void solve(int id) {
	val.clear();
	st.clear();
	dfs(id);
	int siz = val.size();
	sort(val.begin(), val.end());
	sort(st.begin(), st.end());
	for (int i = 0, j = 0; i < siz && j < siz; ) {
		if (st[i] > val[j]) j++;
		else if (st[i] < val[j]) i++;
		else {
			ans++;
			i++;
			j++;
		}
	}
}


int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	fill(checked, checked+100005, false);
	for (int i = 1; i <= n; i++) {
		if (!checked[i]) solve(i);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 10156
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

class UnionFind {
public:
	vector<int>par;

	void init(int sz) {
		par.resize(sz, -1);
	}
	int root(int pos) {
		if (par[pos] == -1) return pos;
		par[pos] = root(par[pos]);
		return par[pos];
	}
	void unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return;
		par[x] = y;
	}
	bool same(int x, int y) {
		if (root(x) == root(y)) return true;
		return false;
	}
};

long long N, M, D, A[2009], B[2009], C[2009], minCost, Count;
vector<tuple<long long, long long, long long>>X;
map<pair<int, int>, int>E;

int main() {
	cin >> N >> M >> D;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		X.push_back(make_tuple(C[i], A[i], B[i]));
	}
	sort(X.begin(), X.end());
	UnionFind UF; UF.init(N + 2);

	for (int i = 0; i < X.size(); i++) {
		if (i == 0 || get<0>(X[i]) != get<0>(X[i - 1])) {
			vector<pair<int, int>>S;
			for (int j = 0; j < X.size(); j++) {
				if (get<0>(X[i]) == get<0>(X[j])) S.push_back(make_pair(get<1>(X[j]), get<2>(X[j])));
			}
			for (int j = 0; j < S.size(); j++) {
				if (UF.same(S[j].first, S[j].second) == false) {
					E[make_pair(S[j].first, S[j].second)] = true;
					E[make_pair(S[j].second, S[j].first)] = true;
					Count++;
				}
			}
		}
		if (UF.same(get<1>(X[i]), get<2>(X[i])) == false) {
			UF.unite(get<1>(X[i]), get<2>(X[i]));
			minCost += get<0>(X[i]);
		}
	}
	if (D == minCost) {
		int ret1 = 1; for (int i = 0; i < M; i++) { ret1 *= 2; ret1 %= 1000000007; }
		int ret2 = 1; for (int i = 0; i < M - Count + 1; i++) { ret2 *= 2; ret2 %= 1000000007; }
		cout << (ret1 - ret2 + 1000000007) % 1000000007 << endl;
	}
	else {
		vector<long long>Z;
		for (int i = 1; i <= M; i++) {
			if (E[make_pair(A[i], B[i])] == 1) continue;
			vector<tuple<long long, long long, long long>>Y;
			for (int j = 1; j <= M; j++) {
				if (i == j) continue;
				Y.push_back(make_tuple(C[j], A[j], B[j]));
			}
			sort(Y.begin(), Y.end());
			reverse(Y.begin(), Y.end());
			Y.push_back(make_tuple(C[i], A[i], B[i]));
			reverse(Y.begin(), Y.end());

			long long ret = 0; UnionFind UF2; UF2.init(N + 2);
			for (int j = 0; j < Y.size(); j++) {
				if (UF2.same(get<1>(Y[j]), get<2>(Y[j])) == false) {
					UF2.unite(get<1>(Y[j]), get<2>(Y[j]));
					ret += get<0>(Y[j]);
				}
			}
			Z.push_back(ret);
		}
		sort(Z.begin(), Z.end());
		long long ans = 0;

		for (int i = 0; i < Z.size(); i++) {
			if (Z[i] != D) continue;
			long long rr = 1;
			for (int j = i + 1; j < Z.size(); j++) { rr *= 2; rr %= 1000000007; }
			ans += rr;
		}
		ans *= 2;
		cout << ans % 1000000007 << endl;
	}
	return 0;
}

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

int main(){
    int x,a,b;

    while(scanf("%d%d%d",&x,&a,&b)==3){
        x-=a;
        int amount = x/b;
        x -= amount*b;
        printf("%d\n",x);
    }

    return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var fd = new int[] {  1,2,4,8,16,32,64,128,256,512 };
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var s = Convert.ToString(int.Parse(line.Trim()), 2);
            var sL = s.Length;
            for (int i = 0; i < sL; i++)
                if (s[sL - i - 1] == '1')
                    if (i == sL-1) Console.WriteLine(fd[i]);
                    else Console.Write("{0} ", fd[i]);
        }
    }
}

Measured memory_bytes: 9192
import math
a, b, n = map(int, input().split())
 
 
def calc(a, b, n):
    return int(math.floor((a * n)/b) - (a * math.floor(n/b)))
 
if n <= b -1:
  print(calc(a,b,n))
else:
  print(calc(a,b,b-1))

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}

void solve()
{
    ll n,x;
    cin>>n>>x;
    ll a[n];
    ll p=0,ans=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        p = p + a[i];
        if(p<=x)
            ans++;
        else
            break;
    }
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3708
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 a[100];
  for (i32 i = 0; i < n; ++i) {
    scanf("%" SCNi32, a + i);
  }
  i32 ans = 0;
  for (i32 i = 1; i < n; ++i) {
    if (a[i] == a[i - 1]) {
      a[i] = a[i + 1] + 1;
      ans++;
    }
  }
  printf("%" PRIi32 "\n",ans);
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 128
from collections import deque

SA = deque(input())
SB = deque(input())
SC = deque(input())

NowCard = SA.popleft()
ans = 'A'

while True:
    if NowCard == 'a':
        NowList = SA
        ans = 'A'
    elif NowCard == 'b':
        NowList = SB
        ans = 'B'
    elif NowCard == 'c':
        NowList = SC
        ans = 'C'

    if len(NowList) == 0:
        break

    NowCard = NowList.popleft()

print(ans)


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main(){
  int n;
  int seq = 0;
  int result = 0;
  
  cin >> n;
  for (int i = 1;i<=n;i++) {
    int p;
    cin >> p;
    if (i == p) {
      seq++;
    } else {
      if (seq % 2 == 0) {
	result += seq / 2;
      } else {
	result += seq / 2 + 1;
      }
      seq = 0;
    }
  }
  if (seq % 2 == 0) {
    result += seq / 2;
  } else {
    result += seq / 2 + 1;
  }
  cout << result << endl;
  return(0);
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
MOD = 10**9+7

na = [a[0]]
for i in range(n-1):
    if a[i] != a[i+1]:
        na.append(a[i+1])
        
m = len(na)
cur = [-1]*(max(na)+1)

dp = [0]*(m+1)
dp[0] = 1
for i in range(m):
    if cur[na[i]] != -1:
        dp[i+1] = (dp[i] + dp[cur[na[i]]]) % MOD
        cur[na[i]] = i+1
    else:
        cur[na[i]] = i+1
        dp[i+1] = dp[i]
        
print(dp[m])

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

using namespace std;
using ll = long long;

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

  ll x;
  cin >> x;
  ll m = 100;
  ll ans = 0;
  while (m < x) {
    m = floor(m * 1.01);
    ans++;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
int main() {
  ll N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) {
    cout << 1 << endl;
  } else if (N == 1 || M == 1) {
    cout << max(N,M) - 2 << endl;
  } else {
    cout << (N - 2) * (M - 2) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.diverta2019
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] rgbn = ReadInts();
            int r = rgbn[0];
            int g = rgbn[1];
            int b = rgbn[2];
            int n = rgbn[3];

            int[] val = new int[3] { r, g, b };
            Array.Sort(val);
            Array.Reverse(val);
            int res = 0;
            for(int i = 0; i * val[0] <= n; i++)
            {
                int delta = n - i * val[0];
                for(int j = 0; j * val[1] <= delta; j++)
                {
                    int delta2 = delta - j * val[1];
                    if (delta2 % val[2] == 0) res++;
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268
N = int(input())
c = input()
c = list(c)
t = True

i = 0
j = N - 1
count = 0

while t:
	if c[i] == "R":
		i += 1
	elif c[j] == "W":
		j -= 1
	elif c[i] == "W" and c[j] == "R":
		c[i] = "R"
		c[j] = "W"
		count += 1	
	if i >= j:
		t = False
		break
print(count)


Measured memory_bytes: 10744
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
    	cin>>a[i];
    }
    ll mx=0;
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
    	ans+=max(0LL,mx-a[i]);
    	mx=max(mx,a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5204
#include<iostream>

using namespace std;

#define long long long

long n, s, m;
long w[101], v[101], dp[101][100000];


long cal(int idx, long val) { 
    if (idx > n && val == 0) return 0;
    if (val <= 0) return 0;
    if (idx > n) return 1e18;
    if (dp[idx][val] != -1) return dp[idx][val];
    dp[idx][val] = 0;

    if (val - v[idx] >= 0) dp[idx][val] = min (cal(idx + 1, val), cal(idx + 1, val - v[idx]) + w[idx]);
    else dp[idx][val] = cal(idx + 1, val);
    return dp[idx][val];
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) cin >> w[i] >> v[i], s += v[i];
    for (int i = 0; i <= n; i ++)
        for (int j = 0; j <= s; j ++) dp[i][j] = -1;
}

void Solve() {
    for (int i = s; i >= 1; i --) {
        long res = cal(1, i);
        if (res <= m) {
            cout << i;
            return;
        }
    }
}

int main() {
    FastInput();
    Input();
    Solve();
}

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

int main()
{
	int n;
	cin>>n;
	int count = 0;
    for(int i=1; i<=n; i*=100)
    {
        if(i*10-1 <= n)
        {
            count+= i*10-i;
            //cout<<i*10-1<<": "<<count<<endl;
        }

        else
        {
            //cout<<"Inside Else:\n";
            count += n-i+1;
            //cout<<i<<": "<<n-i+1<<": "<<count<<endl;
            break;
        }
    }
    cout<<count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){ 
  string s,t;
  cin >> s>>t;
  int ans=0;
  rep(i,s.size()){
    if(s.at(i)!=t.at(i)){
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3916
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll bit[200005];

void add(int index, ll x) {
  while(index<200005) {
    bit[index] += x;
    index += index&-index;
  }
}

ll getsum(int index1, int index2) {
  ll ans1=0, ans2=0;
  while(index1>0) {
    ans1 += bit[index1];
    index1 -= index1&-index1;
  }
  while(index2>0) {
    ans2 += bit[index2];
    index2 -= index2&-index2;
  }
  return ans2-ans1;
}

int main() {
  ll N, D, A;
  cin>>N>>D>>A;
  vector<pair<ll, ll> > arr(N);
  ll X, H;
  for(int i=0;i<N;++i) {
    cin>>X>>H;
    arr[i] = mp(X, H);
  }
  sort(arr.begin(), arr.end());
  vector<ll> arr1(N);
  for(int i=0;i<N;++i) arr1[i] = arr[i].fi;
  int index;
  ll tmp;
  ll ans=0;
  for(int i=0;i<N;++i) {
    X = arr[i].fi;
    H = arr[i].se;
    index = lower_bound(arr1.begin(), arr1.end(), arr1[i]-2*D)-arr1.begin()+1;
    tmp = getsum(index-1, i+1);
    H -= A*tmp;
    if(H<=0) ;
    else if(H%A==0) {
      ans += H/A;
      add(i+1, H/A);
    }
    else {
      ans += H/A+1;
      add(i+1, H/A+1);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 9592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

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

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll ans=0;
  vl LG(n),RG(n);
  LG[0]=a[0];
  RG[n-1]=a[n-1];
  FOR(i,1,n-1){
    LG[i]=gcd(LG[i-1],a[i]);
    RG[n-1-i]=gcd(a[n-1-i],RG[n-i]);
  }
  rep(i,n){
    if(i==0){
      ans=max(ans,RG[1]);
    }
    else if(i==n-1){
      ans=max(ans,LG[n-2]);
    }
    else{
      ll z=gcd(LG[i-1],RG[i+1]);
      ans=max(ans,z);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int query = sc.nextInt();

        int data[][] = new int[n + 1][n + 1];
        for (int i = 0; i < m; i++) {
            data[sc.nextInt()][sc.nextInt()]++;
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                data[i][j] += data[i][j - 1];
            }
        }
        for (int j = 0; j <= n; j++) {
            for (int i = 1; i <= n; i++) {
                data[i][j] += data[i - 1][j];
            }
        }

        for (int i = 0; i < query; i++) {
            int p = sc.nextInt();
            int q = sc.nextInt();
            System.out.println(data[q][q] - data[p - 1][q]);
        }
    }

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


Measured memory_bytes: 153456
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define N 4
#define NPANEL (N * N)
#define EMPTY 0

int manhattan_sum(short panels[]) {
  int result = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int v = panels[i * N + j] - 1;
      if (v == EMPTY - 1)
        continue;
      int tmp = abs(i - v / N) + abs(j - v % N);
      result += tmp;
    }
  }
  return result;
}

class State {
public:
  short panels[NPANEL];
  short empty;
  int estimate;
  State(short p[]) {
    for (int i = 0; i < NPANEL; i++) {
      panels[i] = p[i];
      if (p[i] == EMPTY)
        empty = i;
    }
    estimate = manhattan_sum(panels);
  }
  void print() {
    for (int i = 0; i < NPANEL; i++) {
      if (i != 0 && i % N == 0)
        printf("\n");
      printf("%d ", panels[i]);
    }
    printf("\n");
  }
  bool is_completed() {
    for (int i = 0; i < NPANEL-1; i++)
      if (panels[i] != i+1)
        return false;
    return true;
  }
  State left() { return slide(empty, empty - 1); }
  State above() { return slide(empty, empty - N); }
  State right() { return slide(empty, empty + 1); }
  State bottom() { return slide(empty, empty + N); }
  State slide(int x, int y) {
    auto s = State(panels);
    swap(s.panels[x], s.panels[y]);
    s.empty = y;
    s.estimate = manhattan_sum(s.panels);
    return s;
  }

  vector<State> nexts() {
    vector<State> v;
    if (empty % N != 0)
      v.push_back(left());
    if (empty >= N)
      v.push_back(above());
    if (empty % N != N - 1)
      v.push_back(right());
    if (empty <= NPANEL - N - 1)
      v.push_back(bottom());
    return v;
  }
  bool operator<(const State &s) const {
    for (int i = 0; i < NPANEL - 1; i++) {
      if (panels[i] == s.panels[i])
        continue;
      return panels[i] < s.panels[i];
    }
    return false;
  }
};

bool is_cached(State st) {
  /*
  static map<long long, bool> cache;
  long long hash = 0;
  long long n = 1;
  for (int i = 0; i < NPANEL-1; i++) {
    hash += st.panels[i] * n;
    n *= (NPANEL-1);
  }
  bool exists = cache[hash];
  if (!exists) {
    cache[hash] = true;
  }
  */
  static set<long long> cache;
  long long hash = 0;
  long long n = 1;
  for (int i = 0; i < NPANEL-1; i++) {
    hash += st.panels[i] * n;
    n *= (NPANEL-1);
  }
  bool exists = cache.find(hash) != cache.end();
  if (!exists) {
    cache.insert(hash);
  }
  return exists;
}

struct Node {
  State state;
  int depth;
  bool operator<(const Node &n) const {
    return state.estimate + depth > n.state.estimate + n.depth;
  }
};

short solve(State init) {
  priority_queue<Node> que;
  que.push(Node{init, 0});
  is_cached(init);

  while (!que.empty()) {
    Node node = que.top();
    que.pop();
    if (node.state.is_completed())
      return node.depth;
    for (auto s : node.state.nexts()) {
      if (!is_cached(s)) {
        que.push(Node{s, node.depth + 1});
      }
    }
  }
  return -1; // unsolved
}

int main() {
  short data[NPANEL];
  for (int i = 0; i < NPANEL; i++)
    cin >> data[i];

  auto s = State(data);

  cout << solve(s) << endl;
}

Measured memory_bytes: 142008
package main

import "fmt"

const inf = 1e15

// Edge .
type Edge struct {
	to, cost int
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	edges := make(map[int][]Edge)
	var a, b, c int
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b, &c)
		a, b = a-1, b-1
		e := Edge{to: b, cost: -c}
		edges[a] = append(edges[a], e)
	}

	d := make([]int, n)
	for k := range d {
		d[k] = inf
	}
	d[0] = 0

	loop := false
	for i := 0; i <= n*2; i++ {
		for v := 0; v < n; v++ {
			if d[v] == inf {
				continue
			}
			for _, e := range edges[v] {
				if d[v]+e.cost < d[e.to] {
					d[e.to] = d[v] + e.cost
					if e.to == n-1 && i == n*2-1 {
						loop = true
					}
				}
			}
		}
	}

	if loop {
		fmt.Println("inf")
	} else {
		fmt.Println(-d[n-1])
	}
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=205;
int F[N][N],arr[11],p[11];
vector<PII>adj[N];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,m,r;
    scanf("%d%d%d",&n,&m,&r);
    for(int i=1;i<=r;i++)
		scanf("%d",arr+i),p[i]=i;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j)
				F[i][j]=INF;
	while(m--){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		F[a][b]=F[b][a]=c;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				umin(F[i][j],F[i][k]+F[k][j]);
	int ans=INF;	
	do{
		int res=0;
		for(int i=1;i<r;i++)
			res+=F[arr[p[i]]][arr[p[i+1]]];
		umin(ans,res);	
	}while(next_permutation(p+1,p+r+1));	
	printf("%d\n",ans);	
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int A[25];
int n;
int dp[25][2010];

bool solve(int i,int k){
	if(k==0) dp[i][k]=1;
	else if(i>=n) dp[i][k]=0;
	else if(solve(i+1,k)) dp[i][k]=1;
	else if(solve(i+1,k-A[i])) dp[i][k]=1;
	else dp[i][k]=0;
	return dp[i][k];
}

int main (){
	int q,k;
	cin>>n;
	for(int i=0;i<n;i++) cin>>A[i];
	cin>>q;
	for(int i=0;i<q;i++) {
		cin>>k;
		if(solve(0,k)==true) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep (i,q) {
        cin >> a.at(i);
    }
    vector<int> mochi(n,k - q);

    for (int i = 0; i < q; i++) {
        mochi.at(a.at(i) - 1)++;
    }

    rep(i, n) {
        if (mochi.at(i) <= 0) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

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

int main() {
  long double w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << fixed << setprecision(10) << w * h / 2 << endl;
  if (x == w / 2 && y == h / 2) cout << 1 << endl;
  else cout << 0 << endl;
}

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

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

	int K,N;
	cin>>K>>N;

	vector<int>V;

	for(int i = 0;i<N;i++)
	{
		int inp;
		cin>>inp;
		V.push_back(inp);
	}

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

	int MAX = K - V[N-1] + V[0]; //finding distance between last and first segment

	for(int i = 0;i<N-1;i++)
		MAX = max(MAX,V[i+1] - V[i]); //finding the segment to be skipped because atmost 1 segment is skipped

	cout<<K - MAX<<endl;

	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
using namespace std;
 
int cnt,MX;
int M[92][92];
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0 ,-1};
 
void dfs(int y, int x) {
  M[y][x] = 0; cnt++;
 
  int ny, nx, flag=0;
 
  for(int i = 0; i < 4; i++) {
    ny = y + dy[i]; nx = x + dx[i];
 
    if(M[ny][nx]) dfs(ny, nx);
    else flag++;
  }
  if(flag==4)MX=max(MX,cnt);
  M[y][x] = 1; cnt--;
}
 
int main() {
  int m, n;
 
  while(1) {
    cin >> m >> n;
    if(m == 0 && n == 0) break;
 
    for(int i = 0; i <= 91; i++) {
      for(int j = 0; j <= 91; j++) {
    M[i][j] = 0;
      }
    }
 
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= m; j++) {
    cin >> M[i][j];
      }
    }
 
    //int mx = 0;
    MX=0;
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= m; j++) {
    if(M[i][j]) {
      cnt = 0;
      dfs(i, j);
      
    }
      }
    }
 
    cout << MX << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n, k; cin >> n >> k;
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }
  sort(l.begin(), l.end(), greater<int>());
  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += l[i];
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n,k;
vector<int> seq;

bool comp(int a,int b) {
  return a < b;
}

int main() {
  int a,f=0,ans=0;
  while(cin >> n >> k) {
    if(n==0&&k==0) break;
    bool wild = false;
    for(int i=0;i<k;i++) {
      cin >> a;
      if(a!=0) {
        seq.push_back(a);
      }
      else {
        wild = true;
        f=1;
      }
    }
    sort(seq.begin(),seq.end(),comp);


    for(int i=0;i<k-f;i++) {
      bool temp = wild;
      int res = 1;
      for(int j=1;j<k-f;j++) {
        if(seq[i+j] == seq[i+j-1]+1) {
          res++;
        }
        else if(seq[i+j] != seq[i+j-1]+1 && temp == false) {
          break;
        }
        else if(seq[i+j] != seq[i+j-1]+1 && temp == true) {
          res++;
          temp = false;
          if(seq[i+j] == seq[i+j-1]+2) {
            res++;
          }
          else {
            break;
          }
        }
      }
      ans = max(ans,res);
    }
    cout << ans << endl;
    ans = 0;
    seq.clear();
  }
}

Measured memory_bytes: 1352