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

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 0 && 0 <= b){
        cout << "Zero" << endl;
        return 0;
    }
    int minus = 0;
    if(a < 0)minus += abs(a);
    if(b < 0)minus += 1 - abs(b);
    if(minus % 2)cout << "Negative" << endl;
    else cout << "Positive" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
ans1 = 0
sum1 = 0
for i, a in enumerate(A):
    sum1 += a
    if i % 2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
    elif i % 2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
ans2 = 0
sum2 = 0
for i, a in enumerate(A):
    sum2 += a
    if i % 2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
    elif i % 2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
print(min(ans1, ans2))

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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  string s;
  cin>>s;
  bool f=true;
  int a=s.size();
  rep(i,a/2){
    if(s[i]!=s[a-1-i]) f=false;
  }
  //YesNo(f);
  rep(i,(a-1)/4){
    if(s[i]!=s[(a-1)/2-1-i]) f=false;
  }
  //YesNo(f);
  REP(i,(a+3)/2-1,a){
    if(s[i]!=s[(3*a+3)/2-2-i]) f=false;
  }
  YesNo(f);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0;
  string str;
  cin>>n;
  cin>>str;
  for(int i=0;i<n-2;i+=1){
    if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='C') cnt+=1;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3604
s = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30)
w = ("Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday")
while True:
    m, d = map(int, input().split())
    if m == 0:break
    print(w[(d + sum(s[:m])) % 7])


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define rkc ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define rfl(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
#define test ll t;cin>>t;while(t--)
#define lld long double
const ll M = 1e9 + 7;
const double pi  =3.141592653589793238463;
bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
} 

int main()
{
    rkc;
    ll n,s=0,s1=0,mx=-M;
    cin>>n;
    ll a[n],b[n],c[n];
    vector<pair<ll,ll>> v;
    fl(i,0,n){cin>>a[i];}
    fl(i,0,n){cin>>b[i];}
    fl(i,0,n)c[i]=a[i]-b[i];
    fl(i,0,n)
    {
        if(c[i]>0)s+=c[i];
    }
    cout<<s;
}


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

long long int res=0,mymin=99999999999999999,odd=0,n,a[200005],zero=0;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
   	cin>>a[i];
    if(a[i]<0){odd++;}
    res+=abs(a[i]);
    mymin=min(mymin,abs(a[i]));
  }
  if(odd%2==0)cout<<res<<endl;
  if(odd%2==1)cout<<res-2*mymin<<endl;
}


Measured memory_bytes: 1024
# ALDS1_9_B Maximum Heap
import sys

def maxheap(A, i):
    # i はリストの位置
    l = i * 2
    r = l + 1

    largest = i

    if l <= H:
        if A[l] > A[largest]:
            largest = l

    if r <= H:
        if A[r] > A[largest]:
            largest = r

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxheap(A, largest)


def buildmaxheap(A):
    for i in range(H // 2, 0, -1):
        maxheap(A, i)

H = int(input())

A = list(map(int, sys.stdin.readline().strip().split()))
A.insert(0, None)
buildmaxheap(A)
A.remove(None)
print('', ' '.join(map(str, A)))



Measured memory_bytes: 63700
<?php
$a = array();
$a[] = explode(" ", trim(fgets(STDIN)));
$a[] = explode(" ", trim(fgets(STDIN)));
$a[] = explode(" ", trim(fgets(STDIN)));

$n = fgets(STDIN);

$b = array();
for($i = 0; $i < $n; $i++){
	$b[] = trim(fgets(STDIN));
}

for($i = 0; $i < 3; $i++){
		$a[$i + 3][] = $a[0][$i];
		$a[$i + 3][] = $a[1][$i];
		$a[$i + 3][] = $a[2][$i];
}

for($i = 0; $i < 3; $i++){
	$a[6][] = $a[$i][$i];
	$a[7][] = $a[$i][2 - $i];
}
foreach($a as $arr){
	$sum = 0;
	foreach($arr as $m){
		if(in_array($m, $b)){
			$sum++;
		}
	}
	if($sum === 3){
		echo 'Yes';
		exit;
	}
}
echo 'No';
?>


Measured memory_bytes: 4604
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
int dp[101][10001];
void Bugged(){
	int n;
	cin >> n;
	fill(dp[0], dp[0] + 10001, -1);
	dp[0][0] = 1;

	for (size_t i = 1; i <= n; i++)
	{
		fill(dp[i], dp[i] + 10001, -1);
		int a;
		cin >> a;
		for (size_t j = 0; j < 10001; j++)
		{
			if (dp[i - 1][j] == 1) {
				dp[i][j + a] = 1;
				dp[i][j] = 1;
			}
		}
	}

	int res = 0;
	for (size_t i = 0; i <= 10000; i++)
	{
		if (i % 10 == 0) continue;
		if (dp[n][i] == 1) res = i;
		
	}
	cout << res << endl;
}

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



Measured memory_bytes: 4224
fun main(args: Array<String>) {
    val cards = listOf("S", "H", "C", "D").flatMap { s -> (1..13).map { i -> "$s $i" } }
    val n = readLine()!!.toInt()
    val taros = (1..n).map { readLine()!!.split(" ").joinToString(" ") }
    cards.subtract(taros).forEach(::println)
}


Measured memory_bytes: 34056
#include<stdio.h>
int main()
{
	int n,i,c;
	long long T,t[200005]={0};
	scanf("%d %d",&n,&T);
	for(i=0;i<n;i++)
	{
		scanf("%d",&t[i]);
	}
	c=T;
	for(i=0;i<n-1;i++)
	{
		if((t[i+1]-t[i])>=T)
		c=c+T;
		else
		c=c-(T-(t[i+1]-t[i]))+T;
	}
	printf("%d",c);
 } 

Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

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

    map<int, int> mpodd, mpevn;
    map<int, int>::iterator itr;

    for(int i=0; i<n; i+=2){
        if(mpodd.find(v[i]) == mpodd.end()){
            mpodd.insert(make_pair(v[i], 1));
        }
        else{
            mpodd[v[i]]++;
        }
    }
    for(int i=1; i<n; i+=2){
        if(mpevn.find(v[i]) == mpevn.end()){
            mpevn.insert(make_pair(v[i], 1));
        }
        else{
            mpevn[v[i]]++;
        }
    }

    int maxodd = 0;
    int maxodd2 = 0;
    int oddtemp = 0;
    int oddtemp2 = 0;
    pair<int, int> p;
    for(itr = mpodd.begin(); itr != mpodd.end(); itr++){
        p = *itr;
        if(maxodd < p.second){
            maxodd2 = maxodd;
            maxodd = p.second;
            oddtemp2 = oddtemp;
            oddtemp = p.first;
        }
        else if(maxodd2 < p.second){
            maxodd2 = p.second;
            oddtemp2 = p.first;
        }
    }

    int maxevn = 0;
    int maxevn2 = 0;
    int evntemp = 0;
    int evntemp2 = 0;
    for(itr = mpevn.begin(); itr != mpevn.end(); itr++){
        p = *itr;
        if(maxevn < p.second){
            maxevn2 = maxevn;
            maxevn = p.second;
            evntemp2 = evntemp;
            evntemp = p.first;
        }
        else if(maxevn2 < p.second){
            maxevn2 = p.second;
            evntemp2 = p.first;
        }
    }

    // cout << oddtemp << " " << oddtemp2 << " " << evntemp << " " << evntemp2 << endl;
    
    if(oddtemp == evntemp){
        if(maxodd > maxevn){
            cout << n - maxodd - maxevn2 << endl;
        }
        else if(maxodd < maxevn){
            cout << n - maxodd2 - maxevn << endl;
        }
        else{
            if(maxodd2 >= maxevn2){
                cout << n - maxodd2 - maxevn << endl;
            }
            else{
                cout << n - maxodd - maxevn2 << endl;
            }
        }
    }
    else{
        cout << n - maxodd - maxevn << endl;
    }

    return 0;
}

Measured memory_bytes: 5376
n = int(input())
a = [int(item) for item in input().split()]
MOD = 10**9 + 7

N = 10**5 + 10 
fac = [1] + [0] * N
fac_inv = [1] + [0] * N
for i in range(1, N+1):
    fac[i] = (fac[i-1] * i) % MOD
    fac_inv[i] = fac_inv[i-1] * pow(i, MOD-2, MOD) % MOD

fracn_sum = [0] * n
for i in range(n):
    fracn_sum[i] = (fac[n] * pow(i+1, MOD-2, MOD)) % MOD
for i in range(1, n):
    fracn_sum[i] += fracn_sum[i-1] 
    fracn_sum[i] %= MOD

ans = 0
for i, item in enumerate(a):
    ans += (fracn_sum[i] + fracn_sum[n-1-i] - fracn_sum[0]) * item
    ans %= MOD
print(ans)

Measured memory_bytes: 19248
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)

N,Y=l()
ans=[-1,-1,-1]
for i in range(N+1):
    for j in range(N+1):
        if(i+j>N):
            break
        z=N-i-j
        if(i*1000+j*5000+z*10000==Y):
            ans=[z,j,i]
            break
    if(ans!=[-1,-1,-1]):
        break
print(*ans)






Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    double t,x;
    cin>>t>>x;
    cout<<t/x;
    return 0;
}

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

using namespace std;

int N;

int length(int x1, int y1, int x2, int y2){
    int dx = abs(x1 - x2);
    int dy = abs(y1 - y2);
    return dx + dy;
}

int main(){
    cin >> N;
    int x = 0, y = 0;
    int t = 0;
    for(int i=0;i<N;i++){
        int nt,nx,ny;
        cin >> nt >> nx >> ny;
        int l = length(x,y,nx,ny);
        if(nt < t + l){
            cout << "No" << endl;
            return 0;
        }
        int dt = nt - (t + l);
        if(dt % 2 != 0){
            cout << "No" << endl;
            return 0;
        }
        t = nt;
        x = nx;
        y = ny;
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

int main()
{
	const int MAX_VALUES = 101;
	bitset<MAX_VALUES> bits;
	bitset<MAX_VALUES> reversed;
	bits.flip();
	reversed.flip();
	int x, n, t;
	scanf("%d %d", &x, &n);
	if (n == 0) {
		printf("%d", x);
		exit(0);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", &t);
		bits.reset(t);
		reversed.reset(MAX_VALUES - 1 - t);
	}
	if (bits[x]) {
		printf("%d", x);
		exit(0);
	}
	int rV = bits._Find_next(x);
	int lV = MAX_VALUES - 1 - reversed._Find_next(MAX_VALUES - 1 - x);
	int d1 = abs(rV - x);
	int d2 = abs(lV - x);
	if (d1 < d2) {
		printf("%d", rV);
	} else if (d2 < d1) {
		printf("%d", lV);
	} else {
		printf("%d", min(rV, lV));
	}
	return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    fori (i, 0, n) cin >> v[i];
    int total = 0;
    fori (i, 0, n) total += v[i];
    int selected = 0;
    double need = (double) total / (double) (4.0 * m);
    fori (i, 0, n) {
        if (v[i] >= need) {
            selected++;
        }
    }
    cout << (selected >= m ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
using System;

namespace abc110A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            int D;
            int E;
            int F;
            int G;
            if (A < B)
            {
                D = B;
                
            }
            else
            {
                D = A;
                
            }
            if (B < C)
            {
                E = C;
                
            }
            else
            {
                E = B;
                
            }
            if (D < E)
                F = (10 * E) + D;
            else
                F = (10 * D) + E;
            G = (A + B + C) - (D + E) + F;
            Console.WriteLine(G);
        }
    }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
#include<numeric>

using namespace std;

int main() {
	vector <int> a;
	int N = 0;
	long long SumN = 0;
	long long Sumi = 0;
	long long ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int num = 0;
		cin >> num;
		a.push_back(num);
		SumN += a[i];
	}
	ans = abs(SumN-2*a[0]);

	for (int i = 0;i<N;i++) {
		Sumi += a[i];
		if (i+1<N) {
			ans = min(ans, abs(SumN - 2 * Sumi));
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1400
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()


if N%2 == 0:
    d = defaultdict(lambda:defaultdict(lambda:-float('inf')))
    d[0][1] = A[0]
    d[1][1] = max(A[0],A[1])
    for i in range(2,N):
        if i%2 == 0:
            for j in [i//2,i//2+1]:
                d[i][j] = max(d[i-2][j-1]+A[i],d[i-1][j])
        else:
            for j in [(i+1)//2]:
                d[i][j] = max(d[i-2][j-1]+A[i],d[i-1][j])
    print(d[N-1][N//2])
else:
    d = defaultdict(lambda:defaultdict(lambda:-float('inf')))
    d[0][1] = A[0]
    d[1][1] = max(A[0],A[1])
    for i in range(2,N):
        if i%2 == 0:
            for j in [i//2,i//2+1]:
                d[i][j] = max(d[i-2][j-1]+A[i],d[i-1][j])
        else:
            for j in [i//2,i//2+1]:
                d[i][j] = max(d[i-2][j-1]+A[i],d[i-1][j])
    a1 = d[N-1][N//2]
    n = 0
    for i in range(2,N,2):
        n += A[i]
    print(max(n,a1))

Measured memory_bytes: 150660
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 3000010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll f[MAXN], rev[MAXN];
int r1, c1, r2, c2;

ll binPowMod(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1LL) res = res * a % MODBASE;
        a = a * a % MODBASE;
        b >>= 1LL;
    }
    return res;
}

ll add(ll a, ll b) {
    return (a + b) % MODBASE;
}

ll mul(ll a, ll b) {
    return a * b % MODBASE;
}

ll sub(ll a, ll b) {
    return (a - b + MODBASE) % MODBASE;
}

ll C(ll n, ll k) {
    if (k > n || k < 0) return 0;
    return mul(f[n], mul(rev[n-k], rev[k]));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    f[0] = 1;
    rev[0] = binPowMod(f[0], MODBASE-2);
    FOR(i,1,3000000) {
        f[i] = mul(f[i-1], i);
        rev[i] = binPowMod(f[i], MODBASE-2);
    }
    cin >> r1 >> c1 >> r2 >> c2;
    ll res = 0;
    FOR(i,r1,r2) res = add(res, sub(C(c2+i+1, i+1), C(c1-1+i+1, i+1)));
    cout << res;
    return 0;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using i64 = long long;
using B = std::bitset<701>;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::set<int>> g(n);
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) g[i].insert(j);
    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        g[a].erase(b);
        g[b].erase(a);
    }

    std::vector<int> c(n);
    std::vector<std::pair<int, int>> w;
    for (int i = 0; i < n; i++) {
        if (c[i]) continue;

        std::deque<int> q { i };
        c[i] = 1;
        int o = 0, e = 0;
        while (!q.empty()) {
            int v = q.front();
            q.pop_front();

            if (c[v] == 1) o++;
            else e++;

            for (int to : g[v]) {
                if (c[to]) {
                    if (c[to] == c[v]) {
                        std::cout << -1 << std::endl;
                        return 0;
                    }
                } else {
                    c[to] = 3 - c[v];
                    q.push_back(to);
                }
            }
        }

        w.emplace_back(o, e);
    }

    B dp;
    dp[w.front().first] = 1;
    dp[w.front().second] = 1;
    for (int i = 1; i < w.size(); i++) {
        dp = (dp << w[i].first) | (dp << w[i].second);
    }

    int ret = n * n;
    for (int i = 1; i <= n; i++) {
        if (!dp[i]) continue;
        int tmp = i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2;
        ret = std::min(ret, tmp);
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 24368
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var l = lines[0].split(' ');
  console.log(l[0]*1+l[1]/2);
});

Measured memory_bytes: 7628
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2;
}


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

list_inp = [list(map(int,input().split())) for _ in range(N)]
list_inp.sort(key=lambda x: x[2], reverse=True)
max_list_inp = list_inp[0]

for x in range(101):
  for y in range(101):
    flg = True
    max_h = max_list_inp[2] + abs(max_list_inp[0] - x) + abs(max_list_inp[1] - y)
    
    # 全サンプルで、結果が一致することを確認する。
    for i in list_inp:
      h = max(max_h - abs(i[0] - x) - abs(i[1] - y), 0)
      if h != i[2]:
        flg = False
        break
    
    if flg:
      ans_x, ans_y,ans_h = x,y,max_h
      break
    
  if flg:
    break
    
    
print(ans_x, ans_y,ans_h)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

  int a, b, calc;
  char mark;

  while(1) {
    scanf("%d %c %d", &a, &mark, &b);

    if (mark == '+') {
      calc = a + b;
    } else if (mark == '-') {
      calc = a - b;
    } else if (mark == '*') {
      calc = a * b;
    } else if (mark == '/') {
      calc = a / b;
    } else {
      break;
    }

    printf("%d\n", calc);
  }

  return 0;
}



Measured memory_bytes: 2060
N = int(input())
S = sorted([sorted(input()) for i in range(N)])

ans = 0
count = 1
pre = S[0]
for i in range(1, N):
    if S[i] != pre:
        ans += count*(count-1)//2
        count = 1
        pre = S[i]
    else:
        count += 1

ans += count*(count-1)//2
print(ans)

Measured memory_bytes: 25420
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

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

    string s;
    cin >> s;
    int red = 0;
    int blue = 0;
    REP(i, s.size()) {
        char c = s[i];
        if (c == '0') {
            red++;
        }
        else {
            blue++;
        }
    }
    cout << min(red, blue) * 2 << endl;
    return 0;
}


Measured memory_bytes: 1144
import sys
 
out = []
for line in sys.stdin.readlines():
    List = map(float, line.strip().split())
 
    [a, b, c, d, e, f] = List
 
    x = (b*f-c*e)/(b*d-a*e)
    y = (a*f-c*d)/(a*e-b*d)
 
    out.append("%.3f %.3f" % (x+0, y+0))
 
for i in xrange(len(out)):
    print out[i]

Measured memory_bytes: 6280
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,m = map(int, input().split())
    ans = 0
    S = []
    for i in range(m):
        s = list(map(int, input().split()))
        k = s.pop(0)
        S.append(s)
    p = list(map(int, input().split()))

    for i in range(1<<n):
        ok = True
        for j in range(m):
            cnt = 0
            for s in S[j]:
                if ((i>>s-1)&1): # スイッチが対象であれば
                    cnt += 1
            if cnt%2!=p[j]:
                ok = False
        if ok:
            ans += 1
    print(ans)




if __name__=="__main__":
    main()


Measured memory_bytes: 74276
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[10][10], b;

int main()
{
	int N;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	cin >> N;
	for (int k = 0; k < N; k++) {
		cin >> b;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (A[i][j] == b) A[i][j] = 0;
			}
		}
	}
	for (int i = 0; i < 3; i++) {
		int sum1 = 0, sum2 = 0;
		for (int j = 0; j < 3; j++) {
			if (A[i][j] == 0) sum1++;
			if (A[j][i] == 0) sum2++;
		}
		if (sum1 == 3 || sum2 == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	int sum1 = 0, sum2 = 0;
	for (int i = 0; i < 3; i++) {
		if (A[i][i] == 0) sum1++;
		if (A[i][2 - i] == 0) sum2++;
	}
	if (sum1 == 3 || sum2 == 3) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	string sa;
	vector<int> v1;
	LL s=0;
	cin>>sa;
	n=sa.size();
	for(i=0,j=0;i<n;i++){
		if(j%2==0 && sa[i]=='0'){
			v1.push_back(i);
		}else{
			s+=j/2+1;
			j++;
		}
	}
	i=n;
	reverse(v1.begin(),v1.end());
	v1.push_back(-1);
	for(j=0;j<v1.size();j++){
		a=0,b=0;
		for(i--;i>v1[j];i--){
			c=i-(int)v1.size()-j-1;
			if(sa[i]=='1'){
				if(c%2==0)a++;
				else b++;
			}
		}
		c=(int)v1.size()-j-1;
		a*=c/2+j,b*=(c+1)/2;
		s+=a+b;
	}
	cout<<s<<endl;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

/////////////////////////////////////////////////////////
class UnionFind {
 public:
  static const int MAX_N_LIB = (int)(2e5 + 100);

  int uf_par[MAX_N_LIB];
  int uf_rank[MAX_N_LIB];
  int uf_size[MAX_N_LIB];

  UnionFind(int n) { init(n); }

  void init(int n) {
    for (int i = 0; i < n; ++i) {
      uf_par[i] = i;
      uf_rank[i] = 0;
      uf_size[i] = 1;
    }
  }

  int find(int x) {
    if (uf_par[x] == x)
      return x;
    else {
      return uf_par[x] = find(uf_par[x]);
    }
  }

  void unite(int leaf_x, int leaf_y) {
    int x = find(leaf_x);
    int y = find(leaf_y);

    if (x == y) return;

    if (uf_rank[x] < uf_rank[y]) {
      uf_par[x] = y;
      uf_size[y] += uf_size[x];
    } else if (uf_rank[x] > uf_rank[y]) {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
    } else {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
      uf_rank[x] += 1;
    }
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return uf_size[find(x)]; }
};
/////////////////////////////////////////////////////////

int n, m;
vector<pair<int, int>> vec;

UnionFind uf(MAX_N);

vector<ll> ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    vec.push_back(make_pair(a, b));
  }

  reverse(vec.begin(), vec.end());

  ll num = (ll)(n) * (ll)(n - 1) / 2;

  ans.push_back(num);

  for (int i = 0; i < m - 1; ++i) {
    auto e = vec[i];

    if (uf.same(e.first, e.second)) {
      ans.push_back(num);
      continue;
    }

    num -= (ll)(uf.size(e.first)) * (ll)(uf.size(e.second));

    uf.unite(e.first, e.second);

    ans.push_back(num);
  }

  reverse(ans.begin(), ans.end());

  for (auto &e : ans) {
    printf("%lld\n", e);
  }

  return 0;
}


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

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

    int N;
    cin >> N;
    vector<int> B(N);
    for (int i = 1; i <= N - 1; i++)
        cin >> B[i];

    int sum = B[1];
    for (int i = 1; i <= N - 2; i++)
        sum += min(B[i], B[i + 1]);
    sum += B[N - 1];
    cout << sum << '\n';

    return 0;
}

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

result = 0
while True:
    start = N
    for i in range(N):
        if h[i] != 0:
            start = i
            break
    if start == N:
        break
    end = N - 1
    count = float('inf')
    for i in range(start, N):
        if h[i] == 0:
            end = i - 1
            break
        if h[i] < count:
            count = h[i]
    for i in range(start, end + 1):
        h[i] -= count
    result += count
print(result)


Measured memory_bytes: 3064
import itertools

P = []
counter = 0
if __name__ == '__main__':
    N, M = map(int, input().split())
    P = [[0]*N for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        P[a-1][b-1] = P[b-1][a-1] = 1
    for v in itertools.permutations(range(N)):
        if v[0] != 0:
            break
        flag = 0
        for i in range(N - 1):
            if P[v[i]][v[i + 1]] == 0:
                flag = 1
                break
        if flag == 0:
            counter += 1
        
    print(counter)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;

int s = 0, t = 0, ans = 0, n = 1;

signed main() {
    
   cin >> s >> t;
    if(t == 1){
        cout << 0; return 0;
    }
  
   ans = s; 
   while(ans < t){
       n++; ans += s-1;
   } 
    
    cout << n;
    
	return 0;
}


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

using namespace std;

const int maxN = 100010 + 10;

int x[maxN], y[maxN], z[maxN];
char c[maxN];
int a[2222][2222][2];

int getSum(int x1, int y1, int x2, int y2, int color) {
    return a[x2][y2][color] - a[x1 - 1][y2][color] - a[x2][y1 - 1][color] + a[x1 - 1][y1 - 1][color];
}

int intersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, int color) {
    int X1 = max(x1, x3), Y1 = max(y1, y3);
    int X2 = min(x2, x4), Y2 = min(y2, y4);
    if (X1 <= X2 && Y1 <= Y2) {
        return getSum(X1, Y1, X2, Y2, color);
    }
    return 0;
}

int get(int x1, int y1, int k, int color) {
    int answer = 0;
    for (int dx = -1; dx <= 1; ++dx) {
        for (int dy = -1; dy <= 1; ++dy) {
            int X1 = x1 + dx * k, Y1 = y1 + dy * k;
            int X2 = X1 + k - 1, Y2 = Y1 + k - 1;
            int t = abs(dx) + abs(dy);
            t %= 2;
            if (t == 0) answer += intersect(1, 1, k + k, k + k, X1, Y1, X2, Y2, color); else
            answer += intersect(1, 1, k + k, k + k, X1, Y1, X2, Y2, 1 - color);
        }
    }
    return answer;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> y[i] >> c[i];
        x[i] %= (k + k);
        y[i] %= (k + k);
        int X = x[i], Y = y[i], Z;
        if (c[i] == 'B') Z = 0; else Z = 1;
        a[X + 1][Y + 1][Z]++;
    }
    for (int i = 1; i <= k + k; ++i) {
        for (int j = 1; j <= k + k; ++j) {
            for (int t = 0; t <= 1; ++t) {
                a[i][j][t] = a[i][j][t] + a[i - 1][j][t] + a[i][j - 1][t] - a[i - 1][j - 1][t];
            }
        }
    }
    int answer = 0;
    for (int sX = 1; sX <= k; ++sX) {
        for (int sY = 1; sY <= k; ++sY) {
            int ans1 = get(sX, sY, k, 0);
            int ans2 = get(sX, sY, k, 1);
            answer = max(answer, max(ans1, ans2));
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 37888
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
map<string,bool>S;
char com[7];
char  str[13];
int n;

int main(){
	scanf("%d",&n);
	for(int j=0;j<n;j++){
	scanf("%s %s",com,str);
	if(com[0]=='i'){
		S[string(str)]=true;
		}
		else if(S[string(str)]==true){
			cout<<"yes"<<endl;
		}
	    else if(S[string(str)]!=true){
	         cout<<"no"<<endl;
			}
	}
	return 0;
	}

Measured memory_bytes: 47532
import java.util.Scanner;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] arr = new int[N];
    int sum = 0;
    
    for(int i = 0; i < N; i++){
      arr[i] = sc.nextInt();
    }

    for(int i = 0; i < N; i++){
      for(int j = i + 1; j < N; j++){
        sum = sum + (arr[i] * arr[j]);
      }
    }

    System.out.println(sum);

  }
}

Measured memory_bytes: 22868
using System;
   class Program
    {
     
        static void Main(string[] args)
            {
            string S = Console.ReadLine();          
            string[] Ss = new string[6];
            int m1 = 0;
            for(int i=0;i<6;i++)
            {
                Ss[i]=S.Substring(i,1);
            }

            if (Ss[2] == Ss[3])
            {
                m1++;
            }
            if (Ss[4] == Ss[5])
            {
                m1++;
            }
            if (m1==2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadLine();
             



            }
        }


Measured memory_bytes: 13140
#include <iostream>
#include <math.h>
#include <stdio.h>
#define EPS 0.00000001
using namespace std;

int main(void){
	double x1,y1,x2,y2;
	double x0,y0;
	double dx,dy;
	double m;
	double X,Y;
	int q;
	cin >> x1 >> y1 >> x2 >> y2;
	dx=x1-x2;
	dy=y1-y2;
	cin >> q;
	while(q--){
		cin >> x0 >> y0;
		X=(dx*dx*x0+dy*dy*x1-dx*dy*(y1-y0))/(dx*dx+dy*dy);
		if(!(-EPS<=dx && dx<=EPS)){
			Y=dy/dx*(X-x1)+y1;
		}else{
			Y=y0;
		}
		printf("%.8lf %.8lf\n",X,Y);
	}
	return 0;
}

Measured memory_bytes: 1252
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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)*}
    };
}

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

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input!{
        n: usize,
        pa: [u64; n],
    }

    let ans: u64 = pa.iter().sum::<u64>() - pa.iter().max().unwrap() / 2;
    println!("{}", ans);
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int count = 0;;
    int tmp;
    int tmp2;
    vector<int> s(n, 0);
    for(int i = 0; i < k; i++){
        cin >> tmp;
        for(int j = 0; j < tmp; j++){
            cin >> tmp2;
            s.at(tmp2 - 1) = 1;
        }
    }

    for(int i = 0; i < n; i++){
        if(s.at(i) == 0){
            count++;
        }
    }

    cout << count << endl; 
}

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

using namespace std;

int main()
{
  long long N, x;
  cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < N; i++)
    if (x < (i == 0 ? 0 : a[i - 1]) + a[i])
    {
      ans += (i == 0 ? 0 : a[i - 1]) + a[i] - x;
      a[i] = x - (i == 0 ? 0 : a[i - 1]);
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  ll cnt[n+5]; CLR(cnt);
  VL a(n);
  rep(i,n){
    cin>>a[i]; cnt[a[i]]++;
  }
  ll ans = 0;
  rep(i,n+5){
    ans += (cnt[i]-1)*cnt[i]/2;
  }
  rep(i,n){
    cout << ans - (cnt[a[i]]-1) << endl;
  }
  // cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5760
arr = 10.times.map{ Array.new(10){0} }
while gets do
  x, y, size = $_.split(",").map(&:to_i)

  drops = [[0, 0], [0,1], [1,0], [0,-1], [-1,0]]
  drops += [[1, 1], [1, -1], [-1, 1], [-1, -1]] if size>=2
  drops += [[2, 0], [0, 2], [-2, 0], [0, -2]] if size>=3

  drops.each do |dx, dy|
    nx, ny = dx + x, dy + y
    arr[nx][ny] += 1 if (0..9).include?(nx) && (0..9).include?(ny)
  end
end
puts arr.map{ |i| i.count { |v| v == 0 } }.inject(:+)
puts arr.map{ |i| i.max }.max

Measured memory_bytes: 6112
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

int main(int argc, char ** argv) {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	stack<char> st;
	for(ll i=0; i<n; i++) {
		if(s[i] == '(') {
			st.push('(');
		} else if(s[i] == ')' && !st.empty() && st.top() == '(') {
			st.pop();
		} else if(s[i] == ')' && !st.empty() && st.top() == ')') {
			st.push(')');
		} else if(s[i] == ')' && st.empty()) {
			st.push(')');
		}
	}
	ll num_beg = 0, num_end = 0;
	while(!st.empty() && st.top() == '(') {
		num_end++;
		st.pop();
	}
	while(!st.empty() && st.top() == ')') {
		num_beg++;
		st.pop();
	}
	for(ll i=0; i<num_beg; i++) {
		cout << "(";
	}
	cout << s;
	for(ll i=0; i<num_end; i++) {
		cout << ")";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
from queue import Queue
INF = float("inf")
R, C = map(int,input().split())
M = [input() for k in range(R)]
ans = 0
for k in range(C):
    for l in range(R):
        if M[l][k] == ".":
            D = [[INF for k in range(C)] for l in range(R)]
            sx, sy = l, k
            Q = Queue()
            Q.put([sx,sy])
            D[sx][sy] = 0
            dx = [1,0,-1,0]
            dy = [0,1,0,-1]
            while not Q.empty():
                t = Q.get()
                x = t[0]
                y = t[1]
                for d in range(4):
                    if 0 <= x + dx[d] < R and 0 <= y + dy[d] < C:
                        if M[x+dx[d]][y+dy[d]] == "." and D[x+dx[d]][y+dy[d]] > D[x][y]+1:
                            D[x+dx[d]][y+dy[d]] = D[x][y]+1
                            Q.put([x+dx[d],y+dy[d]])
            for p in range(C):
                for q in range(R):
                    if D[q][p] != float("inf"):
                        ans = max(ans,D[q][p])
print(ans)


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

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

typedef long long ll;

int main(){
  ll x;
  cin >> x;

  ll cdd1 = (x + 10) / 11;
  ll cdd2 = (x + 5 + 10) / 11;
  if(2 * cdd1 < 2 * cdd2 - 1) {
    cout << (2 * cdd1) << endl;
  }else {
    cout << (2 * cdd2 - 1) << endl;
  }
  return 0;
}



Measured memory_bytes: 384
import bisect
N,M,Q=map(int,input().split())
LR = []
for _ in range(M):
    LR.append(list(map(int,input().split())))
LR.sort()
L = [x for x,_ in LR]
R = [x for _,x in LR]

#事前に配列化 ans[i][j] i以降にスタート、j以前に完了の個数
ans = [[0]*510 for _ in range(510)]
for i in range(1,501):
    idx_L = bisect.bisect_left(L,i)
    arr=R[idx_L:]
    for ar in arr:
        ans[i][ar]+=1
    for j in range(1,501):
        ans[i][j]=ans[i][j-1]+ans[i][j]
    
for _ in range(Q):
    l,r = map(int,input().split())
    print(ans[l][r])


Measured memory_bytes: 220284
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}


int main(){
    int n,m ;
    cin >> n >> m ;
    vector<vector<pair<int,int> > > info(n,vector<pair<int,int> >(0)) ;
    int l,r,d ;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r >> d ;
        l -- ;
        r -- ;
        info.at(l).push_back(make_pair(r,d)) ;
        info.at(r).push_back(make_pair(l,d*-1)) ;
        
    }
    vector<int> x(n,-1) ;
    vector<bool> seen(n,0) ;
    queue<int> wait ;
    for (int i = 0; i < n; i++)
    {
        if (seen.at(i) == 1)
        {
            continue ;
        }
        x.at(i) = 0 ;
        wait.push(i) ;
        seen.at(i) = 1 ; 
        while (wait.empty() == 0)
        {
            int lookl = wait.front() ;
            wait.pop() ;
            for (int j = 0; j < info.at(lookl).size(); j++)
            {
                int lookr = info.at(lookl).at(j).first ;
                int lookd = info.at(lookl).at(j).second ;
                if (seen.at(lookr) == 0 )
                {
                    x.at(lookr) = x.at(lookl) + lookd ;
                    wait.push(lookr) ;
                    seen.at(lookr) = 1 ; 
                }
                
                
            }
            
        }
        
        
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < info.at(i).size(); j++)
        {
            if (x.at(info.at(i).at(j).first) - x.at(i) != info.at(i).at(j).second) 
            {
                cout << "No" << endl ;
                return 0 ;
            }
            
        }
        
    }
    
    cout << "Yes" << endl ;
    
}

Measured memory_bytes: 12556
n = input()

def abc(s):
  t = all(('3' in s, '5' in s, '7' in s))
  if len(s) < len(n):
    return abc(s+'3') + abc(s+'5') + abc(s+'7') + t
  elif s <= n:
    return t
  else:
    return 0

print(abc(''))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

int solve(int x) {
	return x * (x - 1) / 2;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	map<int, int> cnt;
	for (auto t : a) {
		cnt[t]++;
	}
	int ans = 0;
	for (auto t : cnt) {
		ans += solve(t.second);
	}
	for (int i = 0; i < n; i++) {
		ans -= solve(cnt[a[i]]);
		cnt[a[i]]--;
		ans += solve(cnt[a[i]]);
		cout << ans << ' ';
		ans -= solve(cnt[a[i]]);
		cnt[a[i]]++;
		ans += solve(cnt[a[i]]);
	}
	cout << endl;
} 


Measured memory_bytes: 11136
#include <stdio.h>

int main(){
  int n = 0, q = 0;
  int i = 0, j = 0, cnt = 0;
  int S[10000], T[500];

  /*Input S[N]*/
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }
  
  /*Input T[N]*/
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
    /*
    if(i > 0){
      for(j = 0; j < i; j++){
	if(T[i] == T[j])scanf("%d",&T[i]);
      }
    }
    */
  }

  /*Search*/
  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(S[j] == T[i]){
	cnt++;
	break;
      }
    }
  }

  /*Print*/
  printf("%d\n",cnt);
}



Measured memory_bytes: 2108
N, X, Y = map(int, input().split())
anslist = [0]*(N)

for i in range(1, N):
    for j in range(i+1, N+1):
        anslist[min(j-i,abs(X-i)+1+abs(Y-j))] += 1
for i in range(N-1):
    print(anslist[i+1])

Measured memory_bytes: 3444
#ABC085C/Otoshidama
def main():
    n,y = map(int,input().split())

    for i in range(n+1):
        for j in range(n-i+1):
            if 10000*i + 5000*j + 1000*(n-i-j) == y:
                print(i,j,(n-i-j))
                exit()
    print("-1 -1 -1") 
main()

Measured memory_bytes: 2940