akhauriyash/Code-Regression huggingface dataset:
n,d = [int(_) for _ in input().split()]
x = [[int(_) for _ in input().split()] for __ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        dist=0
        for k in range(d):
            dist += (x[i][k] - x[j][k])**2
        for k in range(1,200):
            if dist == k**2:
                ans += 1
                break
        dist = 0
print(ans)

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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

typedef long long ll;

int main() {
  ll N, s = 0;
  cin >> N;
  vector<ll> A(N + 1);
  rep(i, N) cin >> A[i], s += A[i];
  ll b = N * (N + 1) / 2;
  if (s % b != 0) return cout << "NO\n", 0;
  ll t = s / b;
  A[N] = A[0];
  rep(i, N) {
    ll d = A[i] + t - A[i + 1];
    if (d < 0 || d % N != 0) return cout << "NO\n", 0;
  }
  cout << "YES\n";
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using lint = long long;
using std::vector;
std::map<lint, int> cnt;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		lint a;
		scanf("%lld", &a);
		cnt[a]++;
	}
	lint ans = 0;
	vector<lint> p;
	for (auto q : cnt) {
		if (q.second >= 4) {
			ans = std::max(ans,q.first*q.first);

		}
		if (q.second >= 2) {
			p.push_back(q.first);
		}
	}
	std::sort(p.begin(), p.end(), std::greater<lint>());
	if (p.size() >= 2) {
		ans = std::max(ans, p[0] * p[1]);
	}
	printf("%lld", ans);
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    string s;
    cin >> s;
    map<char, int> cnt;
    int slen = s.length();
    rep(i, slen){
        cnt[s[i]]++;
    }

    set<pair<char, int>> use;
    for(auto const& e : cnt){
        use.insert(make_pair(e.first, e.second));
    }

    if(cnt.size() == 1){
        cout << 0 << endl;
        return 0;
    }

    int res = 1e6;
    for(auto const& e : use){
        string bufs = s;
        int cnt = 0;
        while(true){
            string news = "";
            rep(i, bufs.length()-1){
                if(bufs[i] == e.first || bufs[i+1] == e.first){
                    news += e.first;
                }else{
                    news += bufs[i];
                }
            }
            bool good = true;
            rep(i, news.length()){
                if(news[i] != e.first){
                    good = false;
                    break;
                }
            }
            cnt++;
            if(good) break;
            bufs = news;
        }
        chmin(res, cnt);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool com_f(map<string,int> :: value_type &i1 ,map<string,int> :: value_type &i2  )
{
return i1.second < i2.second;
}
int main()
{
map<string,int> dif;
int n;
cin>>n;
string arr[n];  
for(int i=0;i<n;i++)
{
cin>>arr[i];
map<string,int> :: iterator itr = dif.find(arr[i]);
if(itr == dif.end()) dif.insert(pair<string,int>(arr[i],1));
else itr->second=itr->second+1;
}
map<string,int> :: iterator largest = max_element(dif.begin(),dif.end(),com_f);
for(map<string,int> :: iterator itr=dif.begin();itr != dif.end(); ++itr)
{
  if(itr->second==largest->second){
  cout<<itr->first<<endl;
  }
}
return 0;
}



Measured memory_bytes: 26752
#define _CRT_SECURE_NO_WARNINGS


#include <stdio.h>

int main()
{
	int a, b, c, d;
	int N;
	scanf("%d",&N);
	
	a = N / 1000;
	b = (N - (a * 1000)) / 100;
	c = (N - (a * 1000) - (b * 100)) / 10;
	d = N - (a * 1000) - (b * 100) - (c * 10);
	if (a == b&& b == c)
	{
		printf("Yes");

	}
	else if (b == c&& c == d)
	{
		printf("Yes");

	}
	else
	{
		printf("No");
	}
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>

int main() {
	long long int w, h, x, y; std::cin >> w >> h >> x >> y; 
	std::cout << std::setprecision(15) << std::fixed;
	if (x * 2 == w && y * 2 == h) {
		std::cout << w * h / 2.0 << " 1\n";
	}
	else {
		std::cout << w * h / 2.0 << " 0\n";
	}
}



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

struct TPond
{
	int DownPoint;
	int Surface;
};

void ConstructPond(vector<TPond> &PondRow, stack<int> &DownPointRow, int InputCount)
{
	TPond Pond;
	Pond.DownPoint = DownPointRow.top();
	Pond.Surface = InputCount - DownPointRow.top();
	//????????´???????±????????????§???????±????????????????????????°?±?list???????????????
	//????????´???????±????????????§???????±????????????????????????°????????´???????±???????????????????
	while(!PondRow.empty() && Pond.DownPoint < PondRow.back().DownPoint){
		Pond.Surface += PondRow.back().Surface;
		PondRow.pop_back();
	}
	PondRow.push_back(Pond);
	DownPointRow.pop();
	return;
}

void Output(vector<TPond> PondRow)
{
	//?????¢???????±???????
	int SumOfSurface = 0;
	for(int i = 0; i < PondRow.size(); i++){SumOfSurface += PondRow[i].Surface;}
	//?????¢?????¨??°??¨?????????????????¢??????????????????
	cout << SumOfSurface << endl; 
	cout << PondRow.size();
	for(int i = 0; i < PondRow.size(); i++){cout << ' ' << PondRow[i].Surface;}
	cout << endl;
	return;
}

int main()
{
	//?±?(????????????????????°??¨??¢???????????±?????????)????????????list???????????????
	vector<TPond> PondRow;
	//????????????????????°????????????stack???????????????
	stack<int>   DownPointRow;
	//????????????????????°???????????????????????????????????°???????????????
	int InputCount = 0;
	while(true){
		//??????????????????????????\???????????\?????????
		char Input;
		cin >> Input;
		if(cin.good() == false){break;}
		InputCount += 1;
		//???????????\???????????????DownPointRow???????????????
		//???????????\????????????????????´?????????????????????????±?????§??????????
		if(Input == '\\'){
			DownPointRow.push(InputCount);
		}else if(Input == '/' && !DownPointRow.empty()){
			ConstructPond(PondRow, DownPointRow, InputCount);
		}
	}
	Output(PondRow);
	return 0;
}

Measured memory_bytes: 1284
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var X = long.Parse(inputs[1]);
        inputs = Console.ReadLine().Split(' ');
        var x = new long[N];
        for (int i = 0; i < N; i++)
        {
            x[i] = long.Parse(inputs[i]);
        }

        x = x.OrderBy(xd => xd).ToArray();
        var d = new long[N];
        // スタート地点から、最初、あるいは末尾までの移動する最大公約数
        var gcd = Math.Max(Math.Abs(x.First() - X), Math.Abs(x.Last() - X));
        for (int i = 1; i < N; i++)
        {
            d[i] = Math.Abs(x[i] - x[i - 1]);
            gcd = Gcd(d[i], gcd);
        }
        Console.WriteLine(gcd);
    }

    /**
     * 最小公倍数
     * <see cref="https://qiita.com/gushwell/items/f08d0e71fa0480dbb396"/>
     */
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    /**
     * ユークリッド互除法(最大公約数)
     * <see cref="https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486"/>
     */
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}



Measured memory_bytes: 26592
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      
      int a = sc.nextInt();
      HashSet<Integer> hs = new HashSet<Integer>();
      while(!hs.contains(a)) {
         hs.add(a);
         if(a % 2 == 1) {
            a = 3 * a + 1;
         }
         else {
            a /= 2;
         }
      }
      System.out.println(hs.size() + 1);
   }
}

Measured memory_bytes: 23636
#include <iostream>
#include <cassert>
#include <cmath>
//#define NDEBUG
int main(void){
	using namespace std;
	static const int INPUT_R_MAX = 10000;
	static const int INPUT_R_MIN = 0;
	double input_r = 0;
	double area = 0;	    	/* 面積 */
	double circumference = 0;	/* 円周 */

	cin >> input_r;             /* 半径 */

	/* 入力値の前提条件 */
	assert (INPUT_R_MIN <= input_r && input_r <= INPUT_R_MAX);

	/* Calculation */
	area = input_r*input_r*M_PI;
	circumference = input_r*2*M_PI;

    /* Output */
	cout << fixed << area << " " << circumference << endl;
	return 0;
}




Measured memory_bytes: 3256
#include <stdio.h>
#include <stdlib.h>

typedef struct {int id, solved, penalty;} Team;

int compare(const void *a, const void *b) {
	const Team ta = *(Team *)a, tb = *(Team *)b;

	if (ta.solved != tb.solved)
		return tb.solved - ta.solved;
	if (ta.penalty != tb.penalty)
		return ta.penalty - tb.penalty;
	return ta.id - tb.id;
}

int main(void) {
	int i;
	int t, p, r;

	while (scanf("%d %d %d", &t, &p, &r), t) {
		Team team[50] = {0};
		int wrong[50][10] = {0};

		for (i = 0; i < t; i++)
			team[i].id = i + 1;

		for (i = 0; i < r; i++) {
			int tid, pid, t;
			char mes[10];

			scanf("%d %d %d %s", &tid, &pid, &t, mes);
			tid--;
			pid--;

			if (mes[0] == 'C') {
				team[tid].solved++;
				team[tid].penalty += wrong[tid][pid] * 1200 + t;
			} else
				wrong[tid][pid]++;
		}

		qsort(team, t, sizeof(Team), &compare);

		for (i = 0; i < t; i++)
			printf("%d %d %d\n", team[i].id, team[i].solved, team[i].penalty);
	}

	return 0;
}

Measured memory_bytes: 1040
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Data.Maybe (fromJust)
import qualified Data.ByteString.Char8 as S8
import qualified Data.Vector as V
getInt :: IO Int
getInt = (fst .fromJust . S8.readInt) <$> S8.getLine
getInts :: IO [Int]
getInts = map (fst .fromJust . S8.readInt) . S8.words <$> S8.getLine
main = do
  n <- getInt
  as <- getInts
  print $ solve n as
  return ()

solve :: Int -> [Int] -> Int
solve n as = (`div`2) $ V.sum $ V.zipWith f (V.fromList [1..n]) arr
  where
    arr = V.fromList as
    f ix val | ix  == arr V.! (val - 1) = 1
             | otherwise = 0


Measured memory_bytes: 10620
n = int(input())
h = list(map(int, input().split()))
dp = [10 ** 18 for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    dp[i] = min(
        abs(h[i]-h[i-1]) + dp[i-1],
        abs(h[i]-h[i-2]) + dp[i-2])
print(dp[-1])

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

int main() {
	double r;
	cin >> r;
	double p = acos(-1);;
	printf("%.10lf ", r * r * p);
	printf("%.10lf\n", 2 * r * p);
	return 0;
}

Measured memory_bytes: 1240
# 入力
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
result=0

# 処理
# 肉が凍っていて，その温度が 0 ℃より小さいとき
if A<0:
    # C 秒で 1 ℃温まる (0秒含む）
    result+=C*-(A)
    # 肉が凍っていて，その温度がちょうど 0 ℃のとき
    result+=D

    result+=B*E
# 肉が凍っていないとき
elif A==0:
    result=+E
    result+=B*E
else:
    result+=(B-A)*E



print(result)


Measured memory_bytes: 5592
from collections import deque
h,w = map(int,input().split())
G = []
G.append(['']*(w+2))
for i in range(h):
    G.append([''] + list(input()) + [''])
G.append(['']*(w+2))

dist = [[-1]*(w+2) for i in range(h+2)]

dist[1][1] = 1
que = deque([(1,1)])

while que:
    v = que.popleft()
    compass = [(v[0],v[1]-1),(v[0]+1,v[1]),(v[0],v[1]+1),(v[0]-1,v[1])]
    for i in compass:
        if G[i[0]][i[1]] == '.' and dist[i[0]][i[1]] == -1:
            dist[i[0]][i[1]] = dist[v[0]][v[1]] + 1
            que.append(i)

if dist[h][w] == -1:
    print(-1)
    exit()

cnt = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if G[i][j] == '#':
            cnt += 1

print(h*w-cnt-dist[h][w])

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

#define _ << ": " <<
#define watch1(var1) cerr << (#var1) _ var1 << '\n'
#define watch2(var1, var2) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << '\n'
#define watch3(var1, var2, var3) cerr << (#var1) _ var1 << ", " << (#var2) _ var2 << ", " << (#var3) _ var3 << '\n'
#define wloop(size, arr) cerr << (#arr) << ": "; for (int i = 0; i < int(size); i++) cerr << arr[i] << " \n"[i+1 == int(size)]

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ll long long
#define ints(a...) int a; read(a)
#define IN(a) for (auto &it : a) cin >> it

int dp[100001];

void solve() {
    ints(n);
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) read(v[i]);

    dp[2] = abs(v[2] - v[1]);
    for (int i = 3; i <= n; i++) {
        dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
    }

    show(dp[n]);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <tuple>
#include <stack>
using namespace std;
typedef long long ll;

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

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll a,b,c,d,e,m,n,o1=0,o2=0,o3=0,p,q,r,x,y,z,max1=0,ans=0,o=0;
    string s,t,u;
    cin>>a>>s;
    for(ll i=0;i<10;i++){
        for(ll j=0;j<10;j++){
           for(ll k=0;k<10;k++){
               o1=0;
               o2=0;
               o3=0;
               for(ll l=0;l<a;l++){
                    if(s[l]-48==i&&o1==0){
                        o1=1;
                        continue;
                    }
                    if(s[l]-48==j&&o1==1&&o2==0){
                        o2=1;
                        continue;
                    }
                    if(s[l]-48==k&&o1==1&&o2==1){
                        o3=1;
                        break;
                    }
               }
               if(o3==1&&o1==1&&o2==1)o++;
            }
        }   
    }
    
    cout<<o<<endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  int k, n;
  cin >> k >> n;
  arr(a,n);

  int tmp=0;
  rep(i,n){
    if(i!=n-1){
      chmax(tmp, a[i+1]-a[i]);
    } else {
      chmax(tmp, k+a[0]-a[i]);
    }
  }
  prt(k-tmp);
}


Measured memory_bytes: 1152
import numpy as np

N, D = map(int, input().split())
xy = np.array([list(map(int, input().split())) for xy in range(N)])
o = np.array([0, 0])
count = 0

for i in range(N):
    if np.linalg.norm(xy[i] - o) <= D:
        count += 1
    else:
        pass

print(count)


Measured memory_bytes: 66512
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define MAX 500000
using namespace std;

long long factorial[MAX] = {0}, finverse[MAX] = {0},
          inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if(n == k && n == 0) return 1;
  if(n < 0 || k < 0 || n < k) return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] %
         N;
}

long long n;
string s;

long long solve();

int main() {
  cin >> n >> s;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long cnt = 1, ans = 1;
  smodfact();
  if(s[0] == 'W' || s[2 * n - 1] == 'W') return 0;
  ans = factorial[n];
  for(int i = 1; i < 2 * n; ++i)
    if(cnt % 2 == (s[i] == 'W'))
      ++cnt;
    else
      (ans *= cnt--) %= N;
  if(cnt != 0) return 0;
  return ans;
}

Measured memory_bytes: 12292
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int n, h[100010], left, cnt = 0, maxcnt = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> h[i];
  left = h[0];
  for (int i = 1; i < n; ++i)
  {
    if (left >= h[i])
    {
      ++cnt;
    }
    else
    {
      if (maxcnt < cnt) maxcnt = cnt;
      cnt = 0;
    }
    left = h[i];
  }
  if (maxcnt < cnt) maxcnt = cnt;

  cout << maxcnt;
}


Measured memory_bytes: 3856
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h=in.nextInt();
        int n=in.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
        }
        //Arrays.sort(a);
        for(int i=n-1;i>=0;i--){
            h-=a[i];
            if(h<=0){
                break;
            }
        }
        if(h<=0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll inf = LONG_LONG_MAX;
const int nax = 1e5+200;
const double mpi = acos(-1);
const double eps= 1e-10;

int dr[] = {1,-1,0, 0,1,-1,-1, 1}; // trick to explore an implicit 2D grid
int dc[] = {0, 0,1,-1,1, 1,-1,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cout<< setprecision(20)<< fixed;
  double a, b;
  ll n;
  cin>> a>> b>> n;
//  ll maxi = 0;
//  ll pos = 0;
//  forn(i,n+1){
//    ll cur = floor(a*i/b) - ll(a)*floor(i/b);
//    if(maxi<cur){
//      maxi = cur;
//    }
//  }
//
//  forn(i,n+1){
//    ll cur = floor(a*i/b) - ll(a)*floor(i/b);
//    if(maxi==cur){
//      d(i);
//    }
//  }
  ll ans = -1;
  if(b>n){
    ans= n;
  }else{
    ans = (ll(b)-1)%n;
  }
  ans = floor(a*ans/b) - ll(a)*floor(double(ans)/b);
  cout<< ans<<el;
}




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

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) (v.size())
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;

int main(int argc, char *argv[]) {
    
    LL X;
    cin >> X;
    
    LL ans = X / 11 * 2;
    if (X % 11 == 0) {
        ;
    }
    else if (X % 11 > 6) {
        ans += 2;
    }
    else {
        ans += 1;
    }
    
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for (int i=0;i<n;i++)
    {
        cout<<s[i]<<t[i];
    }
}

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

using namespace std;

#define loop(n) for(int lp=0; lp<(n); lp++)
#define ascent(i, a, b)  for(int (i)=(a); (i)<(b); (i)++)
#define descent(i, a, b) for(int (i)=(a); (i)<(b); (i)--)

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

  loop(n) {
    int y, m, d;
    cin >> y >> m >> d;

    int ans = 196471;
    if(y%3 == 0) {
      ans -= (m-1)*20+d;
    }
    else {
      ans -= d;
      for(int i = m-1; i > 0; i --) {
	if(i%2 == 0) { ans -= 19; }
	else { ans -= 20; }
      }
    }

    for(int i = y-1; i > 0; i --) {
      if(i%3 == 0) {
	ans -= 20*10;
      }
      else {
	ans -= 20*5+19*5;
      }
    }

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

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long int N;
  cin >> N;
  vector<long long int> A(N), B(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> B[i];
  long long int d = 0;
  for(int i = 0; i < N; ++i){
    long long int t = B[i] - A[i];
    if(t > 0) t /= 2;
    d += t;
  }
  if(d < 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 384
n=int(input())
s=[]
for _ in range(n):
	s.append(str(input()))

counter={}
ans=0
for i in range(n):
	ss = sorted(s[i])
	ss=("").join(ss)
	if ss not in counter:
		counter[ss]=0
	else:
		counter[ss]+=1
		ans+=counter[ss]

print(ans)

Measured memory_bytes: 29176
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

ll n, k, sum;
V<ll> a;

bool need(const int &mid) {
    bitset<5005> b(1);
    rep(i, n) if(i != mid) b |= b << a[i];
    FOR(i, max(0LL, k - a[mid]), k) if(b[i]) return true;
    return false;
}

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

    cin >> n >> k;
    a.resize(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(ALL(a));
    ll ok = -1, ng = n;
    while(ok + 1 < ng)
        (need(ng + ok >> 1) ? ng : ok) = ng + ok >> 1;
    cout << ng << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    d = []
    for i in range(n):
        tmp = a[i]
        d.append(tmp)
        for j in range(i + 1, n):
            tmp += a[j]
            d.append(tmp)

    def maxbit(a, idx, k):
        first1 = [[] for _ in range(41)]
        for ai in a:
            for i in range(40, -1, -1):
                if ai >> i & 1:
                    first1[i].append(ai)

        for i in range(idx - 1, -1, -1):
            if len(first1[i]) >= k:
                return first1[i], i

        return first1[idx], -1

    idx = 40
    while True:
        tmp, idx = maxbit(d, idx, k)
        if idx == -1:
            break
        d = tmp

    bit1 = [0 for _ in range(41)]
    for di in d:
        for i in range(41):
            if di >> i & 1:
                bit1[i] += 1

    ans = 0
    for i, bi in enumerate(bit1):
        if bi >= k:
            ans += pow(2, i)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 340384
#include <bits/stdc++.h>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;

int dp[102][100005];

signed main(){
	int n, wt;
	cin>>n>>wt;
	
	int w[n+1], v[n+1];
	for(int i=1; i<=n; i++){
		cin>>w[i]>>v[i];
	}
	
	for(int i=0; i<=n; i++){
		for(int j=0; j<100004; j++){
			dp[i][j]=1000000004;
		}
	}
	
	dp[0][0]=0;
	int ans=0;
	for(int i=1; i<=n; i++){
		for(int j=0; j<=100000; j++){
			if(dp[i-1][j]==1000000004)
				continue;
			
			dp[i][j+v[i]]=min( dp[i-1][j]+w[i], dp[i][j+v[i]]);
			dp[i][j]=min(dp[i-1][j], dp[i][j]);
			
			if(dp[i][j+v[i]]<=wt){
				ans=max(ans, j+v[i]);
			}
		}
	}
	
	cout<<ans;
	
    return 0;
}

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

int main() {
  ll a,b,c,d; cin >> a >> b >> c >> d;
  ll L = c * d / gcd(c,d);
  
  ll x = ((a-1)/c) + ((a-1)/d) - ((a-1)/L);
  ll y = (b/c) + (b/d) - (b/L);
  
  cout << (b-a+1) - (y-x) << endl;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<int> A(n, 0);
	vector<bool> check(n, true);
	for (int i=0; i<n; i++) cin >> A[i];
	map<int, int> count;
	int maxA = 0;
	for (int i=0; i<n; i++) {
		maxA = max(maxA, A[i]);
		count[A[i]]++;
	}

	sort(A.begin(), A.end());
	for (int i=0; i<n; i++) {
		int a = A[i];
		for (int i=2; i*a<=maxA; i++) {
			if (binary_search(A.begin(), A.end(), i*a)){
				auto itr = lower_bound(A.begin(), A.end(), i*a);
				int dist = itr - A.begin();
				check[dist] = false;
			}
		}
		if (!check[i]) continue;
		if (count[a]>1) {
			check[i] = false;
			continue;
		}
	}
	int ret = 0;
	for (int i=0; i<n; i++) ret += check[i];
	cout << ret << endl;
	return 0;
}

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

using namespace std;

int main(){
        int N;
        cin>>N;
        if((N%10==(N/10)%10&&(N/10)%10==(N/100)%10)||((N/10)%10==(N/100)%10&&(N/100)%10==(N/1000)%10)){
                cout<<"Yes"<<endl;
        }
        else{
                cout<<"No"<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <math.h>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int,Int>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

Int LCM(Int a, Int b){
    return a*b/GCD(a,b);
}


int main() {
    Int N;
    cin >> N;

    vi X,L;
    X = vi(N);
    L = vi(N);


    vector<pair<Int,Int>> Ps;
    rep(i,N){
        cin >> X[i] >> L[i];
        Ps.emplace_back(make_pair(X[i]+L[i],X[i]-L[i]));
    }

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

    Int ans = 0;
    Int now = -1000000000;

    rep(i,N){
        if(now <= Ps[i].second){
            ans++;
            now = Ps[i].first;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,r=0,w1=0,w=0,i;
    cin >> a ;
    string s;
    cin >> s;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='W')
            w++;
            else
                r++;
    }
    for(i=0;i<s.length()-w;i++)
    {
        if(s[i]=='W')
            w1++;
    }
    cout << min(w1,w) << endl;
}


Measured memory_bytes: 3752
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int d[55];
int n, k;

long long ans = 0;

void solve(int left, int right) {
		long long ret = 0;
		vector<int> taken;
		for(int i=0; i<left; i++) taken.push_back(d[i]);
		for(int i=n-1; i>=n-right; i--) taken.push_back(d[i]);
		sort(taken.begin(), taken.end());
		assert(taken.size() <= k);
		int not_taken = 0;
		for(int i=0; i<taken.size(); i++) {
			if(taken[i] < 0 && not_taken + left + right < k ) {
				not_taken++;
				continue;
			}
			ret += taken[i];
		}
		ans = max(ans, ret);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> d[i];
	for(int left = 0; left <= k; left ++) {
		for(int right = 0; right <= k; right ++) {
			if(left + right > k || left + right > n) continue;
			solve(left, right);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
N, Q = [int(i) for i in input().split()]
S = list(input())
term = [[int(i) for i in input().split()] for x in range(Q)]
ACs = [0 for i in range(N)] 
ans = []

for i in range(N-1):
    if (S[i+1] == 'C' and S[i] == 'A'):
        ACs[i+1] = ACs[i] + 1
    else:
        ACs[i+1] = ACs[i] + 0
    
for i in range(len(term)):
    ans.append((ACs[term[i][1] - 1]) - (ACs[term[i][0] - 1]))

for i in range(Q):
        print(ans[i])


Measured memory_bytes: 30568
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

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

int main(){
	int n;
	cin>>n;
	
	vector<llong> a(n+3);
	REP(i,n) cin>>a[i+1];
	a[n+1]=1;
	a[n+2]=INF;
	
	llong ans=1000;
	llong num=0;
	for(int i=1;i<=n;++i){
		if(a[i]<a[i+1]){
			num+=ans/a[i];
			ans%=a[i];
		}else if(a[i]>=a[i+1]){
			ans+=a[i]*num;
			num=0;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int n,m,s;
int main()
{
 cin>>n;
 for (int i=1;i<=n;i++)
 {
 	cin>>m;
 	s+=m;
 }
 if (s%2==0) cout<<"YES"<<endl; else cout<<"NO"<<endl;
 return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    A, B, K = map(int, input().split())

    for i in range(K):
        if i % 2 == 0:
            if A % 2 == 1:
                A -= 1
            B += A // 2
            A //= 2
        else:
            if B % 2 == 1:
                B -= 1
            A += B // 2
            B //= 2

    print(f"{A} {B}")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
N=int(input())

t0=0
x0=0
y0=0

ans="Yes"

for i in range(N):
    t,x,y=map(int,input().split())
    d=abs(x-x0)+abs(y-y0)
    dt=t-t0
    if not (d<=dt and (dt-d)%2==0):
        ans="No"
    t0=t
    x0=x
    y0=y

print(ans)

Measured memory_bytes: 3316
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int a, b;

	cin >> a >> b;

	for (int i = b * 10; i < b * 10 + 10; ++i) {
		if ((i * 8) / 100 == a && (i * 10) / 100 == b) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=[int(x) for x in input().split()]
s=sum(a)

candidates=set()
for i in range(1,int(s**0.5)+2):
  if s%i==0:
    candidates.add(i)
    candidates.add(s//i)

ans=0
for cdd in candidates:
  div_cdd=[0]*n
  for i in range(n):
    div_cdd[i]=a[i]%cdd
  div_cdd=sorted(div_cdd)
  pstv,ngtv=0,-sum(div_cdd)
  # calc need
  if pstv==-ngtv:
    ans=max(ans,cdd)
    continue
  for i in range(n):
    pstv+=cdd-div_cdd[-1-i]
    ngtv+=div_cdd[-1-i]
    if pstv==-ngtv: break
  ans=max(ans,cdd) if pstv<=k else ans
    
print(ans)

Measured memory_bytes: 9440
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <ctime>
#include <iomanip>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	a *= 500;
	if (a >= b) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
int x;
int y;
int s;
int a[14][14];
char b;
int c;
int d;
c=0;
while(c<14){
d=0;
while(d<14){
a[c][d]=0;
d=d+1;}
c=c+1;}
while(cin>>x>>b>>y>>b>>s){
if(s==1){
a[x+2][y+2]=a[x+2][y+2]+1;
a[x+1][y+2]=a[x+1][y+2]+1;
a[x+3][y+2]=a[x+3][y+2]+1;
a[x+2][y+1]=a[x+2][y+1]+1;
a[x+2][y+3]=a[x+2][y+3]+1;}
if(s==2){
a[x+1][y+1]=a[x+1][y+1]+1;
a[x+1][y+2]=a[x+1][y+2]+1;
a[x+1][y+3]=a[x+1][y+3]+1;
a[x+2][y+1]=a[x+2][y+1]+1;
a[x+2][y+2]=a[x+2][y+2]+1;
a[x+2][y+3]=a[x+2][y+3]+1;
a[x+3][y+1]=a[x+3][y+1]+1;
a[x+3][y+2]=a[x+3][y+2]+1;
a[x+3][y+3]=a[x+3][y+3]+1;}
if(s==3){
a[x][y+2]=a[x][y+2]+1;
a[x+1][y+1]=a[x+1][y+2]+1;
a[x+1][y+2]=a[x+1][y+2]+1;
a[x+1][y+3]=a[x+1][y+3]+1;
a[x+2][y]=a[x+2][y]+1;
a[x+2][y+1]=a[x+2][y+1]+1;
a[x+2][y+2]=a[x+2][y+2]+1;
a[x+2][y+3]=a[x+2][y+3]+1;
a[x+2][y+4]=a[x+2][y+4]+1;
a[x+3][y+1]=a[x+3][y+1]+1;
a[x+3][y+2]=a[x+3][y+2]+1;
a[x+3][y+3]=a[x+3][y+3]+1;
a[x+4][y+2]=a[x+2][y+2]+1;}
}
int e;
int f;
e=a[2][2];
f=0;
c=2;
while(c<12){
d=2;
while(d<12){
if(e<a[c][d]){e=a[c][d];}
if(a[c][d]==0){f=f+1;}
d=d+1;}
c=c+1;}
cout <<f<<endl<<e<<endl;}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A >= B){
    for(int i = 0;i < A;i++){
      cout << B;
    }
  }
  else{
    for(int i = 0;i < B;i++){
      cout << A;
    }
  }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
struct  node
{
	string s;
	int l;
};
queue<node>q;
int  main(){
	int k;
	cin>>k;
	for(int i=1;i<=9;++i){
		node nm;
		nm.s+=i+'0';
		q.push(nm);
	}
	int cnt=1;
	while(!q.empty()){
		node te=q.front();
		q.pop();
		if(cnt==k){
			cout<<te.s;
			return 0;
		}
		cnt++;
		node tte=te;
		int f=0;
		for(char i='0';i<='9';++i){
			if(i<=tte.s[tte.s.length()-1]+1&&i>=tte.s[tte.s.length()-1]-1){
				//cnt++;
				tte.s+=i;
				q.push(tte);
				//cout<<tte.s<<",";
				tte=te;
				
			}
		}
		//if(f)break;
	}
	return 0;
}

Measured memory_bytes: 15360
/* vishal shrivastava
     185023
     nit hamirpur
   */
  #include <bits/stdc++.h>
  using namespace std;
  #define minpq priority_queue <int, vector<int>, greater<int> >;
  #define maxpq  priority_queue <int>;
  #define F first
  #define S second
  #define mp make_pair
  #define pb push_back
  #define f(i,x,n) for(int i=x;i<n;i++)
  #define all(c) c.begin(),c.end()
  #define ll long long
  #define pll pair<ll,ll>
  #define pii pair<int,int>
  const int mod = 1e9+7, N = 1e5 + 10;
  int solve()
  {
     int k,c;
     cin>>k>>c;
     for(int i=max(-1000000,c-k+1);i<=min(1000000,c+k-1);i++)
     {
         cout<<i<<" ";
     }

  }

  int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int test=1;
    //cin>>test;
    while(test--)
    {
      solve();
    }
  }


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        hs: [i64; n],
    }
    let mut max = 0;
    let mut ans = 0;
    for h in hs {
        if h >= max {
            ans += 1;
            max = h;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }


void solve() {
    int k, a, b;
    cin >> k >> a >> b;

    while (a % k) {
        a++;
    }
    cout << ((a <= b) ? "OK" : "NG");
}


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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

int main(){
	static char x[1001];
	while (1) {
		cin.getline(x,sizeof(x));
		int sum = 0;
		for (int i = 0; i < strlen(x); ++i)
			sum += x[i] - '0';
		if (sum == 0)
			break;
		else 
			cout << sum << endl;
	}
	return 0;
}



Measured memory_bytes: 3092
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int main()
{
	char str[1001];
	char *p;
	fgets(str,sizeof(str),stdin);
	while(1)
	{
		if(strstr(str,"apple")==NULL)break;
		p=strstr(str,"apple");
		*p='t';
		*(p+1)='i';
		*(p+2)='n';
		*(p+3)='k';
		*(p+4)='o';
	}
	while(1)
	{
		if(strstr(str,"peach")==NULL)break;
		p=strstr(str,"peach");
		*p='a';
		*(p+1)='p';
		*(p+2)='p';
		*(p+3)='l';
		*(p+4)='e';
	}
	while(1)
	{
		if(strstr(str,"tinko")==NULL)break;
		p=strstr(str,"tinko");
		*p='p';
		*(p+1)='e';
		*(p+2)='a';
		*(p+3)='c';
		*(p+4)='h';
	}
	cout << str;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int K, X; cin >> K >> X;
	rep(i, 2 * K - 1) {
		cout << X - K + 1 + i << " ";
	}
}

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(){
  long long n,ans=0;
  cin >> n;
  int a;
  cin >> a;
  ans=ans+a-1;
  long long ma=1;
  rep(i,n-1){
    int p;
    cin >> p;
    if(p==ma+1){
      ma++;
      continue;
    }
    ans+=(p-1)/(ma+1);
  
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
s = [input() for _ in range(h)]

ans = 0
for i in range(h): ans += s[i].count(".")
dist = [[-1 for _ in range(w)] for _ in range(h)]
dist[0][0] = 1
queue = deque()
queue.append((0,0))
while len(queue) != 0:
    cx,cy = queue.popleft()
    if cx == h-1 and cy == w-1: 
        ans -= dist[cx][cy]
        break
    for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):
        nx,ny = cx+dx,cy+dy
        if 0 <= nx < h and 0 <= ny < w and s[nx][ny] == "." and dist[nx][ny] == -1:
            queue.append((nx,ny))
            dist[nx][ny] = dist[cx][cy] + 1
else:
    ans = -1

print(ans)

Measured memory_bytes: 3316
n = gets.chomp.to_i
w = gets.chomp.split.map(&:to_i)

left = 0
right = w.reduce(&:+)

ans = right
n.times do |i|
  left += w[i]
  right -= w[i]
  diff = (left - right).abs
  ans = diff if ans > diff
end

puts(ans)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll N,K;
    cin >> N >> K;
    ll a = N%K;
    if (a == 0) cout << 0 << endl;
    else cout <<min(a,K-a) << endl; 
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}
int main(){
	int n,i,r=1,t;
	int arr[999];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",arr+i);
	qsort(arr,n,4,compare);
	t=arr[0];
	for(i=1;i<n;i++){
		if(t!=arr[i]){
			t=arr[i];
			r++;
		}
	}
	printf("%d\n",r);
	return 0;
}


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

using namespace std;

using Point = complex<double>;

Point rotate(Point origin, double degree) {
    return origin * polar(1.0, 2 * M_PI * degree);
}

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    cout << setiosflags(ios::fixed) << setprecision(10) << abs(rotate(Point(0, A), (H + M / 60.0) / 12.0) - rotate(Point(0, B), M / 60.0)) << endl;
    return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int mod = 1000000007;

int N; long long K;

struct mat{
	long long a[55][55];
	mat operator *(mat t){
		mat r;
		for (int i=0;i<N;i++) for (int j=0;j<N;j++){
			r.a[i][j] = 0;
			for (int k=0;k<N;k++){
				r.a[i][j] = (r.a[i][j] + a[i][k] * t.a[k][j]) % mod;
			}
		}
		return r;
	}
};

int main()
{
	mat a,e;
	scanf ("%d %lld",&N,&K);
	for (int i=0;i<N;i++){
		for (int j=0;j<N;j++){
			a.a[i][j] = e.a[i][j] = 0;
			scanf ("%d",&a.a[i][j]);
		}
		e.a[i][i] = 1;
	}

	while (K){
		if (K & 1) e = e * a;
		a = a * a;
		K /= 2;
	}

	long long ans = 0;
	for (int i=0;i<N;i++) for (int j=0;j<N;j++) ans = (ans + e.a[i][j]) % mod;
	printf ("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 256
N,W=map(int,input().split())

items=[]

for i in range(N):
    items.append(list(map(int,input().split())))
    
dp = [[0 for i in range(10001)] for j in range(110)]

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


print(dp[N][W])


Measured memory_bytes: 43208
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, K;
    cin >> N >> K;
    cout << (N % K == 0 ? 0 : 1) << endl;
    return 0;
}

Measured memory_bytes: 768