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

using namespace std;

typedef long long LL;

int N;
int a[3005];

LL dp[3005][3005][2];
bool done[3005][3005][2];

LL solve(int st, int dr, int who)
{
    if(st > dr) return 0;
    if(done[st][dr][who])   return dp[st][dr][who];
    done[st][dr][who] = 1;

    LL ans = 0;
    if(who == 1)
        ans = max( a[st] + solve(st + 1, dr, 0), a[dr] + solve(st, dr - 1, 0) );
    else
        ans = min( -a[st] + solve(st + 1, dr, 1), -a[dr] + solve(st, dr - 1, 1) );
    dp[st][dr][who] = ans;
    return ans;
}

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

    LL ans = solve(1, N, 1);
    cout << ans << '\n';
}

Measured memory_bytes: 158208
#include<bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
	return (!b)?a:gcd(b,a%b);
}
int main(){
	long long a,b,c,d,l;
	cin>>a>>b>>c>>d;l=c*d/gcd(c,d);
	cout<<(b-b/c-b/d+b/l)-((a-1)-(a-1)/c-(a-1)/d+(a-1)/l)<<endl;
	return 0;
} 

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<bool>B(N);
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		if (x == y) {
			B[i] = true;
		}
		else {
			B[i] = false;
		}
	}
	for (int i = 2; i < N; ++i) {
		if ((B[i]) && (B[i - 1]) && (B[i - 2])) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main(){
    long long N;  cin >> N;
    N++;
    string s = to_string(N);
    int n = s.length();
    if(s[0]=='1'){
        cout << 9*(n-1) << endl;
    }else{
        cout << 9*(n-1) + (s[0]-'0' - 1) << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int i;
    int num;
    int max=-1000000;
    int min=1000000;
    long int sum=0;
    scanf("%d",&i);
    for(int k=1;k<=i;k++){
        scanf("%d",&num);
        if(max<=num){
            max=num;
        }
        if(min>=num){
            min=num;
        }
        sum+=num;
    }
    printf("%d %d %ld\n",min,max,sum);
    
    return 0;
}


Measured memory_bytes: 2096
#高速化heapqダイクストラ
from collections import *
from heapq import*
import sys
input=lambda:sys.stdin.readline()


def DIJKSTRA(point,d):
    cost      = [float("inf")]*(n+1)
    Q         = []
    cost[point]=0
    heappush(Q,(point,cost[point]))
    while Q:
        prefnd,tmpC=heappop(Q)
        if cost[prefnd]<tmpC:
            continue
        for node,c in d[prefnd]:
            altC=c+tmpC
            if cost[node]>altC:
                cost[node]=altC
                heappush(Q,(node,altC))
    return cost

n=int(input())
d={}
for i in range(n-1):
    a,b=map(int,input().split())
    if a in d.keys():
        d[a].append([b,1])
    else:
        d[a]=[[b,1]]
    if b in d.keys():
        d[b].append([a,1])
    else:
        d[b]=[[a,1]]
        
x=DIJKSTRA(1,d)[1:]
y=DIJKSTRA(n,d)[1:]
#print(x)
#print(y)
F=0
S=0
for s,t in zip(x,y):
    if s<=t:
        F+=1
    else:
        S+=1
if F<=S:
    print("Snuke")
else:
    print("Fennec")

Measured memory_bytes: 54496
#include<iostream>
using namespace std;
int n,m,a[40],b[40],c[41];
void solve(int l,int r){
  //cout<<"l:"<<l<<",r:"<<r<<",m:"<<m<<endl;//確認用
  if(l>r)return;
  int x=a[m++];
  //cout<<"x:"<<x<<",c[x]-1:"<<c[x]-1<<",c[x]+1:"<<c[x]+1<<endl;//確認用
  solve(l,c[x]-1);
  solve(c[x]+1,r);
  cout<<x<<" \n"[x==a[0]];
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i],c[b[i]]=i;
  solve(0,n-1);
  return 0;
}



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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

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

	V<int> v(n+1);

	REP(i,n-1) {
		cin >> t;
		v[--t]++;
	}

	REP(i,n) {
		cout << v[i] << endl;
	}

}



Measured memory_bytes: 4048
def warshall_floyd(d, next_node):
    # d: nxn adjacent matrix
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    next_node[i][j] = next_node[i][k]
 
 
INF = float("inf")
 
n, m = map(int, input().split())
d = [[INF] * n for _ in range(n)]
next_node = [list(range(n)) for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for j in range(m):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    d[a][b] = d[b][a] = c
 
warshall_floyd(d, next_node)
 
used_path = set()
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        used_path.add((i, next_node[i][j]))
        used_path.add((next_node[i][j], i))
 
ans = m - len(used_path) // 2
 
print(ans)

Measured memory_bytes: 3568
K, A, B = map(int, input().split())
ans = 0
if A + 1 >= B or K + 1 <= A :
    ans = K + 1
else:
    ans = ans + B
    ans = ans + (K - A - 1) // 2 * (B - A)
    ans = ans + (K - A - 1) % 2

print(ans)


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

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

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();
  let c = read::<i64>();

  println!("{}", if (10 * b + c) % 4 == 0 { "YES" } else { "NO" })
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l=a+b, r=c+d;

    if(l>r) cout << "Left" << endl;
    if(l<r) cout << "Right" << endl;
    if(l==r) cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[6];
    for(int i=0;i<6;i++)
        cin>>s[i];
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(a+k<e) cout<<":("<<endl;
  else cout<<"Yay!"<<endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
reds=[]
for _ in range(N):
    red=[]
    a,b=map(int,input().split())
    red.append(b)
    red.append(a)
    reds.append(red)
blues=[]
for _ in range(N):
    blue=[]
    c,d=map(int,input().split())
    blue.append(c)
    blue.append(d)
    blues.append(blue)
reds2=sorted(reds)
blues2=sorted(blues)
answer=0
for b in blues2:
    A=[a for a in reds2 if a[1]<b[0] and a[0]<b[1]]
    if len(A)==0:
        continue
    else:
        delete=A[-1]
        reds2.remove(delete)
        answer+=1
print(answer)


Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    int sum=0;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    if(sum<n)
        cout<<n-sum;
    else if(sum==n)
        cout<<"0";
    else
        cout<<"-1";
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include <numeric>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;



int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

bool dp[200200], dp2[200020];
int a[200020], b[200020];
int main() {
	int N, M;
	cin >> N >> M;
	REP(i, M) {
		cin >> a[i] >> b[i];
	}
	REP(i, N) {
		dp[i] = false;
	}
	dp[1] = true;

	REP(i, M) {
		if (a[i]==1)dp[b[i]] = true;
	}
	REP(i, M) {
		if (dp[a[i]])dp2[b[i]] = true;
	}
	if (dp2[N])cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
const int N=100005;
long long f[N];
int main ()
{
	int n;
	scanf("%d",&n);
	f[0]=2,f[1]=1;
	for(int i=2;i<=n;i++)
	    f[i]=f[i-1]+f[i-2];
	printf("%lld\n",f[n]);
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

sum_odd = sum([v for v in A[1::2]])
x0 = sum(A)-2*sum_odd
ans = [x0]

x = x0
for a in A:
    nex = 2*a-x
    ans.append(nex)
    x = nex
print(*ans[:-1])


Measured memory_bytes: 14316
#include<iostream>
using namespace std;
int main(){
    int k,s;
    cin>>k>>s;
    int count=0;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            
            if(s-i-j<=k&&s-i-j>=0)
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 3604
N, K = list(map(int, input().split())) 

count = 0

R = N % K

for a in range(1, N + 1):
	r = a % K
	if 2 * r % K == 0:
		if r == 0:
			count += (N // K) ** 2
		elif R >= r:
			count += (N // K + 1) ** 2
		else:
			count += (N // K) ** 2


print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
     
typedef long long lo;
     
template<typename tp> inline void read(tp &x) {
	x = 0; char c = getchar(); int f = 0;
	for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
	for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if (f) x = -x;
}
const int N = 2e5 + 233;
int n, k, a[N], b[N];
multiset <int> s;

int main(void) {
	read(n); read(k);
	rep (i, n) read(a[i]);
	rep (i, k) s.insert(a[i]);
	rep (i, n - 1) b[i] = (a[i] < a[i + 1]) + b[i - 1];
	int ans = 1;
	for (int i = k + 1; i <= n; i++) {
		auto it = s.find(a[i - k]);
		int tt = (b[i - 1] - b[i - 1 - (k - 1)]) == (k - 1);
		if (it == s.begin() && a[i] > *--s.end() && !tt) {
			--ans;
		}
		s.erase(it);
		s.insert(a[i]);
		++ans;
	}
	// rep (i, n - 1) cout << b[i] << " \n"[i == n - 1];
	int all = 0;
	rep (i, n - 1) if (i >= (k - 1)) all += (b[i] - b[i - (k - 1)]) == (k - 1);
	// cout << ans << " " << all << "\n";
	cout << ans - (all >= 2 ? all - 1 : 0) << "\n";
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
ll a[100010];
int main(void){
	cin >> n;
	rep(i, n) cin >> a[i];

	ll sum = 0;
	ll cnt = 0;
	rep(i, n){
		sum += a[i];
		if(i % 2){ //+
			if(sum ==  0){
				sum++;
				cnt++;
			}else if(sum < 0){
				ll d = abs(sum) + 1;
				sum = 1;
				cnt += d;
			}
		}else{ //-
			if(sum == 0){
				sum--;
				cnt++;
			}else if(sum > 0){
				ll d = sum + 1;
				sum = -1;
				cnt += d;
			}
		}
	}

	ll bsum = 0;
	ll bcnt = 0;
	rep(i, n){
		bsum += a[i];
		if(i % 2 == 0){ //+
			if(bsum ==  0){
				bsum++;
				bcnt++;
			}else if(bsum < 0){
				ll d = abs(bsum) + 1;
				bsum = 1;
				bcnt += d;
			}
		}else{ //-
			if(bsum == 0){
				bsum--;
				bcnt++;
			}else if(bsum > 0){
				ll d = bsum + 1;
				bsum = -1;
				bcnt += d;
			}
		}
	}
	printf("%lld\n", min(cnt, bcnt));

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
bool f[105];
int main()
{
	int m;
	cin>>m;
	f[0]=true;
	f[4]=true;
	for(int i=7;i<=m;i++)
	{
		if(f[i-4]==true||f[i-7]==true)
		{
			f[i]=true;
		}
	}
	if(f[m]==true)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


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

int main(){
  int n,m;
  cin >> n;
  vector<string> ss(n+1);
  for(int i=0;i<n;i++){
    cin >> ss.at(i) ;
  }
  ss.at(n) = "";
  cin >> m;
  vector<string> tt(m);
  for(int i=0;i<m;i++){
    cin >> tt.at(i);
  }

  int maxval = -20;
  int count;
  string str;
  for(int i=0;i<n+1;i++){
    count = 0;
    str = ss.at(i);
    for(int j=0;j<n;j++){
      if(ss.at(j) == str){
        count++;
      }
    }
    for(int j=0;j<m;j++){
      if(tt.at(j)==str){
        count--;
      }
    }
    if(count > maxval){
      maxval = count;
    }
    
  }
  cout << maxval << endl;
}

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

int main(){
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    int z = X;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        z = max(z, x);
    }
    z++;
    bool flag = true;
    for(int i=0; i<m; i++){
        int y;
        cin >> y;
        if(z > y) flag = false;
    }
    if(flag && X < z && z <= Y) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
if N<=26:
    print(chr(N+96))
else:
    s = ''
    tmp = N
    while True:
        ttmp = tmp%26
        if ttmp==0:
            ttmp = 26
        s = chr(ttmp+96)+s
        if tmp<=26:
            break
        tmp = (tmp-ttmp)//26
    print(s)

Measured memory_bytes: 9180
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 0x3f3f3f3f
int h[100005];
int main()
{
	int n,k,hmax,hmin;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
			scanf("%d",&h[i]);
	sort(h,h+n);
	int mi=maxn;
	for(int i=n-1;i>=0;i--)
	{
		hmax=h[i];
		if(i-k+1<0)
			break;
		hmin=h[i-k+1];
		int num=hmax-hmin;
		mi=min(mi,num);
	}
	printf("%d\n",mi);
	return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int r;
	cin >> r;
	if (r < 1200)
		cout << "ABC" << endl;
	else if (r < 2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;
} 

Measured memory_bytes: 3612
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func combination(n int, k int) int {
	return permutation(n, k) / factorial(k)
}

func homogeneous(n int, k int) int {
	return combination(n+k-1, k)
}

func main() {
	r := oneInt()
	ans := 3 * pow(r, 2)
	fmt.Print(ans)
}

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

int main(){
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  for(int64_t i=0; i<N; i++){
    cin >> A.at(i);
    B.at(i)=A.at(i);
  }
  sort(A.begin(), A.end());
  int64_t Ans=0;
  int64_t t=1;
  map<int64_t, int64_t> M;
  for(int64_t i=1; i<N; i++){
    if(A.at(i)==A.at(i-1)){
      t++;
    }
    else{
      M[A.at(i-1)]=t;
      Ans+=t*(t-1)/2;
      t=1;
    }
  }
  M[A.at(N-1)]=t;
  Ans+=t*(t-1)/2;
  for(int64_t i=0; i<N; i++){
    t=M[B.at(i)];
    cout << Ans-t*(t-1)/2+(t-1)*(t-2)/2 << endl;
  }
}

Measured memory_bytes: 12672
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b;
        scanf("%d:%d", &a, &b);
        int aa = a*60+b, bb = 12*b;
        int p = min(abs(aa-bb), (720-abs(aa-bb))%720);
        if(p < 60) puts("alert");
        else if(p < 180) puts("warning");
        else puts("safe");
    }
    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 305;
const long long INF = 1E18;
long long dis[maxn][maxn];
int main()
{
    int n, m, l; cin >> n >> m >> l;
    for( int i = 1; i <= n; ++ i )
        for( int j = 1; j <= n; ++ j ) dis[i][j] = INF;
    for( int i = 0; i < m; ++ i )
    {
        int a, b, c; cin >> a >> b >> c;
        dis[a][b] = dis[b][a] = c;
    }
    for( int k = 1; k <= n; ++ k )
        for( int i = 1; i <= n; ++ i )
            for( int j = 1; j <= n; ++ j )
                dis[i][j] = min( dis[i][j], dis[i][k] + dis[k][j] );
    for( int i = 1; i <= n ; ++ i )
        for( int j = 1; j <= n; ++ j )
            if( dis[i][j] <= l ) dis[i][j] = 1;
            else dis[i][j] = INF;
    for( int k = 1; k <= n; ++ k )
        for( int i = 1; i <= n; ++ i )
            for( int j = 1; j <= n; ++ j )
                dis[i][j] = min( dis[i][j], dis[i][k] + dis[k][j] );
    int q; cin >> q;
    while( q -- )
    {
        int a, b;
        cin >> a >> b;
        if( dis[a][b] >= INF )
            cout << -1 << endl;
        else
            cout << dis[a][b] - 1 << endl;
    }
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cmath>

long long p[19][19];
long long sum[20][20];

int main(){
    double x;
    long long a;
    int n;
    scanf("%d", &n);
    int i;
    for(i = 0; i < n; ++i){
        scanf("%lf", &x);
        x *= 1000000000.0;
        a = llround(x);
        int n2 = 0, n5 = 0;
        while(a % 2 == 0){
            ++n2;
            a /= 2;
        }
        while(a % 5 == 0){
            ++n5;
            a /= 5;
        }
        if(n2 > 18)
            n2 = 18;
        if(n5 > 18)
            n5 = 18;
        ++p[n2][n5];
    }
    int j;
    for(i = 18; i >= 0; --i)
        for(j = 18; j >= 0; --j)
            sum[i][j] = p[i][j] + sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1];
    long long ans = 0;
    for(i = 18; i >= 0; --i)
        for(j = 18; j >= 0; --j){
            if(i >= 18 - i && j >= 18 - j)
                ans += p[i][j] * (sum[18 - i][18 - j] - 1);
            else
                ans += p[i][j] * sum[18 - i][18 - j]; 
        }
    printf("%lld\n", ans / 2);
    return 0;
}


Measured memory_bytes: 2196
def main():  
  N,M=map(int,input().split())
  A=list(map(int,input().split()))
  dp=[2,5,5,4,5,6,3,7,6]
  p=[]
  q=[]
  for i in range(M):
    p.append(dp[A[i]-1])
    q.append(A[i])
  bp=[[0,0]for i in range(N+1)]
  for i in range(N-1):
    for j in range(len(p)):
      if i+p[j]>N:
        continue
      if bp[i][0]==0:
          if i!=0:
              continue
      bp[i+p[j]][0]=max(bp[i+p[j]][0],bp[i][0]+(10**bp[i][1])*q[j])
      bp[i+p[j]][1]=bp[i][1]+1
  print(bp[N][0])
if __name__=='__main__':
  main()

Measured memory_bytes: 21992
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)

int n,x[101],y[101];
const double PI=acos(-1);
double k[101];

int main(){
	scanf("%d",&n);
	if(n==2){puts("0.5\n0.5");return 0;}
	F(i,1,n) scanf("%d%d",x+i,y+i);
	F(i,1,n){
		int cnt=0;
		F(j,1,n) if(j!=i){
			k[++cnt]=atan2(x[j]-x[i],y[j]-y[i]);
		}
		std::sort(k+1,k+cnt+1);
		double t;
		t=k[1]-k[cnt]+PI+PI;
		if(t>=PI) {printf("%.15lf\n",(t-PI)/(PI+PI)); continue;}
		bool ok=0;
		F(j,1,cnt-1){
			t=k[j+1]-k[j];
			if(t>=PI) {printf("%.15lf\n",(t-PI)/(PI+PI)); ok=1; break;}
		} if(!ok) printf("%.15lf\n",0.);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char a;
    cin >> a ;
    
    if(a == 'A')
    {
        cout << 'T' << endl;
    }
    else if(a == 'T')
    {
        cout << 'A' << endl;
    }
    else if(a=='C')
    {
        cout << 'G' <<endl;
    }
    else
    {
        cout << 'C' << endl;
    }
}

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

int a[100010] = { 0 };

int main(){
    //n:人数
    int n, k, q;
    cin >> n >> k >> q;
    for(int i = 1; i <= n; ++i){
        a[i] = k - q;
    }

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

    for(int i = 1; i <= n; ++i){
        if(a[i] <= 0){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
}

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

using namespace std;

int digit(long long n){
    int ret=0;
    do{
        n/=10;
        ++ret;
    } while(n);
    return ret;
}

int main(){
    long long n; cin >> n;
    int ans=digit(n);
    for(long long i=2; i*i<=n; ++i){
        if(n%i!=0) continue;
        ans=min(ans, digit(n/i));
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    int n, a[100005], vis[100005];
    cin >> n;
    fill(vis, vis + 100005, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int i = 1, cnt = 0;
    while (!vis[a[i]]) {
        i = a[i];
        vis[i] = 1;
        cnt++;
        if (i == 2) {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector <vector<bitset<13002>>> dp(82,vector <bitset<13002>>(82));
vector <vector<int>> a(81,vector <int>(81));
vector <vector<int>> b(81,vector <int>(81));
int h,w;
signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>h>>w;
    rep(i, h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    rep(i, h){
        rep(j,w){
            cin>>b[i][j];
        }
    }
    dp[0][0].set(6500);
    //queue <pair<int,itn>> q;
    //q.push({0,0});
    vector <vector<int>> v(h,vector <int>(w));
    /*while(!q.empty()){
        int y = q.front().F, x = q.front().S;
        q.pop();
        if(v[y][x]) continue;
        v[y][x] = true;
        int sa1 = a[y][x] - b[y][x], sa2 = b[y][x] - a[y][x];
        if(y - 1 >= 0){
            dp[y][x] |= dp[y-1][x];
        }
        if(x - 1>= 0){
            dp[y][x] |= dp[y][x-1];
        }
        dp[y][x] = ( (dp[y][x] <<sa1) | (dp[y][x] << sa2) );
        if(y + 1 < h) q.push({y+1,x});
        if(x + 1 < w) q.push({y, x+1});
    }*/
    rep(i,h){
        rep(j,w){
            int y = i, x = j;
            bitset<13002> tmp;
            if(i == 0 && j == 0) tmp.set(6500);
            if(y - 1 >= 0){
                tmp |= dp[y-1][x];
            }
            if(x - 1>= 0){
                tmp |= dp[y][x-1];
            }
            int sa1 = a[y][x] - b[y][x], sa2 = b[y][x] - a[y][x];
            
            bitset<13002> tmp2 = tmp;
            if(sa1 >= 0) tmp <<= sa1;
            else tmp >>= abs(sa1);

            if(sa2 >= 0) tmp2 <<= sa2;
            else tmp2 >>= abs(sa2);
            dp[y][x] = (tmp | tmp2);
            
        }
    }
    rep(i,6400){
        if(dp[h-1][w-1][i + 6500] || dp[h-1][w-1][-i+6500]){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 11260
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var XYZ = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var X = XYZ[0];
            var Y = XYZ[1];
            var Z = XYZ[2];

            Console.WriteLine((X - Z) / (Y + Z));
        }
    }
}


Measured memory_bytes: 28180
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: String = input();
    println!("{}", s.chars().filter(|&c| c == '1').count());
}


Measured memory_bytes: 4352
function Main(input) {
    var N = parseInt(input[0], 10);
    var K = parseInt(input[1], 10);

    var kakurituList = [0.5]; // 連続で表をだす確率のリスト(17回やれば必ず100000を越えるため長さは14)
    for (i = 0; i < 16; i ++) {
        kakurituList.push(kakurituList[i]/2);
    }

    var numList = []; // 何回表を出す必要があるかのリスト
    for (var nIndex = 1; nIndex < N + 1; nIndex++) {
        var num = nIndex; // サイコロで出した数
        var omoteNum = 0;
        while (num < K) {
            num = num * 2;
            omoteNum++;
        }
        numList.push(omoteNum);
    }
    // console.log(numList);

    var result = 0;
    var nKakuritu = 1 / N;

    for (var rIndex = 0; rIndex < numList.length; rIndex++) {
        result += numList[rIndex] !== 0 ? kakurituList[numList[rIndex] - 1] : 1;
    }

    console.log(result * nKakuritu);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 14924
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
  int n,r;
  cin >> n >> r;
  if(n==0&&r==0) break;
  vector<int> a(n);

  for(int i=0;i<a.size();i++){
    a[i] = n-i;
    //cout << a[i] << endl;
  }
  for(int k=0;k<r;k++){
  int p,c;
  cin >> p >> c;
  vector<int> tori(c),tmp(p-1);

    for(int i=0;i<(p-1);i++){
      tmp[i]=a[i];
      //cout << endl << tmp[i] << endl << endl;
    }
    for(int i=0;i<c;i++){
      tori[i]=a[(p-1)+i];
      //cout << tori[i] << endl;
    }
    /*for(int i=0;i<c;i++){
      cout << tori[i] << endl;
    }*/
    for(int i=0;i<c;i++){
      a[i]=tori[i];
    }
    int j=0;
    for(int i = c;i<(c+p-1);i++){
      a[i] = tmp[j];
      j++;
    }

  }
  cout << a[0] << endl; 
}
  }



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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    while (1)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
            return 0;

        REP(i, H)
        {
            REP(j, W)
            {
                if (i % 2 == j % 2)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100000+5;
int n,h[MAXN],dp[MAXN],k;

int main(){
	cin>>n>>k;
	cin>>h[1];
	for(int i=2;i<=n;++i){
		cin>>h[i];
		dp[i]=dp[i-1]+abs(h[i-1]-h[i]);
		for(int j=2;j<=k;++j)
			if(i>j && dp[i-j]+abs(h[i-j]-h[i])<dp[i]) dp[i]=dp[i-j]+abs(h[i-j]-h[i]); 
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int main() {
	string s;
	cin >> s;
	
	bool check = true;
	int x = 0;
	int y = s.size() - 1;
	rep(i, s.size() / 2) {
		if (s[x] != s[y]) {
			check = false;
			break;
		}
		x++;
		y--;
	}

	x = 0;
	y = ((s.size() - 1) / 2) - 1;
	rep(i, ((s.size() - 1) / 2) / 2) {
		if (s[x] != s[y]) {
			check = false;
			break;
		}
		x++;
		y--;
	}

	x = ((s.size() + 3) / 2) - 1;
	y = s.size() - 1;
	rep(i, ((s.size() - 1) / 2) / 2) {
		if (s[x] != s[y]) {
			check = false;
			break;
		}
		x++;
		y--;
	}

	if (check) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

d = {}
for each in a:
  d[each] = d.get(each, 0) + 1
  d[each-1] = d.get(each-1, 0) + 1
  d[each+1] = d.get(each+1, 0) + 1
  
print(max(d.values()))

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a+b==15){
    cout << '+' << endl;
    return 0;
  }
  if(a*b==15){
    cout << '*' << endl;
    return 0;
  }
  cout << 'x' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    vector<int> As(n);
    rep(i,n) cin >> As.at(i);
    int total = 0;
    rep(i,n) total += As.at(i);
    sort(As.begin(), As.end());
    if((ll)As.at(n - m) * 4 * m >= total){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();

        int b = sc.nextInt();

        if (a - (b * 2) >= 0) {
            System.out.println(a - (b * 2));
        } else {
            System.out.println(0);
        }



    }
}


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

int main() {
  int64_t N,K=0;
  cin>>N;
  vector<char> p;
  while(N>0){
    char Q='a';
    if(N%26!=0){
      Q+=(N%26-1);
    }
    else{
      Q='z';
      N--;
    }
    p.push_back(Q);
    N/=26;
    K++;
  }
  reverse(p.begin(),p.end());
  for(int i=0;i<K;i++){
    cout<<p.at(i);
  }
  cout<<endl;
    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
int f(ll a){
    ll res = 0;
    while(a%2==0 && a>=1){
        res++;
        a/=2;
    }
    return res;
}
ll gcd(ll a,ll b){
    ll c;
    while(a%b){
        c = b;
        b = a%b;
        a = c;
    }
    return b;
}
ll lcm(ll a,ll b){
    return a*b/ gcd(a,b);
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    ll N,M;
    cin >> N >> M;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
    }
    ll t = f(a[0]);
    rep(i,N){
        if(t!= f(a[i])){
            cout << 0 << endl;
            return 0;
        }
    }
    ll T = a[0]/2;
    rep(i,N){
        T = lcm(T,a[i]/2);
        if(T>M){
            cout << 0 << endl;
            return 0;
        }
    }
    ll X = T;
    ll ans = 0;
    ll now = X;
    while(now<=M){
        ans ++;
        now += 2*X;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
M, D = list(map(int, input().split()))

cnt = 0

for m in range(1, M+1):
    for d in range(22, D+1):
        d10 = int(d/10)
        d1 = d % 10
        if (d10 < 2) or (d1 < 2):
            continue
        else:
            if d10 * d1 == m:
                cnt += 1

print(cnt)


Measured memory_bytes: 2940
s = int(input())
if s == 1 or s == 2:
    print(4)
else:
    def f(n):
        if n % 2 == 0:
            return int(n / 2)
        else:
            return 3 * n + 1
    LIST = []
    a=s
    while a!=1:
        LIST.append(a)
        a=f(a)
    print(len(LIST)+2)

Measured memory_bytes: 3060
#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)

int main() {
	
	int n;
	while (cin >> n, n) {
		bool grid[255][255];
		
		REP(i, n) {
			string str;
			cin >> str;
			REP(j, n) {
				grid[i][j] = !!(str[j] - '0');
			}
		}
		int ans = 0, cnt;
		
		REP(i, n) {
			cnt = 0;
			REP(j, n) {
				if (!grid[i][j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, n) {
				if (!grid[j][i]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[i - j][j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[i - j][n - 1 - j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[n - 1 - i + j][j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[n - 1 - i + j][n - 1 - j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1272
//raja1999

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define int ll

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


//std::ios::sync_with_stdio(false);

int main(){
	std::ios::sync_with_stdio(false); cin.tie(NULL);
	ll x,cur,yr;
	cin>>x;
	cur=100;
	yr=0;
	while(cur<x){
		cur+=cur/100;
		yr++;
	}
	cout<<yr<<endl;
	return 0;
} 


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

typedef long long ll;
typedef long long unsigned ull;

int main() {
    int n, h, w;
    ll c[10];
    cin >> h >> w >> n;
    for (int i = 0; i < 10; i++) c[i] = 0;
    c[0] = (ll)(h - 2) * (w - 2);
    vector<pair<int, int>> m(n);
    set<pair<int, int>> s;
    for (auto &e:m) {
        cin >> e.first >> e.second;
        for (int i = -2; i < 3; i++)
            for (int j = -2; j < 3; j++)
                if (e.first + i > 0 && e.first + i <= h && e.second + j > 0 && e.second + j < +w)
                    s.insert(make_pair(e.first + i, e.second + j));
    }
    sort(m.begin(), m.end());
    for (auto &e:s) {
        if (e.first + 2 > h || e.second + 2 > w) continue;
        int d = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (binary_search(m.begin(), m.end(), make_pair(e.first + i, e.second + j))) d++;
            }
        }
        c[d]++;
        c[0]--;
    }
    for(int i = 0;i < 10;i++) cout << c[i] << endl;
}

Measured memory_bytes: 120192
N, W = map(int, input().split())
a = []
for i in range(N):
    x,y = map(int,input().split())
    a.append([x,y])
dp = [0]*(W+1)
max_weight = 0

for w, v in a:
    max_w = min(max_weight, W-w)
    for old_v, from_i in zip(dp[max_w::-1], range(max_w, -1, -1)):
        if dp[from_i+w] < old_v + v:
            dp[from_i+w] = old_v + v
    max_weight = min(max_weight+w, W)

print(max(dp))


Measured memory_bytes: 61040
using System;

namespace Bite_Eating
{
    class Program
    {
        static void Main(string[] args)
        {
            string arg = Console.ReadLine();
            string[] w = arg.Split(' ');
            int n = int.Parse(w[0]);
            int L = int.Parse(w[1]);

            int b;
            if( L < 0)
            {
                int ws = n + L;
                if(ws <= 0)
                {
                    b = n-1;
                }
                else
                {
                    b = n - ws;
                }

            }
            else
            {
                b = 0;
            }
            int start = L;
            int sum = 0;
            for(int i = 0;i<n;i++)
            {
                if(i == b)
                {
                    sum += 0;
                }
                else
                {
                    sum += start;
                }
                start++;
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		br.readLine();
		String[] tmp = br.readLine().split(" ");
		List<Integer> S = new ArrayList<Integer>();
		S.add(Integer.parseInt(tmp[0]));
		for (int i = 1; i < tmp.length; i++) {
			if (!tmp[i].equals(tmp[i - 1]))
				S.add(Integer.parseInt(tmp[i]));
		}
		br.readLine();
		String[] T = br.readLine().split(" ");

		int cnt = 0;
		for (String s : T) {
			if (Collections.binarySearch(S, Integer.parseInt(s)) >= 0) {
				cnt++;
			}
		}
		System.out.println(cnt);

		if (br != null) {
			br.close();
			br = null;
		}
	}
}

Measured memory_bytes: 40772
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    int a,b;
    cin>>a>>b;
    cout<<max(a+a-1,max(b+b-1,a+b))<<endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int a[maxn];
int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    --a[i];
  }
  return 1;
}

void solve() {
  int res = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] < i && a[a[i]] == i) {
      ++res;
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void dump_(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

inline vector<int> digit(unsigned long long n) {
  vector<int> ret;
  do { ret.push_back(n % 10); n /= 10; } while (n > 0);
  return ret;
}

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

  VAR(int, x);
  vector<int> dig = digit(x);
  int a = dig[3], b = dig[2], c = dig[1], d = dig[0];

  if (a + b + c + d == 7) OUTN(a, '+', b, '+', c, '+', d, '=', 7, "\n");
  else if (a - b + c + d == 7) OUTN(a, '-', b, '+', c, '+', d, '=', 7, "\n");
  else if (a + b - c + d == 7) OUTN(a, '+', b, '-', c, '+', d, '=', 7, "\n");
  else if (a + b + c - d == 7) OUTN(a, '+', b, '+', c, '-', d, '=', 7, "\n");
  else if (a - b - c + d == 7) OUTN(a, '-', b, '-', c, '+', d, '=', 7, "\n");
  else if (a + b - c - d == 7) OUTN(a, '+', b, '-', c, '-', d, '=', 7, "\n");
  else if (a - b + c - d == 7) OUTN(a, '-', b, '+', c, '-', d, '=', 7, "\n");
  else if (a - b - c - d == 7) OUTN(a, '-', b, '-', c, '-', d, '=', 7, "\n");

  return 0;
}


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

vector<int> Input(const int n)
{
	vector<int> W;
	for(int i = 0; i < n; i++){
		int w;
		cin >> w;
		W.push_back(w);
	}
	return W;
}

bool IsAllLoaded(int P, vector<int>& W, int k)
{
	int TrackIndex = 0;
	int CurrentSum = 0;
	int i = 0;
	for(i = 0; i < W.size(); i++){
		if(W[i] > P){
			return false;
		}
		if(CurrentSum + W[i] > P){
			TrackIndex++;
			if(TrackIndex == k){
				return false;
			}
			CurrentSum = 0;
		}
		CurrentSum += W[i];
	}
	return true;
}

int Calc(vector<int> &W, int k)
{
	int Sum = accumulate(W.begin(), W.end(), 0 );
	int Ave = Sum / W.size();
	int e = Sum;
	int s = Ave - 1;
	int m = (e + s) / 2;
//	cout << s << ' ' << m << ' ' << e << endl;
	
	while(e > s + 1){
		if(IsAllLoaded(m, W, k)){
			e = m;
			m = (s + m) / 2;
		}else if(!IsAllLoaded(m+1, W, k)){
			s = m;
			m = (e + m) / 2;
		}else{
			return m + 1;
		}
//		cout << s << ' ' << m << ' ' << e << endl;
	}
	return e;
}

int main()
{
	int n, k; //n:???????????° k:?????????????????°  
	cin >> n >> k;
	vector<int> W = Input(n);
	int P = Calc(W, k); //P:??????????????????????????????????????????????????§????????????????°????
	cout << P << endl;
	return 0;
}

Measured memory_bytes: 3520