akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int a, b;
    
    while (true) {
        cin >> a >> b;
        if ( a == 0 && b == 0 ) {
            break;
        } else if ( a > b ) {
            cout << b << " " << a << endl;
        } else {
            cout << a << " " << b << endl;
        }
    }
}

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


int main(){
   bool is_prime[100000];
   is_prime[0]=is_prime[1]=false;
   for(int i=2;i<100000;i++)
      is_prime[i]=true;
   for(int i=2;i*i<100000;i++){
      if(is_prime[i]){
         for(int j=i*i;j<100000;j+=i){
            is_prime[j]=false;
         }
      }
   }
   while(true){
      int count=0;
      int n;
      cin >> n;
      if(n==0){
         break;
      }else{
         for(int i=2;i<n/2+1;i++){
            if(is_prime[i]&&is_prime[n-i])
                count++;
          }
         cout << count << endl;
      }
   }
   return 0;
}

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

int P(long long p,long long T[], int n, int k)
{
	int i=0,j;
	long long s;
	for(j=0;j<=k-1;j++)
	{
		s=0;
		while(s+T[i]<=p)
		{
			s+=T[i];
			i++;
			if(i==n) return n;
		}
	}
	return i;
}


int main()
{
	int i;
	int n,k;
	long long T[100000];
	long long left=0;
	long long right;
	long long mid;
	int v;
	
	cin >> n;
	cin >> k;
	right=10000*n;
	for(i=0;i<=n-1;i++) cin >> T[i];
	while(right-left>1)
	{
		mid=(right+left)/2;
		v=P(mid,T,n,k);
		if(v>=n) right=mid;
		else left=mid;
	}
	cout << right << endl;
	return 0;
}

Measured memory_bytes: 3872
a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]

ans = min(a) + min(b)

for i in range(m):
    x = xyc[i][0] - 1
    y = xyc[i][1] - 1
    c = xyc[i][2]

    ans = min(ans, a[x] + b[y] - c)

print(ans)


Measured memory_bytes: 82156
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ld a, b, h, m;
	cin >> a >> b >> h >> m;

	setp(15);
	ld x = (h * 60 - m * 11) / 12 / 60 * 2 * PI;
	//co(x);
	co(sqrt(a * a + b * b - 2 * a * b * cos(x)));

	return 0;
}


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

int r[55];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        r[a]++; r[b]++;
    }
    for(int i=1;i<=n;i++){
        cout<<r[i]<<endl;
    }
}


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

PY.sort(key=lambda x:(x[1],x[2]))
PY[0][2]=1
cnt=1
for i in range(M-1):
    if PY[i+1][1]==PY[i][1]:
        cnt+=1
        PY[i+1][2]=cnt
    else:
        cnt=1
        PY[i+1][2]=cnt
PY.sort(key=lambda x:x[0])
for i in range(M):
    print((("0"*6)+str(PY[i][1]))[-6:]+(("0"*6)+str(PY[i][2]))[-6:])

Measured memory_bytes: 31252
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int t=n;
  bool b=false;
  for (int i=0;i<=n/4;i++){
    for (int j=0;j<=n/7;j++){
      if(4*i+7*j==n){
        b=true;
        break;
      }
    }
  }
  if(b){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#! env python
# -*- coding: utf-8 -*-

import os
import sys
from itertools import repeat


# ac_py.main
# Date: 2020/06/13
# Filename: main 
# Author: acto_mini

def main():
    H, W = map(int, input().split())

    S = list()
    ans = list()

    for i in range(H):
        S.append(input())
        ans.append(list(repeat(0, W)))

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                ans[i][j] = "#"

                # 左上
                if i > 0 and j > 0 and ans[i - 1][j - 1] != "#":
                    ans[i - 1][j - 1] += 1
                # 上
                if i > 0 and ans[i - 1][j] != "#":
                    ans[i - 1][j] += 1
                # 右上
                if i > 0 and j < W - 1 and ans[i - 1][j + 1] != "#":
                    ans[i - 1][j + 1] += 1

                # 左
                if j > 0 and ans[i][j - 1] != "#":
                    ans[i][j - 1] += 1
                # 右
                if j < (W - 1) and ans[i][j + 1] != "#":
                    ans[i][j + 1] += 1

                # 左下
                if i < (H - 1) and j > 0 and ans[i + 1][j - 1] != "#":
                    ans[i + 1][j - 1] += 1
                # 下
                if i < (H - 1) and ans[i + 1][j] != "#":
                    ans[i + 1][j] += 1
                # 右下
                if i < (H - 1) and j < W - 1 and ans[i + 1][j] != "#":
                    ans[i + 1][j + 1] += 1

    for i in range(H):
        print(*ans[i], sep="")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 43632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
int col[605][605][2];
int d,e;
vector<P>vec[2];
void dfs(int x,int y,int z,int coll,int D){
    if(col[x][y][z] != -1 && col[x][y][z] != coll) assert(0);
	col[x][y][z] = coll;
	for(int i=0;i<vec[D].size();i++){
		int nx = x+vec[D][i].fi;
		int ny = y+vec[D][i].sc;
		if(0<=nx&&nx<2*n&&0<=ny&&ny<2*n&&col[nx][ny][z]==-1){
			dfs(nx,ny,z,1-coll,D);
		}
	}
}
int main(){
	cin>>n>>d>>e;
	for(int i=-1000;i<=1000;i++){
		for(int j=-1000;j<=1000;j++){
			if(i*i+j*j == d) vec[0].pb(mp(i,j));
			if(i*i+j*j == e) vec[1].pb(mp(i,j));
		}
	}
	rep(i,2*n)rep(j,2*n)col[i][j][0]=col[i][j][1]=-1;
	rep(i,2*n)rep(j,2*n)if(col[i][j][0]==-1) dfs(i,j,0,0,0);
	rep(i,2*n)rep(j,2*n)if(col[i][j][1]==-1) dfs(i,j,1,0,1);
	vector<P>cnt[2][2];
	rep(i,2*n)rep(j,2*n)cnt[col[i][j][0]][col[i][j][1]].pb(mp(i,j));
	rep(i,2)rep(j,2){
		if(cnt[i][j].size()>=n*n){
			rep(k,n*n) cout<<cnt[i][j][k].fi<<" "<<cnt[i][j][k].sc<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 34804
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int) 1e9 : (int) 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
    if (a > b) a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
    if (a < b) a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
    return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
    auto inner = vectors(tail...);
    return vector<decltype(inner)>(x, inner);
}
template <class T, class S> void join(T &a, S terminator) {
    for (auto itr = begin(a); itr != end(a); itr++) {
        if (itr != begin(a) or itr != end(a)) cout << terminator;
        cout << *itr;
    }
    cout << endl;
}
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
auto out(int a, int b) {
    (a > b ? a += 1 : b += 1);
    cout << a << " " << b << endl;
}
vector<int> primeFactors(int n) {
    vector<int> v;
    int i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            v.push_back(i);
            n /= i;
        } else {
            i++;
        }
    }
    v.push_back(n);
    return v;
}

main() {
    int n; cin >> n;
    auto primes = primeFactors(n);
    cout << n << ":";
   join(primes,' ');
}


Measured memory_bytes: 3152
#include<stdio.h>
int main(void)
{
	int t[4][3][10]={0};

	int b,f,r,v,i,j,k,n;

	scanf("%d",&n);

	for(i=0;i<n;i++){
	scanf("%d%d%d%d",&b,&f,&r,&v);
	t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;
	}

	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){

	printf(" %d",t[i][j][k]);
		}
		printf("\n");
		}

	if(i!=3)printf("####################\n");

	}
return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define PP pair<P,P>
using namespace std;

int main(){
    ll a,b,c; cin >>a >> b >> c;
    ll ans=0;
    if(a+b+1>=c) ans=b+c;
    else ans=b+a+b+1;
    cout << ans << endl;
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p = 0;
    cin >> n;
    for(i = 1; i <= n; i++){
        if(i % 3 == 0 || i % 5 == 0){
            sum += i;
        }
    }
    cout << (n*(n+1))/2 - sum;;

    return 0;
}


Measured memory_bytes: 3656
n = int(input())
a = [int(input()) for _ in range(n)]

ans = -1
visited = set()
count = 0
btn = 0
for i in range(n):
  if btn in visited:
    break
  visited.add(btn)
  btn = a[btn]-1
  count += 1
  if btn == 1:
    ans = count
    break

print(ans)


Measured memory_bytes: 89864
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;

    class Program
    {

        static void Main()
        {
            string input = Console.ReadLine();
            string[] input2 = Console.ReadLine().Split(' ');
            int n = int.Parse(input);
            int[] a = new int[n];
            for (int i = 0; i < n-1; i++)
            {
                var x = int.Parse(input2[i]);
                a[x - 1]++;
            }
            var sb = new StringBuilder();
            /*何らかの出力処理*/
            for (int j = 0; j < n; j++)
            {
                sb.AppendLine(a[j].ToString());
            }
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Console.WriteLine(sb.ToString());
            Console.Out.Flush();
        }
    }

Measured memory_bytes: 43644
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);


#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    int n, cnt = 0;
    cin >> n;

    for ( int i = 1; i <= n; i++ ) {
        int a;
        cin >> a;
        cnt += ( a != i );
    }

    if ( cnt > 2 ) cout << "NO";
    else cout << "YES";


    return 0;
}


















Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int H,W,K,i,j,k,l,n=0,m=1,ans=0;
  scanf("%d%d%d",&H,&W,&K);
  char s[H][W+1];
  int a[H][W],f[305];
  f[0]=-1;
  FOR(i,0,H)scanf("%s",s[i]);
  FOR(i,0,H)FOR(j,0,W)if(s[i][j]=='#'){
    f[++n]=i;
    break;
  }
  FOR(i,0,n)FOR(j,0,W){
    FOR(k,f[i]+1,f[i+1]+1)a[k][j]=m;
    if(s[f[i+1]][j]=='#')m++;
    else if(j==W-1)for(l=W-1;l>=0;l--){
      FOR(k,f[i]+1,f[i+1]+1)a[k][l]--;
      if(a[f[i+1]][l]==a[f[i+1]][l-1])break;
    }
  }
  FOR(i,f[n]+1,H)FOR(j,0,W)a[i][j]=a[i-1][j];

  FOR(i,0,H){
    FOR(j,0,W)printf("%d ",a[i][j]);
    printf("\n");
  }
	return 0;
}


Measured memory_bytes: 1152
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()
BC = [LIST() for _ in range(M)]
A.sort(reverse=True)
BC.sort(key=lambda x:-x[1])
# print(A)
# print(BC)
count = 0
ans = 0
while count < N:
	if BC and A[0] < BC[0][1]:  # BCからとる
		if BC[0][0] + count > N:
			ans += BC[0][1] * (N-count)
			count = N
		else:
			count += BC[0][0]
			ans += BC[0][1] * BC[0][0]
		# print(count, ans)
		BC.pop(0)
	else:
		count += 1
		ans += A.pop(0)
		# print(count, ans)
print(ans)


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

int WaitTime(int i) {
  int ans = (i + 9) / 10 * 10;
  return ans;
}

int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;

  int WaitA = WaitTime(A);
  int WaitB = WaitTime(B);
  int WaitC = WaitTime(C);
  int WaitD = WaitTime(D);
  int WaitE = WaitTime(E);
  int LastOrder = max({WaitA - A, WaitB - B, WaitC - C, WaitD - D, WaitE - E});
  cout << WaitA + WaitB + WaitC + WaitD + WaitE - LastOrder << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
        public static void main(String[] args) throws Exception{
            Scanner s = new Scanner(System.in);
            int V = s.nextInt();
            int E = s.nextInt();
            int src = s.nextInt();

            HashMap<Integer, List<int[]>> graph = new HashMap<>(V);
            for(int i = 0; i < V; ++i){
                graph.put(i, new LinkedList<int[]>());
            }

            for(int i = 0; i < E; ++i){
                int x = s.nextInt();
                int y = s.nextInt();
                int weight = s.nextInt();

                graph.get(x).add(new int[] {y, weight});
            }

            int[] dist = new int[V];
            Arrays.fill(dist, Integer.MAX_VALUE);

            PriorityQueue<int[]> queue = new PriorityQueue<>(new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return o1[1] - o2[1];
                }
            });

            queue.offer(new int[]{src, 0});
            dist[src] = 0;

            while(!queue.isEmpty()){
                int[] vertex = queue.poll();

                for(int[] adj : graph.get(vertex[0])){
                    if(dist[adj[0]] > dist[vertex[0]] + adj[1]){
                        dist[adj[0]] = dist[vertex[0]] + adj[1];
                        queue.offer(adj);
                    }
                }
            }

            for(int i = 0; i < V; ++i){
                System.out.println(dist[i] == Integer.MAX_VALUE ? "INF" : dist[i]);
            }
        }
}

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

int main(){
  int n;
  vector< string > sample(4);
  sample[0] = "AC", sample[1] = "WA", sample[2] = "TLE", sample[3] = "RE";
  vector< int > a(4, 0);
  cin >> n;
  while( n-- ){
    string s;
    cin >> s;
    for(int i = 0 ; i < 4 ; i++)
      if( s == sample[i] )
      	a[i]++;
  }
  for(int i = 0 ; i < 4 ; i++)
    cout << sample[i] << " x " << a[i] << endl;
  return(0);
}

Measured memory_bytes: 3636
//
//  main.cpp
//  Digit_Sum_2
//
//  Created by Uttam Datta on 02/06/19.
//  Copyright © 2019 Uttam Datta. All rights reserved.
//

#include <iostream>
using namespace std;

long long int N;

long long int ans(){
    long long int res = 0;
    while(N >= 10){
        if(N % 10 < 9){
            N -= 10;
        }
        N /= 10;
        res += 9;
    }
    res += N;
    return res;
}

int main(){
    cin >> N;
    cout << ans() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

const long long LLINF = 1LL << 60;
#define V_MAX 100010

int main(void) {
	LL N, W;
	cin >> N >> W;

	vector<LL> value(110);
	vector<LL> weight(110);
	rep(i, N) cin >> weight[i] >> value[i];

	vector<vector<LL> > dp(110, vector<LL>(V_MAX,LLINF));
	dp[0][0] = 0;
	for (int v = 1; v <= value[0]; v++) {
		dp[0][v] = weight[0];
	}

	for (int i = 1; i < N; i++) {
		for (int v = 0; v < V_MAX; v++) {
			if (v - value[i] >= 0) {
				dp[i][v] = min(dp[i - 1][v - value[i]] + weight[i], dp[i - 1][v]);
			}
			else {
				dp[i][v] = dp[i - 1][v];
			}
		}
	}

	LL ans = 0LL;
	for (int v = 0; v < V_MAX; v++) {
		if (dp[N-1][v] <= W) {
			ans = v;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 87424
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
#define mod      1000000007
#define first    ff
#define second   ss
#define pi       acos(-1.0)
#define test     int t;cin>>t;while(t--)
typedef long long ll;
using namespace std;
vector<int>node[10001];
ll bigmod(ll a,ll b)
{
    ll  res=1;
    a=a%mod;
    if(a==0)
        return 0;
    while(b>0)
    {

           if(b%2)
            res=(res*a)%mod;
            b=b>>1;
            a=(a*a)%mod;
    }
    return res;
}
int main()
{      


     ios::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
     int n;
     cin>>n;

     ll ans=(bigmod(10,n)-(2*bigmod(9,n))%mod+bigmod(8,n))%mod;
     if(ans<0)
        cout<<ans+mod<<endl;
     else
     cout<<ans<<endl;

      return 0;
    
 }   

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

constexpr double PI = 3.1415926535897932384626433832795;
double ans;
Int n;
using P = pair<double, double>;
vector<P> v;

double dot(P a, P b){
	return a.first * b.first + a.second * b.second;
}

double norm(P a){
	return sqrt(a.first * a.first + a.second * a.second);
}

P operator+(P a, P b){
	return P(a.first + b.first, a.second + b.second);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	v.resize(n);
	for(Int i=0; i<n; ++i){
		double x, y;
		cin >> x >> y;
		v[i] = P(x, y);
	}
	for(Int i=0; i<5e6; ++i){
		P x = P(cos(2*PI*5e-6*i), sin(2*PI*5e-6*i));
		P w = P(0, 0);
		for(Int j=0; j<n; ++j){
			if(dot(x, v[j]) >= 0.0){
				w = w + v[j];
			}
		}
		ans = max(ans, norm(w));
	}
	cout << fixed << setprecision(15) << ans << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
	int x;
	int y;
} POSITION;

int main() {
	int W, H;
	while (cin >> W >> H, W + H != 0) {
		bool board[W][H];
		vector<POSITION> movable;
		POSITION myPosition;
		int ans = 1;
		for (int y = 0; y < H; y++) {
			string str;
			cin >> str;
			for (int x = 0; x < W; x++) {
				switch (str[x]) {
				case '.': {
					board[x][y] = true;
					break;
				}
				case '@': {
					board[x][y] = false;
					myPosition.x = x;
					myPosition.y = y;
				}	
				case '#': {
					board[x][y] = false;
					break;
				}
				}
			}
		}
		if (myPosition.x - 1 >= 0 && board[myPosition.x - 1][myPosition.y]) {
			movable.push_back( {myPosition.x - 1, myPosition.y} );
			board[myPosition.x - 1][myPosition.y] = false;
			ans++;
		}
		if (myPosition.x + 1 < W && board[myPosition.x + 1][myPosition.y]) {
			movable.push_back( {myPosition.x + 1, myPosition.y} );
			board[myPosition.x + 1][myPosition.y] = false;
			ans++;
		}
		if (myPosition.y - 1 >= 0 && board[myPosition.x][myPosition.y - 1]) {
			movable.push_back( {myPosition.x, myPosition.y - 1} );
			board[myPosition.x][myPosition.y - 1] = false;
			ans++;
		}
		if (myPosition.y + 1 < H && board[myPosition.x][myPosition.y + 1]) {
			movable.push_back( {myPosition.x, myPosition.y + 1} );
			board[myPosition.x][myPosition.y + 1] = false;
			ans++;
		}

		while (movable.size() != 0) {
			POSITION sp = movable[movable.size() - 1];
			movable.pop_back();
			if (sp.x - 1 >= 0 && board[sp.x - 1][sp.y]) {
				movable.push_back( {sp.x - 1, sp.y} );
				board[sp.x - 1][sp.y] = false;
				ans++;
			}
			if (sp.x + 1 < W && board[sp.x + 1][sp.y]) {
				movable.push_back( {sp.x + 1, sp.y} );
				board[sp.x + 1][sp.y] = false;
				ans++;
			}
			if (sp.y - 1 >= 0 && board[sp.x][sp.y - 1]) {
				movable.push_back( {sp.x, sp.y - 1} );
				board[sp.x][sp.y - 1] = false;
				ans++;
			}
			if (sp.y + 1 < H && board[sp.x][sp.y + 1]) {
				movable.push_back( {sp.x, sp.y + 1} );
				board[sp.x][sp.y + 1] = false;
				ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  long long N,A,B;
  cin>>N>>A>>B;
  
  long long t = N/(A+B);
  long long r = N%(A+B);
  
  cout<<(t*A)+min(r,A)<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	run()
}

func run() {
	setSpace()
	n, a, b, c, d, e := readN(), readN(), readN(), readN(), readN(), readN()

	m := min(a, b, c, d, e)
	z := n / m
	if d := n % m; d > 0 {
		z++
	}
	fmt.Println(4 + z)
}

func min(xs ...int) int {
	n := xs[0]
	for _, x := range xs[1:] {
		if n > x {
			n = x
		}
	}
	return n
}

// ------以下、ユーティリティ------

var sc = bufio.NewScanner(os.Stdin)

func setSpace() {
	sc.Split(bufio.ScanWords)
}

func read() string {
	sc.Scan()
	return sc.Text()
}

func readN() int {
	n, err := strconv.Atoi(read())
	if err != nil {
		panic(err)
	}
	return n
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    
    ll ans=-1;
    ll k=0;
    for(ll i=1;i<=1000000;i++)
    {
        k=(k*10)+7;
        k=k%n;
        if(k==0)
        {
            ans=i;
            break;
        }
    
    }
    cout<<ans<<endl;
    
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
vector<int> postord;
int cur,n;
int pre[41],in[41];
void dfs(int l,int r){
    if(l>=r) return;
    int vi=pre[cur];
    ++cur;
    int m=distance(in,find(in,in+n,vi));
    dfs(l,m);
    dfs(m+1,r);
    postord.pb(vi);
}
int main(){
    int root;
    cin>>n;
    rep(i,n) cin>>pre[i];
    rep(i,n) cin>>in[i];
    root=pre[0];
    dfs(0,n);
    rep(i,n) cout<<postord[i]<<(i==n-1?"":" ");
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define ll unsigned long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
ll lcs[3010];
ll dp[3010][3010];
ll r[3010][3010];
string a, b;
void print(ll i, ll j){
	if(i == 0 || j == 0) return;
	if(r[i][j] == 0){
		print(i-1 , j-1);
		cout << a[i-1];
	}
	else if(r[i][j] == 1){
		print(i,j-1);
	}
	else{
		print(i-1,j);
	}
}
int main(){
	cin >> a >> b;
	ll n = a.size();
	ll m = b.size();
	fop(i,0,n+1) dp[i][0] = 0;
	fop(i,0,m+1) dp[0][i] = 0;
	fop(i,1,n+1){
		fop(j,1,m+1){
			if(a[i-1] == b[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
				r[i][j] = 0;
			}
			else{
				if(dp[i-1][j] > dp[i][j-1]){
					dp[i][j] = dp[i-1][j];
					r[i][j] = 2; //left
				}
				else{
					dp[i][j] = dp[i][j-1];
					r[i][j] = 1; //up
				}
			}
		}
	}  
	print(n,m);
}

Measured memory_bytes: 141696
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	
	auto cell = new uint[][](N * 2, N * 2);
	long[2][] b, r;
	foreach (i; 0..N)
	{
		r ~= [RD!long, RD!long];
		cell[r[$-1][0]][r[$-1][1]] = 1;
	}
	foreach (i; 0..N)
	{
		b ~= [RD!long, RD!long];
		cell[b[$-1][0]][b[$-1][1]] = 2;
	}

	auto dp = new long[](N*2);
	long ans;
	foreach_reverse (i; 1..N*2)
	{
		foreach_reverse (j; 1..N*2)
		{
			if (cell[i][j] == 2)
			{
				//stderr.writeln("b ", i, ":", j);
				
				foreach (k; 0..j+1)
					++dp[k];
			}
			if (cell[i-1][j-1] == 1 && dp[j] > 0)
			{
				//stderr.writeln(dp);
				//stderr.writeln(i-1, ":", j-1);
				++ans;
				auto x = dp[j];
				foreach (k; j..N*2)
				{
					if (dp[k] != x) break;

					--dp[k];
				}
				foreach_reverse (k; 0..j)
				{
					--dp[k];
				}
				//stderr.writeln(dp);
			}
		}
	}

	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 508
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+10;
vector<int>g[maxn],dp(maxn);
int n;
void dfs(int u){
	vector<int>subtree;
	for(auto v:g[u]){
		dfs(v);
		subtree.push_back(dp[v]);
	}
	sort(subtree.begin(),subtree.end());
	for(auto x:subtree){
		dp[u] = max( dp[u] + 1 , x + 1);
	}
	subtree.clear();
}
		
int32_t main(){
	IOS
	cin>>n;
	for(int i=2;i<=n;i++){
		int p;cin>>p;
		g[p].push_back(i);
	}
	dfs(1);
	cout << dp[1];
	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 17104
# Undirected Graph


class Edge:
    __slots__ = ('v', 'w')

    def __init__(self, v, w):
        self.v = v
        self.w = w

    def either(self):
        return self.v

    def other(self, v):
        if v == self.v:
            return self.w
        else:
            return self.v


class Graph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, e):
        self._edges[e.v].append(e)
        self._edges[e.w].append(e)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


def bridges(graph):
    def visit(v, e):
        nonlocal n
        w = e.other(v)
        if not visited[w]:
            parent[w] = v
            n += 1
            visited[w] = n
            low[w] = n
            return True
        elif w != parent[v]:
            low[v] = min(low[v], visited[w])
            return False

    def leave(p, e):
        c = e.other(p)
        if p == parent[c] and low[c] > visited[p]:
            es.append(e)
        low[p] = min(low[p], low[c])
        return False

    visited = [0] * graph.v
    low = [0] * graph.v
    parent = [-1] * graph.v
    es = []

    s = 0
    n = 1
    visited[s] = n
    low[s] = n
    stack = [(s, e, visit) for e in graph.adj(s)]

    while stack:
        v, e, func = stack.pop()
        # print(v, e.v, e.w, func.__name__, visited, low)
        if func(v, e):
            stack.append((v, e, leave))
            w = e.other(v)
            for ne in graph.adj(w):
                stack.append((w, ne, visit))

    return es


def run():
    v, e = [int(i) for i in input().split()]
    g = Graph(v)

    for _ in range(e):
        s, t = [int(i) for i in input().split()]
        g.add(Edge(s, t))

    edges = [(e.v, e.w) if e.v < e.w else (e.w, e.v)
             for e in bridges(g)]

    for v, w in sorted(edges):
        print(v, w)


if __name__ == '__main__':
    run()



Measured memory_bytes: 18068
import sys
input=sys.stdin.readline
a,b,q=map(int,input().split())
s=[int(input()) for _ in range(a)]
t=[int(input()) for _ in range(b)]
import bisect
for _ in range(q):
    x=int(input())
    sb=bisect.bisect_left(s,x)
    tb=bisect.bisect_left(t,x)
    ss=[x-s[max(sb-1,0)],x-s[min(sb,a-1)]]
    tt=[x-t[max(tb-1,0)],x-t[min(tb,b-1)]]
    l=[]
    for i in ss:
        for j in tt:
            if i*j>=0:
                l.append(max(abs(i),abs(j)))
            else:
                l.append(max(abs(i),abs(j))+2*min(abs(i),abs(j)))
    print(min(l))


Measured memory_bytes: 64348
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
double ans;
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>N;
    rep(i,0,N){
        cin>>v[i];
    }
    sort(v,v+N);
    ans=v[0];
    rep(i,1,N){
        ans = (ans+v[i])/2.0;
    }
    cout<<fixed;
    cout<<setprecision(6)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int dp[100100],h[100100];
int ds(int id) {
	if(id >= n) {return 1e9 + 100;}
	if(id == n-1) {return 0;}
	if(dp[id] != -1) {return dp[id];}
	return dp[id] = min(ds(id+1)+abs(h[id+1]-h[id]),ds(id+2)+abs(h[id+2]-h[id]));
}
int main() {
	scanf("%d ",&n);
	memset(dp,-1,sizeof(dp));
	memset(h,0,sizeof(h));
	for(int i=0;i<n;i++) {
		int t;
		scanf("%d ",&t);
		h[i] = t;
	}
	printf("%d\n",ds(0));
}


Measured memory_bytes: 2560
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()
p = read_int()


memo = [0 for i in range(N - K + 1)]

def solve():
    memo[0] = sum(p[:K])
    for i in range(1, N - K + 1):
        memo[i] = memo[i - 1] + p[i + K - 1] - p[i - 1]
    index = 0
    res = 0
    for i, m in enumerate(memo):
        if res < m:
            res = m
            index = i
    ans = 0
    for i in range(K):
        ans += (p[index + i] + 1) / 2
    return ans
if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 25632
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int H, W;
int SS[400][400];
ll writeCount;
ll blackCount;

void checkAroundByBlack(int x, int y);

int checkBlock(int x, int y) {

    if (x < 0 || x >= H) {
        return -3;
    }
    if (y < 0 || y >= W) {
        return -3;
    }

    return SS[x][y];
}

//白に隣接している黒をチェック
//cに入っている方向は調べない
void checkAroundByWrite(int x, int y, char c) {
    writeCount++;
    //調べた白には-2を入れる
    SS[x][y] = -2;
    if (checkBlock(x - 1, y) == 0 && c != 'l') {
        checkAroundByBlack(x - 1, y);
    }
    if (checkBlock(x + 1, y) == 0 && c != 'r') {
        checkAroundByBlack(x + 1, y);
    }
    if (checkBlock(x, y - 1) == 0 && c != 'u') {
        checkAroundByBlack(x, y - 1);
    }
    if (checkBlock(x, y + 1) == 0 && c != 'b') {
        checkAroundByBlack(x, y + 1);
    }
}


//黒に隣接している白をチェック。
//調べ済みの白は調べない
void checkAroundByBlack(int x, int y) {
    //cout << "Black: " << "x: " << x << " y: " << y << endl;
    blackCount++;
    //調べた黒には1を入れる
    SS[x][y] = 1;
    // 左が白かチェックして、そうなら、白の周辺が黒かチェック
    if (checkBlock(x - 1, y) == -1) {
        checkAroundByWrite(x - 1, y, 'r');
    }
    // 右が白かチェックして、そうなら、白の周辺が黒かチェック
    if (checkBlock(x + 1, y) == -1) {
        checkAroundByWrite(x + 1, y, 'l');
    }
    // 上が白かチェックして、そうなら、白の周辺が黒かチェック
    if (checkBlock(x, y - 1) == -1) {
        checkAroundByWrite(x, y - 1, 'b');
    }
    // 下が白かチェックして、そうなら、白の周辺が黒かチェック
    if (checkBlock(x, y + 1) == -1) {
        checkAroundByWrite(x, y + 1, 'u');
    }
}


int main() {
    cin >> H >> W;
    //白なら-1, 黒なら0を入れる
    for (int i = 0; i < H; ++i) {
        string S;
        cin >> S;
        for (int j = 0; j < S.size(); ++j) {
            int s;
            if (S[j] == '#') {
                s = 0;
            } else {
                s = -1;
            }
            SS[i][j] = s;
        }
    }
    ll result = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            // まだ調べていない黒を調べる
            if (SS[i][j] == 0) {
                writeCount = 0;
                blackCount = 0;
                checkAroundByBlack(i, j);
                result += writeCount * blackCount;
            }
        }
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 8320
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <algorithm>
#include <cmath>

using namespace std;

inline long int gcd(long int a, long int b)
{
	if ((0 == a) || (0 == b)) return 0;
	while (a != b)
	{
		if (a > b) a = a - b;
		else  b = b - a;
	}
	return a;
}

inline long int lcm(long int a, long int b)
{
	if ((0 == a) || (0 == b)) return 0;
	return ((a / gcd(a, b)) * b);
}

int main(void)
{

	long int a, b;
	long int x, y;

	while (cin >> a >> b)
	{
		x = gcd(a, b);
		y = lcm(a, b);

		cout << x << " " << y << endl;
	}
	return 0;

}


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

using namespace std;

int main(int argc, char *argv[]) {
  string s;
  cin >> s;
  int n = s.size();
  int ans = s.size();
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      ans = min(ans, max(i, n - i));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
import io.StdIn.readLine

object Main extends App {
  val s = readLine.toInt

  @scala.annotation.tailrec
  def loop(s: Int, str: String = "", n: Int = 3600): String = n match {
    case 3600 => loop(s % n, s"${s / n}", n / 60)
    case 60 => loop(s % n, s"${str}:${s / n}", n / 60)
    case 1 => s"${str}:${s}"
  }

  val result = loop(s)
  println(result)
}



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

using namespace std;

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

int main() {
    int q; cin >> q;
    set<int> s;
    while (q--) {
        int a, x; cin >> a >> x;
        if (a == 0) {
            s.insert(x); cout << s.size() << endl;
            
        } else if (a == 1) {
            cout << s.count(x) << endl;
        } else {
            s.erase(x);
        }
    }
}


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


int ans = 0;
int n;

bool check(long long val){
	vector<int> cnt(9);
	while(val){
	  cnt[val%10]++;
	  val/=10;
	}
	return (cnt[3]>0 && cnt[7]>0 && cnt[5]>0);
}

void bt(long long v){
	if(v>n) return ;
	if(check(v)){
		ans++;
	}
	bt(v*10+5);
	bt(v*10+3);
	bt(v*10+7);
}


int main(){
	
	cin>>n;

	bt(0);
	cout<<ans;

}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
shelfA = list(map(int,input().split()))
shelfB = list(map(int,input().split()))
prodA = [0]*(n+1)
prodB = [0]*(m+1)
for i in range(1,n+1):
    prodA[i] = prodA[i-1] + shelfA[i-1]
for i in range(1,m+1):
    prodB[i] = prodB[i-1] + shelfB[i-1]

ans = -1
j = m
for i in range(n+1):
    if(prodA[i]>k):
        break
    while(prodB[j] > k - prodA[i]):
        # print(prodB[j],j,k-prodA[i])
        j-=1
    # print(ans)
    ans = max(ans,i+j)



print(ans)

Measured memory_bytes: 47348
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        if (N >= 30){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < 3; i++) {
        if(s[i] == '1') {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    ll k,a=0;
    cin>>k;
    for(int i=1;i<10000000;i++){
        a=a*10+7;
        a%=k;
        if(a==0){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 3632
# EDPC Q - Flowers
# 重み付きのLISと言って良いような問題
# これは、LISのdpを少し改造すれば解ける

## test data
# 4
# 3 1 4 2
# 10 20 30 40
## ans=60

import bisect

class SegTree:
	def __init__(self,size,func,init_val,undef):
		self.specSize = size
		self.datSize = 1
		self.compareFunc = func		# suppose to min or max
		self.INIT_VAL = init_val	# 0 etc
		self.UNDEFINED_VAL = undef	# 1e18 -1e18 etc
		while self.datSize < size: self.datSize *= 2

		# the tree is implemented by sequencial list
		self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)]

	def update(self, i, val ):
		i -= 1	# 1-orderで指定され、内部では0-Order想定?
		i += (self.datSize - 1)
		# print("upd",i,val)
		self.datTree[i] = val
		while 0 < i:
			i = (i-1) >> 1	# (i-1)//2
			self.datTree[i] = self.compareFunc( self.datTree[i*2+1], self.datTree[i*2+2] )
			# print("upd",i,self.datTree[i])

	def query(self,a,b):
		return self.query_(a,b,0,0,self.datSize)

	def query_(self,a,b,i,l,r):
		""" get minimun/maximum value of range[a,b)
		all 1-indexed
		i is the root vertex of search 
		l,r is range of the root vertex
		"""
		if r <= a or b <= l:
			# (a,b) and (l,r) is not intersected
			return self.UNDEFINED_VAL

		if a <= l and r <= b:
			# i is index required
			return self.datTree[i]
		else:
			# search children
			m = (l+r) >> 1 #(l+r) // 2
			# vl = self.query_(a, b, i*2 + 1, l, m )
			# vr = self.query_(a, b, i*2 + 2, m, r )
			vl = self.query_(a, b, (i << 1) + 1, l, m )
			vr = self.query_(a, b, (i << 1) + 2, m, r )
			return self.compareFunc(vl,vr)

def LongestIncreaseSeaquence(H,A):
	# === Coordinate compression ===
	# unique and sort asc
	N = len(H)
	# sortedA = sorted(list(set(A)))
	lis = 0

	# === Range Maximum Query ===
	# ここでは、各要素iに、最後の値がiの時のLISを登録
	tree = SegTree(N,max,0,-1e18)
	for n in range(N):

		# i=bisect.bisect_left(sortedA,A[n])

		maxValOfCurrentRange = tree.query(0,H[n])
		# valOfNext = tree.query(H[n],H[n]+1)

		# # i+=1

		# if valOfNext < maxValOfCurrentRange + A[n]:
		# print( H[n], maxValOfCurrentRange + A[n] )
		# tree.debugPrint()
		tree.update( H[n], maxValOfCurrentRange + A[n] )

	lis = tree.query(0,N+1)
	return lis


def main():
	N = int(input())
	# 高さは、N以下で全部違うらしい
	H = list(map(int, input().split()))
	A = list(map(int, input().split()))
	# A = [ int(input()) for _ in range(N)]
	print(LongestIncreaseSeaquence(H,A))



if __name__ == "__main__":
	main()


Measured memory_bytes: 146860
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ff first
#define ss second
long double pi = 3.14159265359 ;
const int N=2e5+5;
const int mod=1e9+7;
 
int binpow(int a, int b, int m) {
    a %= m;
    b %=m;
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int a[N],b[N],dp[N];
map<pair<int,int>,int> pos,neg;
int zero;
int check(int x,int y)
{
    if(x>0 && y>0)
        return 1;
    if(x<0 && y<0)
        return 1;
    if(x==0 && y==0)
        return 0;
    if(x==0)
        return 2;
    if(y==0)
        return 3;
    return -1;    
}
int32_t main()
{
    IOS;
    
    int n;
    cin>>n;
    int x=0,y=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        int val=check(a[i],b[i]);
        a[i]=abs(a[i]);
        b[i]=abs(b[i]);
        if(val==0)
        {
            zero++;
            continue;
        }
        if(val==2)
        {
            x++;
            continue;
        }
        if(val==3)
        {
            y++;
            continue;
        }
        int gc=__gcd(a[i],b[i]);
        a[i]/=gc;
        b[i]/=gc;
        if(val>0)
            pos[{a[i],b[i]}]++;
        else
            neg[{a[i],b[i]}]++;
    }
    vector<pair<int,int>> v;
    for(auto &it:pos)
    {
        if(neg[{it.ff.ss,it.ff.ff}])
            v.push_back({it.ss,neg[{it.ff.ss,it.ff.ff}]});
    }
    v.push_back({x,y});
    int ans=1;
    int lt=0;
    for(auto &it:v)
    {
        int x=it.ff;
        int y=it.ss;
        int temp=binpow(2,x,mod);
        temp%=mod;
        temp+=binpow(2,y,mod);
        temp%=mod;
        temp-=1;
        temp+=mod;
        temp%=mod;
        ans*=temp;
        ans%=mod;
        lt+=x;
        lt+=y;
    }
    lt+=zero;
    lt=n-lt;
    ans*=binpow(2,lt,mod);
    ans%=mod;
    ans-=1;
    ans+=mod;
    ans%=mod;
    ans+=(zero);
    ans%=mod;
    cout<<ans;
}


Measured memory_bytes: 25504