akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define mp make_pair
#define pb push_back
#define FI first
#define SE second
#define FOR(i,a,b) for(int (i)=((int)a); (i)<((int)b); (i)++) // [a,b)
#define REP(i,N) FOR((i), 0, ((int)N)) // [0,N)
#define INF (1 << 30)
#define all(v) (v).begin(),(v).end()
#define vcin(v,N) REP(i,N) cin >> v[i] // 配列にも使用可能
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
#define vidx(v,it) distance((v).begin(),(it))
#define vsum(v) accumulate(all(v),0)
#define vsumr(v,a,b) accumulate((v).begin()+(a),(v).begin()+(b),0) //[a,b)
#define vfnd(v,val) find(all(v),val) // itrを返す
#define vcnt(v,val) count(all(v),val)
#define vrep(v,it) for(auto it=(v).begin(); it != (v).end(); ++it)

#ifdef LOCAL
    #define debug(...) fprintf(stderr, __VA_ARGS__)
    #define stopif(val) assert( !(val) )
#else
    #define debug(...) 1
    #define stopif(val) 1
#endif

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int main(){
        int N;
    cin >> N;
    vi v(N);
    vcin(v,N);
    
    int cnt=0,cur=0;
    while(true){
        if(cur == N) break;
        if(v[cur] == 0){
            cur++;
            continue;
        }
        if(v[cur] > 0){
            int idx = cur;
            while(idx < N && v[idx] > 0){
                v[idx]--;
                idx++;
            }
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    cin >> n;
    set<int> s;
    rep(i, n)
    {
        int c;
        cin >> c;
        s.insert(c);
    }

    int q, cnt = 0;
    cin >> q;
    rep(i, q)
    {
        int c;
        cin >> c;
        if (s.find(c) != s.end())
            cnt++;
    }

    OP(cnt);
    return 0;
}


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

int main(void){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    c *= 2;
    int min = a * x + b * y;
    
    int cost;
    int i;
    for(i = 1; i <= max({x, y}); i++){
        cost = c * i;
        if(x > i){
            cost += a * (x - i);
        }
        if(y > i){
            cost += b * (y - i);
        }
        if(cost < min){
            min = cost;
        }
    }
    
    cout << min << endl;
    
    return 0;
}


Measured memory_bytes: 256
import itertools

total = int(input())
text_1 = list(map(int, input().split()))
text_2 = list(map(int, input().split()))
text_1_join = int("".join([str(x) for x in text_1]))
text_2_join = int("".join([str(x) for x in text_2]))

text_1_sort = sorted(text_1)
target = list(itertools.permutations(text_1_sort))
target_join = [int("".join(str(y) for y in x)) for x in target]

get_index_1 = target_join.index(text_1_join) + 1
get_index_2 = target_join.index(text_2_join) + 1

print(abs(get_index_1 - get_index_2))


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

int main(){ 
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<pair<ll,int>> b;
  int prev = 0;
  for (int i = 0; i < n; i++) {
    if (a[prev] != a[i]) {
      if (i - prev >= 2) b.emplace_back(make_pair(a[prev], i - prev));
      prev = i;
    }
  }
  if (n - prev >= 2) b.emplace_back(make_pair(a[prev], n - prev));
  int m = b.size();
  sort(b.begin(), b.end(),greater<pair<ll,int>>());
  ll res = 0;
  for (int i = 0; i < m; i++) {
    if (b[i].second >= 4) {
      res = max(res, b[i].first * b[i].first);
    }  
    if (i > 0) res = max(res, b[0].first * b[i].first);
  }
  cout << res << endl;
  return 0;
} 

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

int main(){
    int a, b, c, d;
    int turn = 1;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0){
        if(turn % 2 == 1){
            c -= b;
        }
        else if(turn % 2 == 0){
            a -= d;
        }
        turn++;
    }
    if(a > 0){
        cout << "Yes" << endl;
    }
    else if(a <= 0){
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int Q = sc.nextInt();
		long s[] = new long[A+2];
		long t[] = new long[B+2];
		long x[] = new long[Q];
		
		//工夫
		s[0]=(long)-1e10;
		t[0]=(long)-1e10;
		s[A+1]=Long.MAX_VALUE;
		t[B+1]=Long.MAX_VALUE;
		
		for(int i=0;i<A;i++) {
			s[i+1]=sc.nextLong();
		}
		for(int i=0;i<B;i++) {
			t[i+1]=sc.nextLong();
		}
		for(int i=0;i<Q;i++) {
			x[i]=sc.nextLong();
		}
		sc.close();
		
		//sort
		Arrays.sort(s);
		Arrays.sort(t);
		
		StringBuilder sb = new StringBuilder();
		
		//xについてループ
		for(int i=0;i<Q;i++) {
			long X = x[i];
			
			long ans = Long.MAX_VALUE;
			for(int k=0;k<2;k++) {
				//神社から見ていく場合
				if(k==0&i!=0) {
					long tmp[] = s;
					s = t;
					t = tmp;
				}//寺から見ていく場合
				else {
					long tmp[] = s;
					s = t;
					t = tmp;
				}
				
				int l = binarySearch(s,X);
				int r = l+1;
				
				//左に行く場合と、右にいく場合
				long dst = 0;

				long Y = 0;
				int l2 = 0;
				int r2 = 0;
				for(int j=0;j<2;j++) {
					if(j==0) {
						//左に行く場合
						if(l==0)continue;
						dst = X-s[l];
						Y = s[l];
					}else {
						//右に行く場合
						if(r==s.length-1)continue;
						dst = s[r]-X;
						Y = s[r];
					}
					l2 = binarySearch(t,Y);
					r2 = l2 + 1;
					dst += Math.min(Y-t[l2], t[r2]-Y);
					ans = Math.min(ans, dst);
				}
			}
			sb.append(ans + "\n");
		}
		System.out.println(sb.toString());
	}
	
	
	//lを返すので、rはl+1で求める。
	static int binarySearch(long v[], long X) {
		int l = -1;
		int r = v.length;
		while(r>l+1) {
			int c = (l+r)/2;
			if(X > v[c]) l=c;
			else r=c;
		}
		return l;
	}
	
}


Measured memory_bytes: 98508
from itertools import permutations
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

a = [i for i in range(1,n+1)]
for i,per in enumerate(list(permutations(a))):
    if per == p:
        x = i
    if per == q:
        y = i
print(abs(x-y))


Measured memory_bytes: 8052
F = list(map(int,input().split()))

A = F[0]
B = F[1]
C = F[2]
D = F[3]

count = 0
while(1):
    if count%2==0:
        C -= B
    else:
        A -= D
    
    count += 1
    if C<=0 or A<=0:
        if C <= 0:
            print('Yes')
            break
        else:
            print('No')
            break



Measured memory_bytes: 9188
#include <iostream>
#include <stdio.h>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
set<char> s;
int main()
{
    int n; char x;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        s.insert(x);
    }
    if(s.size() == 3) cout<<"Three"<<endl;
    else cout<<"Four"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var on int
	fmt.Scan(&on)
	m := make(map[int]int)
	loop := true
	n := on
	for loop {
		loop = false
		for i := 2; i <= int(math.Sqrt(float64(n))); i++ {
			if n%i == 0 {
				m[i]++
				n /= i
				loop = true
				break
			}
		}
	}
	if n != 1 {
		m[n]++
	}

	var cnt int
	for i := 1; i <= int(math.Sqrt(float64(on))); i++ {
		if on%i == 0 {
			if on/i == i {
				cnt++
			} else {
				cnt += 2
			}
		}
	}

	fmt.Printf("%d %d\n", len(m), cnt-1)
}



Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<ll> a(n);
  vector<int> cnt(100005, 0);
  ll sum = 0;
  REP(i,n){ 
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q; cin >> q;
  REP(qq,q){
    ll b,c; cin >> b >> c;
    sum += (c-b)*cnt[b];
    cout << sum << endl;
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  
  return 0;
}


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

int main() {
    ll n,max=0; cin>>n; map<string,ll>m; string s;
    while(n--)
    {
        cin>>s; m[s]++;
        if (m[s]>max){max=m[s];}
    }
    for(auto it=m.begin();it!=m.end();it++)
    {
        if (it->second==max) {cout<<it->first<<endl;}
    }
	return 0;
}

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


vector<int> g[100010];

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n), b(n);
	vector<int> c(n);
	rep(i, n - 1) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	rep(i, n) cin >> c[i];
	sort(c.begin(), c.end());
	reverse(c.begin(), c.end());

	rep(i, n - 1) {
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}

	set<pair<int, int>> used;
	vector<int> ans(n, -1);

	queue<int> que;
	que.push(0);
	ans[0] = c[0];
	int idx = 1;
	while(!que.empty()) {
		int u = que.front(); que.pop();
		for (auto v : g[u]) {
			if (ans[v] != -1) continue;
			que.push(v);
			ans[v] = c[idx++];
		}
	}

	int score = 0;
	for (int i = 1; i < n; ++i) {
		score += c[i];
	}
	printf("%d\n", score);

	for (int i = 0; i < n; ++i) {
		printf("%d ", ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<ll> a(n+1);
  for(int i=0;i<n;i++){
    cin>>a[i+1];
  }
  vector<ll> ans(n+1);
  ll x1=0;
  for(int i=0;i<n;i++){
    ll val=a[i+1];
    if(i%2==1){
      val*=(-1);
    }
    x1+=val;
  }
  ans[1]=x1/2;
  for(int i=1;i<n;i++){
    ans[i+1]=a[i]-ans[i];
  }
  for(int i=0;i<n;i++){
    cout<<ans[i+1]*2<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    unsigned int n;cin>>n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        
        if((i>0&&i<10)||(i>99&&i<1000)||(i>9999&&i<100000))
            cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
flg = True

while True:
    if flg:
        c -= b
        flg = False
    else:
        a -= d
        flg = True

    if a <= 0:
        print('No')
        break
    elif c <= 0:
        print('Yes')
        break


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, tmp;
    cin >> N;
    vector<int64_t> list(N);
    int64_t all = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> list[i];
        all ^= list[i];
    }
    for (int i = 0; i < N; i++)
    {
        tmp = all ^ list[i];
        cout << tmp << " ";
    }
}

Measured memory_bytes: 4736
/*d[n]で最初に発見した時刻を出していき、
f[n]で戻りながら完了時刻をいれていく書き方*/
#include <iostream>
using namespace std;

int r[101][101];
int d[101], f[101], num, visit[101], p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}


Measured memory_bytes: 3096
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int H = Integer.parseInt(sc.next());
        final int W = Integer.parseInt(sc.next());
        final char S[][] = new char[H+2][W+2];
        for (int i=1; i<H+1; i++) {
            S[i] =  ("#" + sc.next() + "#").toCharArray();
        }
        sc.close();
        for (int i=0; i<W+2; i++) {
            S[0][i] = '#';
            S[H+1][i] = '#';
        }
        int lr[][] = new int[H+2][W+2];
        int ud[][] = new int[H+2][W+2];

        for (int i=1; i<H+1; i++) {
            int cnt = 0;
            for (int j=0; j<W+1; j++) {
                if (S[i][j]=='.') {
                    cnt++;
                } else {
                    cnt = 0;
                }
                lr[i][j] = cnt;
            }
            for (int j=W; j>0; j--) {
                if (lr[i][j]==0) {
                    cnt = 0;
                } else if (cnt==0) {
                    cnt = lr[i][j];
                } else {
                    lr[i][j] = cnt;
                }
            }
        }
        for (int j=1; j<W+1; j++) {
            int cnt = 0;
            for (int i=0; i<H+1; i++) {
                if (S[i][j]=='.') {
                    cnt++;
                } else {
                    cnt = 0;
                }
                ud[i][j] = cnt;
            }
            for (int i=H; i>0; i--) {
                if (ud[i][j]==0) {
                    cnt = 0;
                } else if (cnt==0) {
                    cnt = ud[i][j];
                } else {
                    ud[i][j] = cnt;
                }
            }
        }

        int ans = 0;
        for (int i=1; i<H+1; i++) {
            for (int j=1; j<W+1; j++) {
                int cnt = lr[i][j] + ud[i][j];
                if (ans<cnt) ans = cnt;
            }
        }
        ans -= 1;
        System.out.println(ans);
    }
}

Measured memory_bytes: 108364
n = int(input())
l = []

for i in range(1, n + 1):
    if i % 5 == 0 and i % 3 == 0:
        l.append('FizzBuzz')
    elif i % 3 == 0:
        l.append('Fizz')
    elif i % 5 == 0:
        l.append('Buzz')
    else:
        l.append(i)

l_filter = [l[i] for i in range(len(l)) if type(l[i]) == int]
print(sum(l_filter))

Measured memory_bytes: 37752
#include<stdio.h>
int main(){
  int x,y,t;
  while(1){
    scanf("%d %d",&x,&y);
    if (x == 0 && y ==0) break;
    if(x>y){
      t=x;
      x=y;
      y=t;
    }
    printf("%d %d\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 600
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
from fractions import Fraction
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
INF = float("inf")

N,X,M = map(int,input().split())
A = [0]*100010
A[0] = X
d = defaultdict(int)
d[X] = 1
l = [X]

ans = X
for i in range(1,N):
    num = pow(A[i-1],2,M)
    l.append(num)
    if d[num] == 0:
        A[i] = num
        d[num] += 1
        ans += num
    else:
        kaburi = num
        break
else:
    print(ans)
    exit()

kaburi_index = l.index(kaburi)
loop_len = len(l)-1-kaburi_index
loop_sum = sum(l[kaburi_index:len(l)-1])

nokori = N-i
loop = nokori//loop_len
amari = nokori%loop_len

ans += loop_sum*loop
ans += sum(l[kaburi_index:kaburi_index+amari])
#print(A)

print(ans)

Measured memory_bytes: 83760
while True:
	try:
		data = map(float, raw_input().split())
		[a, b, c, d, e, f] = data
		
		n = (c*e - b*f)
		m = (a*f - c*d)
		i = (a*e - b*d)
		x = float(n) / (i)
		y = float(m) / (i)

		x = '%.3f' % (round(x,3))
		y = '%.3f' % (round(y,3))

		if x == '-0.000':
			x = '0.000'
		if y == '-0.000':
			y = '0.000'
			
		print x, y
	
	except EOFError:
		break


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

int main(){

	array<int, 3> temp;
	for (auto& a : temp) {
		cin >> a;
	}
	sort(temp.begin(), temp.end());

	cout << temp[0] << ' ' << temp[1] << ' ' << temp[2] << endl;

	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine());

		int[] A = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

		int v;
		int j;

		out_put(A);

		for (int i = 1; i < N; i++) {
			v = A[i];
			j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;

			out_put(A);
		}

		sc.close();
	}

	private static void out_put(int array[]) {

		System.out.printf("%d", array[0]);

		for (int i = 1; i < array.length; i++) {
			System.out.printf(" %d", array[i]);
		}
		System.out.printf("\n");
	}
}



Measured memory_bytes: 47824
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}

ll inverse_element(ll t){
	return mod_pow(t,MOD-2);
}
ll n;
ll k;
int main(){
    cin>>n>>k;
    if(k>=n-1){
        k=n-1;
    }
    ll ans=0;
    ll nci=1;
    ll n1ci=1;
    for(ll i=1;i<=k;i++){
        nci*=(n-i+1);
        n1ci*=(n-i);
        nci%=MOD;
        n1ci%=MOD;
        nci*=inverse_element(i);
        n1ci*=inverse_element(i);
        nci%=MOD;
        n1ci%=MOD;
        ans+=(nci*n1ci%MOD);
        ans%=MOD;
    }
    cout<<(ans+1)%MOD<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

const ll MOD = 1e9+7;

template<int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) v += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator - () const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator += (const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator -= (const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator *= (const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator /= (const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b; swap(a, b);
      u -= t * v; swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator == (const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator != (const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
    return is >> x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
  friend constexpr Fp<MOD> modinv(const Fp<MOD> &a) noexcept {
    return modpow(a, MOD - 2);
  }
};

using mint = Fp<MOD>;

int N, K;
vector<vector<int>> G;
vector<int> visited;

mint dfs(int u, int n1, int n2) {
  visited[u] = 1;
  mint res = K - n1 - n2;
  for(int v: G[u]) {
    if(visited[v]) continue;
    res *= dfs(v, 1, n1);
    n1++;
  }
  return res;
}

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

  G.resize(N);
  visited.resize(N, 0);

  rep(i,N-1) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  cout << dfs(0, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 9600
k,n= [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

mx = 0
for i in range(n-1):
    tmp = a[i+1] - a[i]
    if mx < tmp:
        mx = tmp

tmp = k - a[n-1] + a[0] 
if tmp > mx:
    mx= tmp

print(k-mx)


Measured memory_bytes: 26420
a, b = map(int, input().split())
c = 0
for i in range(1, a+1):
    d = 0
    e = i
    while True:
        if e >= b:
            c += (1 / a) * (0.5 ** d)
            break
        d += 1
        e *= 2
print(c)


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

void solve(){
  double A,B,H,M;cin>>A>>B>>H>>M;
  double rad = (M_PI/180) * 360 * ((double)H/12.0 + ((double)M/60.0)/12.0 - (double)M/60.0);
  double ans = A*A + B*B - (2*A*B*cos(rad));
  cout<<pow(ans,0.5) << endl;
}
int32_t main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
 #ifndef ONLINE_JUDGE
      freopen("input.txt",  "r",  stdin);
      freopen("output.txt", "w", stdout);
 #endif
 
     cout << setprecision(9) << fixed;
     clock_t z = clock();
 
     int t=1; 
     // cin >> t;
     while (t--) solve();
 
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
     return 0;
}

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

int main()
{
  string s;
  int n;
  cin >> n;
  s = "No";
  rep(i,10){
    rep(j,10){
      if(i*j == n) s = "Yes";
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,x,y;
    cin >> n >> x >> y;
    vector<vector<int> > Graph(n);
    queue<int>que;
    vector<int>dist(n,0);
    vector<int>answer(n,0);
    REP(i,n-1){
        Graph[i].push_back(i+1);
        Graph[i+1].push_back(i);
    }
    x--;
    y--;
    Graph[x].push_back(y);
    Graph[y].push_back(x);
    REP(i,n){
        que.push(i);
        REP(j,n)dist[j]=-1;
        dist[i]=0;
        while(!que.empty()){
            int v = que.front();
            que.pop();

            for(int nv:Graph[v]){
                if(dist[nv]!=-1)
                    continue;
                dist[nv] = dist[v]+1;
                que.push(nv);
            }
        }
        REP(j,n)answer[dist[j]]++;
    }
    FOR(i,1,n)cout << answer[i]/2 << endl;
    return 0;
}

Measured memory_bytes: 3760
import time
from random import randrange
start = time.time()

D=int(input())
c=list(map(int,input().split()))
def compare(d,q):
  score=maxscore
  changebefore=currentans[d]-1
  changeafter=q-1
  r=contests[changebefore]
  score-=s[d][changebefore]
  score+=s[d][changeafter]
  for j in range(len(r)-1):
    if r[j]==d:
      score-=c[changebefore]*((r[j+1]-r[j-1]-1)*(r[j+1]-r[j-1]))//2
      score+=c[changebefore]*((r[j+1]-d-1)*(r[j+1]-d))//2
      score+=c[changebefore]*((d-r[j-1]-1)*(d-r[j-1]))//2
      break
  r=contests[changeafter]
  for j in range(len(r)-1):
    if r[j+1]>d:
      score+=c[changeafter]*((r[j+1]-r[j]-1)*(r[j+1]-r[j]))//2
      score-=c[changeafter]*((r[j+1]-d-1)*(r[j+1]-d))//2
      score-=c[changeafter]*((d-r[j]-1)*(d-r[j]))//2
      break
  if score>maxscore:
    return score
  else:
    return maxscore

s=[0]
last=[0]*26
currentans=[0]*(D+1)
for i in range(D):
  s.append(list(map(int,input().split())))
contests=[]
for i in range(26):
  contests.append([])
  contests[-1].append(0)
  contests[-1].append(D+1)
#Donyoku
for i in range(1,D+1):
  score=0
  t=0
  score+=s[i][t]
  lasttemp=last[t]
  last[t]=i
  for j in range(26):
    score-=c[j]*(i-last[j])
  maxscore=score
  bestans=1
  last[t]=lasttemp
  for t in range(1,26):
    score=0
    score+=s[i][t]
    lasttemp=last[t]
    last[t]=i
    for j in range(26):
      score-=c[j]*(i-last[j])
    if maxscore<score:
      bestans=t+1
      maxscore=score
    last[t]=lasttemp
  last[bestans-1]=i
  currentans[i]=bestans
for i in range(1,D+1):
  contests[currentans[i]-1].append(i)
counter=0
breakflag=0
lastchanged=0
continueflag=0
while True:
  counter+=1
  if counter%100==0:
    now=time.time()
    if now-start>1.75:
      break
  q=randrange(26)+1
  d=randrange(D)+1
  if lastchanged<=d:
    if randrange(2)==0:
      continue
  if currentans[d]==q:
    continue
  score2=compare(d,q)
  if score2>maxscore:
    changebefore=currentans[d]-1
    changeafter=q-1
    contests[changebefore].remove(d)
    contests[changeafter].append(d)
    contests[changeafter].sort()
    currentans[d]=q
    maxscore=score2
    lastchanged=d
for i in range(1,D+1):
  print(currentans[i])

Measured memory_bytes: 85552
#include <stdio.h>

int main(void){
    int N, a, b, c; /*N=100a+10b+c*/

    scanf("%d", &N);
    a = N / 100;
    b = (N - a*100) / 10;
    c = N - a*100 - b*10;

    if(a == 7||b == 7||c==7) printf("Yes\n");
    else printf("No\n");

    return 0;
}

Measured memory_bytes: 1608
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,L;
int a[100100];
int main(){
	cin >> N >> L;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	int l = 0;
	int id = -1;
	for(int i=1;i<N;i++){
		if(l < a[i]+a[i-1]){
			l = a[i]+a[i-1];
			id = i;
		}
	}
	if(l<L){
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	for(int i=1;i<id;i++)cout << i << endl;
	for(int i=N-1;i>id;i--)cout << i << endl;
	cout << id << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
#define ll long long

ll gcd(ll n1, ll n2){
  if(n2 == 0)
    return n1;
  else
    return gcd(n2, n1 % n2);
}
ll lcm(ll n1, ll n2){
  return n1 / gcd(n1, n2) * n2;
}

int main(){
  int N;
  cin >> N;
  vector<ll> T;
  ll ans = 1;
  for(int i=0; i<N; i++){
    ll in;
    cin >> in;
    ans = lcm(max(ans, in), min(ans, in));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int n;
    
    double sum=0, ave=0, a2=0;
    while(true){
        sum=0; ave=0; a2=0;
        scanf("%d", &n);
        if(n==0) break;
        double s[n];
        for(int i=0;i<n;i++){
            scanf("%lf", &s[i]);
            sum += s[i];
        }

        ave = sum/n;
        for(int i=0;i<n;i++){
            a2 += pow((s[i]-ave), 2);
            s[i] = 0;
        }
        printf("%.8lf\n", sqrt(a2/n));
    }
    return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	
}



int main(){
  ll D,G;
  cin>>D>>G;
vector<ll>p(D);
vector<ll>c(D);
 rep(i,D){
    cin>>p[i]>>c[i];
  
  }
  
ll ans=INF;
  
  rep(i,power(2,D)){
    bitset<10>A(i);
    string B=A.to_string();
    ll sum=0;
    ll count=0;
    ll max=0;
    
    for(ll j=9;j>=10-D;j--){
      if(B[j]=='1'){
        sum+=(9-j+1)*100*p[9-j]+c[9-j];
        count+=p[9-j];
      }
      else{
max=9-j;
      }
      
    }
    
    if(sum<G){
      if((G-sum)%((max+1)*100)==0&&(G-sum)/((max+1)*100)<p[max]){
        count+=(G-sum)/((max+1)*100);
        sum+=((G-sum)/((max+1)*100))*(max+1)*100;
      }
      else if((G-sum)%((max+1)*100)!=0&&(G-sum)/((max+1)*100)+1<p[max]){
        count+=(G-sum)/((max+1)*100)+1;
        sum+=((G-sum)/((max+1)*100)+1)*(max+1)*100;
      }
    }
      
      if(sum>=G&&count<ans){
        ans=count;
      }

        
    }
      
    cout<<ans<<endl;
  }
  

  
  

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

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;

    cin >> n;
    vector<ll> arr(n);
    arr = read(n);

    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = abs(arr[1] - arr[0]);

    Fo(i, 2, n) {

        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[i - 2]));

    }

    cout << dp[n - 1];

    return 0;
}




Measured memory_bytes: 4760
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int a[3],k;
	cin >> a[0] >> a[1] >> a[2] >> k;
	GSORT(a,3);
	REP(i,k){
		a[0]*=2;
	}
	cout << a[0]+a[1]+a[2] << endl;
/////////////////////////////////////////////
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int N,K,tmp;
bool check=false;

int main(){
    cin>>N>>K;
    int D[K];
    rep(i,K){
        cin>>D[i];
    }
    while(true){
        tmp=N;
        check=false;
        while(tmp>0){
            rep(i,K){
                if(tmp%10==D[i]){
                    check=true;
                    break;
                }
            }
            if(check)break;
            tmp/=10;
        }
        if(!check)break;
        N++;
    }
    out(N);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
    int t[200],a[200],b[200],c[200],max[200],min[200],d,n,dp[200][2];
    memset(max,0,sizeof(max));
    memset(min,100,sizeof(min));
    scanf("%d %d",&d,&n);
    for(int i=0;i<d;i++) scanf("%d",t+i);
    for(int i=0;i<n;i++) scanf("%d %d %d",a+i,b+i,c+i);
    for(int i=0;i<d;i++){
        for(int j=0;j<n;j++){
            if(a[j]<=t[i]&&b[j]>=t[i]){
                if(max[i]<c[j]) max[i]=c[j];
                if(min[i]>c[j]) min[i]=c[j];
            }
        }
    }
    dp[0][0]=dp[0][1]=0;
    for(int i=1;i<d;i++){
        dp[i][0]=fmax(dp[i-1][1]+fabs(min[i]-max[i-1]),dp[i-1][0]+fabs(min[i]-min[i-1]));
        dp[i][1]=fmax(dp[i-1][1]+fabs(max[i]-max[i-1]),dp[i-1][0]+fabs(max[i]-min[i-1]));
    }
    printf("%d\n",(int)fmax(dp[d-1][0],dp[d-1][1]));
    return 0;
}

Measured memory_bytes: 1040
/*
    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<ll, ll> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
ll D, A;
ll t[MAXN];
II a[MAXN];

void update(int u, ll val) {
    while (u) {
        t[u] += val;
        u = u - (u & (-u));
    }
}

ll get(int u) {
    ll res = 0;
    while (u <= 200000) {
        res += t[u];
        u = u + (u & (-u));
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> D >> A;
    FOR(i,1,n) cin >> a[i].FI >> a[i].SE;
    sort(a+1, a+n+1);
    ll len = D * 2;
    ll res = 0;
    FOR(i,1,n) {
        ll p = max(-get(i) + a[i].SE, 0LL);
        ll num = p / A + (p % A > 0);
        ll damage = num * A;
        res += num;

        ll r = a[i].FI + len;
        int dau = i, cuoi = n, mid;
        while (dau <= cuoi) {
            mid = (dau + cuoi) >> 1;
            if (a[mid].FI > r) cuoi = mid-1;
            else dau = mid+1;
        }
        int R = cuoi;
        update(R, damage);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

typedef long long LL;
using namespace std;

int n, K;
LL res = 0;
int main() 
{
	while(~scanf("%d%d", &n, &K)) {
		res = 0;
		for (int i = 1; i <= n; i++) {
			int x = n / i, y = n % i;
			int now = max(0, i - K);
			if(y != 0) res = res + 1LL * now * x + max(0, y - (K == 0 ? K : K - 1));
			else res = res + 1LL * now * x;
		}
		printf("%lld\n", res);
	}
	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> a >> b;
	A = a * 3 + b;
	while (A >= 2) {
		ans++;
		A -= 2;
	}
	cout << ans;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;
ll N = 1000000;

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cout.setf(ios::fixed); 
	cout.precision(20);

	ll h, w, n;
	cin >> h >> w >> n;
	map<pair<ll, ll>, ll> m;
	ll a, b;
	rep(i, n) {
		cin >> a >> b;
		a--; b--;
		for (int j = -1; j <= 1; j++) {
			for (int k = -1; k <= 1; k++) {
				m[make_pair(a + j, b + k)]++;
			}
		}
	}
	vll ans(10);
	for (auto n : m) {
		if (1 <= n.first.first&&n.first.first < h - 1 && 1 <= n.first.second&&n.first.second < w - 1) {
			//cout << n.first.first << " " << n.first.second << endl;
			ans[n.second]++;
		}
	}
	ans[0] = (h - 2)*(w - 2);
	REP(i, 1, 10)
		ans[0] -= ans[i];
	rep(i, 10) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 56576
n=int(input())
h=list(map(int,input().split()))
res=h[n-1]
for i in range(1,n):
  if h[n-1-i]<=res:
    res=h[n-1-i]
  elif h[n-1-i]==res+1:
    res=h[n-1-i]-1
  else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 84832
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f(i,a,b,c) for(ll i=a;i<b;i+=c)
#define r(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n; cin >> n;
	cout << !(n);
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

ll gcd(ll x, ll y) {
    ll r;
    if (x < y) swap(x, y);

    while(y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
  ll N;
  cin >> N;
  ll ans = 0;

  for (ll i = 1; i <= N; i++) {
      for (ll j = 1; j <= N; j++) {
          for (ll k = 1; k <= N; k++) {
              ll a = gcd(i, j);
              ll b = gcd(a, k);
              ans += b;
          }
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define REP(n)for(ll i=0;i<n;i++)
#define M make_pair
#define F first
#define S second
typedef long long ll;
using namespace std;
int main(){
    ll n,k,s,t,a[50];cin>>n>>k>>s>>t;
    REP(n)cin>>a[i];
    map<pair<ll,ll>,ll> p[50];
    REP(n){
        for(ll j=k-2;j+1;j--){
            for(const auto&l:p[j]){
                p[j+1][M(l.F.F&a[i],l.F.S|a[i])]+=l.S;
            }
        }
        p[0][M(a[i],a[i])]=1;
    }
    n=0;
    REP(k)n+=p[i][M(s,t)];
    cout<<n;
}

Measured memory_bytes: 154060
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

# 順に見ていく
res = []
cnt = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            if h == H - 1 and w == W - 1:
                continue
            elif a[h][w] % 2 == 1 and w != W - 1:
                cnt += 1
                res.append([h + 1, w + 1, h + 1,  w + 2])
                a[h][w + 1] += 1
            elif a[h][w] % 2 == 1 and w == W - 1:
                cnt += 1
                res.append([h + 1, w + 1, h + 2, w + 1])
                a[h + 1][w] += 1
            else:
                continue
    elif h % 2 == 1:
        for w in range(W-1, -1, -1):
            if h == H - 1 and w == 0:
                continue
            elif a[h][w] % 2 == 1 and w != 0:
                cnt += 1
                res.append([h + 1, w + 1, h + 1,  w])
                a[h][w - 1] += 1
            elif a[h][w] % 2 == 1 and w == 0:
                cnt += 1
                res.append([h + 1, w + 1, h + 2, w + 1])
                a[h + 1][w] += 1
            else:
                continue

print(cnt)
for v in res:
    print(*v)

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){
    
    int N;cin>>N;
    vector<ll> S(N);
    bool plus=false,minus=false;
    for(int i=0;i<N;i++){
        cin>>S[i];
        if(S[i]>0) plus=true;
        else if(S[i]<0) minus=true;
    }
    if(plus&&!minus){
        ll M=S[0];
        int pM=0;
        for(int i=0;i<N;i++){
            if(S[i]>M){
                M=S[i];
                pM=i;
            }
        }
        cout<<N-1<<endl;
        cout<<pM+1<<" "<<2<<endl;
        for(int i=1;i<N-1;i++){
            cout<<i+1<<" "<<i+2<<endl;
        }
    }else if(!plus&&minus){
        ll M=S[0];
        int pM=0;
        for(int i=0;i<N;i++){
            if(S[i]<M){
                M=S[i];
                pM=i;
            }
        }
        cout<<N-1<<endl;
        cout<<pM+1<<" "<<N-1<<endl;
        for(int i=N-1;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }else if(!plus&&!minus) cout<<0<<endl;
    else{
        ll M=abs(S[0]);
        int pM=0;
        for(int i=0;i<N;i++){
            if(abs(S[i])>M){
                M=abs(S[i]);
                pM=i;
            }
        }
        if(S[pM]>0){
            cout<<2*N-1<<endl;
            for(int i=0;i<N;i++){
                if(i!=pM) cout<<pM+1<<" "<<i+1<<endl;
            }
            cout<<pM+1<<" "<<pM+1<<endl;
            cout<<pM+1<<" "<<2<<endl;
            for(int i=1;i<N-1;i++){
                cout<<i+1<<" "<<i+2<<endl;
            }
        }else{
            cout<<2*N-1<<endl;
            for(int i=0;i<N;i++){
                if(i!=pM) cout<<pM+1<<" "<<i+1<<endl;
            }
            cout<<pM+1<<" "<<pM+1<<endl;
            cout<<pM+1<<" "<<N-1<<endl;
            for(int i=N-1;i>1;i--){
                cout<<i<<" "<<i-1<<endl;
            }
        }
    }
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<double> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
    }
    vector<vector<double>> dp(n+1, vector<double>(n+1, 0)); // all, omote
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= n; ++j){
            dp[i+1][j] += dp[i][j] * (1-p[i]);
            if(j != 0) dp[i+1][j] += dp[i][j-1] * p[i];
        }
    }
    double ans = 0;
    for(int i = CEIL(n, 2); i <= n; ++i){
        ans += dp[n][i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#define _USE_MATH_DEFINES
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<string, map<string, int> > Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;

int dp[400][3];
int cost[400];
int value[400][3];

int main(){
	int n, w;
	while(cin >> n >> w){
		string s;
		for(int i = 0; i < n; i++){
			getline(cin, s);
			getline(cin, s);
			cin >> cost[i] >> value[i][0] >> value[i][1] >> value[i][2];
		}
		int res = 0;
		memset(dp, 0, sizeof(dp));
		for(int t = 0; t < 3; t++){
			for(int i = 0; i < n; i++){
				for(int j = 0; j <= w; j++){
					if(j - cost[i] >= 0){
						dp[j][t] = max(dp[j][t], max(dp[j-cost[i]][t] + value[i][t], dp[j-1][t]));
					}
				}
			}
			res = max(res, dp[w][t]);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 932
#include <iostream>
using namespace std;
int main(void){
    int R, A; //正解と回答

    while(true){
        cin >> R >> A;
        if(R == 0 && A == 0) break;

        int r[4], a[4]; //４桁の数字を分解するための箱
        for(int i = 0; i < 4; i++){
            r[3 - i] = R % 10;
            a[3 - i] = A % 10;
            R /= 10;
            A /= 10;
        }

        int c_hit = 0; //ヒットの数を数える
        int c_blow = 0; //ブローの数を数える

        for(int i = 0; i < 4; i++){
            if(r[i] == a[i])
                c_hit++;
            for(int j = 0; j < 4; j++){
                if(i != j) 
                    if(r[i] == a[j]) c_blow++;
            }
        }
        cout << c_hit << " " << c_blow << endl;
    }
}



Measured memory_bytes: 3084