akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
p = list(map(int, input().split()))

sum_k = [0] * N
tmp = 0
for i in range(K):
    tmp += p[i]
sum_k[0] = tmp
max_sum = tmp
candidate = 0
for i in range(len(p)-K):
    sum_k[i+1] = sum_k[i] - p[i] + p[i+K]
    if max_sum < sum_k[i+1]:
        max_sum = sum_k[i+1]
        candidate = i+1


ans = 0
for i in range(candidate, candidate + K):
    ans += (1 + p[i]) / 2
print(ans)

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    map<string, int> mp;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        mp[s]++;
    }
    vector<pair<int, string>> v;
    for (auto &kv: mp) {
        v.push_back({-kv.second, kv.first});
    }
    sort(v.begin(), v.end());
    int best = v[0].first;
    for (auto &par: v) {
        if (par.first != best) break;
        cout << par.second << '\n';
    }
    return 0;
}


Measured memory_bytes: 27632
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  REP(i, M) cin >> B[i];
  
  vector<vector<int>> A(N,vector<int>(M));
  REP(i, N){
    REP(j, M){
      cin >> A.at(i).at(j);
    }
  }
  
  int cnt = 0;
  REP(i,N){
    int sum = 0;
    REP(j,M){
      sum += A.at(i).at(j)*B.at(j);
    }
    if(sum + C > 0){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	cin>>n;
	cout<<a[n-1];
	return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int a = min(B, D) - max(A, C);
  if(a < 0) cout << 0 << endl;
  else cout << a << endl;
}

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

int main()
{
  ll n,w;
    cin>>n>>w;
    ll arr[n+1][2];
    for(ll i=1;i<=n;i++)cin>>arr[i][0]>>arr[i][1];
    vector<ll> dp(w+1,0);
    for(ll i=1;i<=n;i++)
    {
      for(ll j=w-arr[i][0];j>=0;j--)dp[j+arr[i][0]]=max(dp[j+arr[i][0]],dp[j]+arr[i][1]);
    }
    ll ans=0;
   for(ll i=0;i<=w;i++)
  {
      ans=max(ans,dp[i]);
  }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
primes = []
2.upto(123456*2){|x|
    prime = true
    2.upto(Math.sqrt(x)){|y|
        if x % y == 0
            prime = false
            break
        end
    }
    primes << x if prime
}

arr = Array.new(123456 * 2 + 1 , 0)
primes.each{|prime| arr[prime] = 1}
1.upto(arr.length - 1){|i| arr[i] += arr[i - 1]}

while true
    n = gets.to_i
    break if n == 0
    puts arr[n * 2] - arr[n]
end


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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;

int log(int i){
    int p = 0;
    while(i > 0){
        i /= 10;
        p++;
    }
    return p;
}

void solve(){
    int n; scanf("%d", &n);
    int ans = 0;
    for(int i = 1; i <= n; i++){
         if(log(i)%2 == 1) ans++;
    }
    printf("%d\n", ans);
}

int main(){
    int test_cases_number = 1;
//    scanf("%d", &test_cases_number);
    for(int i = 0; i < test_cases_number; i++)
        solve();
}


Measured memory_bytes: 256
import sys,math,collections,itertools
input = sys.stdin.readline

A,B,C,D,E,F = list(map(int,input().split()))

A = A*100
B = B*100

Alim =F//A
Blim = F//B
water = []
for ai in range(Alim+1):
    for bi in range(Blim+1):
        tmp = ai*A+bi*B
        if tmp <=F:
            water.append(tmp)
water = set(water)

suger_limit = math.ceil(F/100)*E
Clim = suger_limit//C
Dlim = suger_limit//D
suger = []
for ci in range(Clim+1):
    for di in range(Dlim+1):
        tmp = ci*C+di*D
        if tmp <=suger_limit:
            suger.append(tmp)
suger = sorted(list(set(suger)),reverse=1)

#judge = 0
candi = [[0,0]]
#limCon=100*E/(100+E)

while water:
    w = water.pop()
    for su in suger:
        
        if w+su > F:
            continue
        else:
            if w*E>=su*100:
                candi.append([w+su,su])
                break
ans = [0,0]
judge = 0
for can in candi:
    ws,s = can
    if ws == 0:
        continue
    else:
        con = s/ws*100
        if con >= judge:
            ans = [ws,s]
            judge=con
  
print(*ans)


Measured memory_bytes: 18544
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var k = h[1];

		var bw = new int[k, k, 2];
		foreach (var x in new int[h[0]].Select(_ => Console.ReadLine().Split()))
		{
			var p = x.Take(2).Select(int.Parse).ToArray();
			bw[p[0] % k, p[1] % k, (p[0] / k + p[1] / k + (x[2] == "B" ? 0 : 1)) % 2]++;
		}

		var ti = new int[k, 2];
		for (int c = 0; c < 2; c++)
			for (int i = 0; i < k; i++)
				for (int j = 0; j < k; j++)
					ti[i, c] += bw[i, j, c];
		var tj = new int[k, 2];
		for (int c = 0; c < 2; c++)
			for (int j = 0; j < k; j++)
				for (int i = 0; i < k; i++)
					tj[j, c] += bw[i, j, c];
		var s = new int[2];
		for (int c = 0; c < 2; c++)
			for (int i = 0; i < k; i++)
				s[c] += ti[i, c];

		var M = 0;
		for (int j = 0; j < k; j++)
		{
			for (int i = 0; i < k; i++)
			{
				M = Math.Max(M, s[0]);
				M = Math.Max(M, s[1]);
				s[0] += ti[i, 1] - ti[i, 0];
				s[1] += ti[i, 0] - ti[i, 1];
			}

			for (int i = 0; i < k; i++)
			{
				ti[i, 0] += bw[i, j, 1] - bw[i, j, 0];
				ti[i, 1] += bw[i, j, 0] - bw[i, j, 1];
			}
			Array.Reverse(s);
			s[0] += tj[j, 1] - tj[j, 0];
			s[1] += tj[j, 0] - tj[j, 1];
		}
		Console.WriteLine(M);
	}
}


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

using namespace std;
using ld = long double;
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

constexpr int INF = 1e9 + 9;

void run() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0)  {
        cout << "Zero\n";
    } else if (a > 0) {
        cout << "Positive\n";
    } else {
        int cnt = min(-1LL, b) - a + 1;
        if (cnt % 2) {
            cout << "Negative\n";
        } else {
            cout << "Positive\n";
        }
    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int t = 1;
   // cin >> t;
    while (t--)
        run();
    return 0;
}

Measured memory_bytes: 256
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [A, B] = r.nn()

    return Math.max(A, B) * 2 - Number(A !== B)
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


Measured memory_bytes: 7372
<?php
class MyTest {

    private function getInput() {
        while (!empty($input = fgets(STDIN))) {
            $ret[] = trim($input);    
        }
        return $ret;
    }

    private function main($input) {
        $line1 = explode(' ', $input[0]);
        $n = $line1[0];
        $k = $line1[1];
        $str = $input[1];
        $ret = '';
        for($i = 0; $i < $n;  $i++){
            if ($i == $k - 1) {
                $txt = strtolower($str[$i]);
            } else {
                $txt = $str[$i];
            }
            $ret .= $txt;
        }
        echo $ret;
    }

    public function run() {
        $input = self::getInput();
        self::main($input);
    }
    
}

MyTest::run();

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
/*
提出 #9750607を参考にしました
*/

struct P {
  long long X;
  long long H;
};

constexpr unsigned long max_monsters_hp{1000000000};

int main(int argc, char** argv) {
  long long N, D, A;
  std::cin >> N >> D >> A;
  std::vector<P> Monsters(N);
  for (auto& e : Monsters) std::cin >> e.X >> e.H;
  std::sort(Monsters.begin(), Monsters.end(), [](const auto& l, const auto& r){return (l.X<r.X);});

  long long ans {};
  std::vector<long long> c(N+1);
  for (auto i = 0;i < N;++i) {
    c[i]   += Monsters[i].H;
    c[i+1] -= Monsters[i].H;
  }

  for (auto i = 0;i < N;++i) {
    if (i) c[i] += c[i-1];
    if (c[i] > 0) {
      long long cnt = (c[i] + A - 1) / A;
      ans += cnt;
      P tmp {Monsters[i].X + 2*D + 1, 0};
      int index = std::lower_bound(Monsters.begin(), Monsters.end(), tmp, [](auto& l, auto& r){return l.X<r.X;}) - Monsters.begin();
      c[i] -= cnt*A;
      c[index] += cnt*A;
    }
  }
  std::cout << ans << '\n';
}


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

int main() {
	int n;
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(x%2!=0&&i%2!=0) ans++;
		
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
N,M = map(int,input().split())
H = list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(M)]
A = [set() for __ in range(N)]
#print(A)
for d in a:
    A[d[0]-1].add(d[1]-1)
    A[d[1]-1].add(d[0]-1)
#print(A)
count = 0
for i,h in enumerate(H):
    if len(A[i]) == 0:
        count += 1
        continue
    is_high = 1
    for a in A[i]:
        if H[a] >= h:
            is_high = 0
            break
    count += is_high
print(count)
    

Measured memory_bytes: 121992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


	string s, t;
	cin>>s>>t;
	ll si = s.size();
	if(si+1 == t.size() && t.substr(0, si) == s) cout<<"Yes";
	else cout<<"No";
	

	return 0;
}


Measured memory_bytes: 3644
num,min,max = gets.chomp.split(" ").map(&:to_i)
    result = 0
    for n in 1...(num + 1) do
        sum = n.to_s.chars.map(&:to_i).inject(:+)
        if (sum >= min && sum <= max) then result += n end
    end
    print(result)

Measured memory_bytes: 1788
import java.util.*;

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

        String[] F = new String[H];
        for (int h = 0; h < H; h++) {
            F[h] = sc.next();
        }

        Graph g = new Graph(H, W, F);
        int res = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (F[h].charAt(w) != '.') {
                    continue;
                }
                
                 res = Math.max(res, g.wfs(h, w));
            }
        }
        
        System.out.println(res);
    }
}

class Graph {
    private int H;
    private int W;
    private String[] F;
    
    public Graph(int H, int W, String[] F) {
        this.H = H;
        this.W = W;
        this.F = F;
    }
    
    class Node {
        public int h;
        public int w;
        public int c;

        public Node(int h, int w, int c) {
            this.h = h;
            this.w = w;
            this.c = c;
        }
    }
    
    public int wfs(int h0, int w0) {
        int[][] cost = new int[H][W];
        for (int h = 0; h < H; h++) {
            Arrays.fill(cost[h], -1);
        }
        
        Queue<Node> q = new ArrayDeque<>();
        q.add(new Node(h0, w0, 0));
        while (!q.isEmpty()) {
            Node n = q.poll();
            int h = n.h;
            int w = n.w;

            if (cost[h][w] != -1) {
                continue;
            }
            
            cost[h][w] = n.c;
            
            if (h != 0 && F[h - 1].charAt(w) == '.' && cost[h - 1][w] == -1) {
                q.add(new Node(h - 1, w, n.c + 1));
            }

            if (h != H - 1 && F[h + 1].charAt(w) == '.' && cost[h + 1][w] == -1) {
                q.add(new Node(h + 1, w, n.c + 1));
            }            

            if (w != 0 && F[h].charAt(w - 1) == '.' && cost[h][w - 1] == -1) {
                q.add(new Node(h, w - 1, n.c + 1));
            }           
            
            if (w != W - 1 && F[h].charAt(w + 1) == '.' && cost[h][w + 1] == -1) {
                q.add(new Node(h, w + 1, n.c + 1));
            } 
        }
        
        int res = 0;
        for (int h = 0; h < H; h++) {
            res = Math.max(res, Arrays.stream(cost[h]).max().getAsInt());
        }
        
        return res;
    }
}




Measured memory_bytes: 35408
n = gets.to_i
a = gets.chomp.split("")
b = gets.chomp.split("")
c = gets.chomp.split("")
ans = 0
for i in 0..n-1
  if a[i] != b[i] && b[i] != c[i] && c[i] != a[i]
    ans += 2
  elsif a[i] == b[i] && b[i] == c[i] && c[i] == a[i]
  else
    ans += 1
  end
end
puts ans


Measured memory_bytes: 1788
#include <stdio.h>

int main(void) {
  int n, arr[4][3][10]={0};
  scanf("%d", &n);

  for (int i=0; i<n; i++) {
    int b, f, r, v;
    scanf("%d %d %d %d", &b, &f, &r, &v);

    arr[b-1][f-1][r-1]+=v;
    
    if (arr[b-1][f-1][r-1]<0) {
      arr[b-1][f-1][r-1]=0;
    } else if (arr[b-1][f-1][r-1]>9) {
      arr[b-1][f-1][r-1]=9;
    }
  }

  for (int i=0; i<4; i++) {
    for (int j=0; j<3; j++) {
      for (int k=0; k<10; k++) {
        if (k<9) {
          printf(" %d", arr[i][j][k]);
        } else {
          printf(" %d\n", arr[i][j][k]);
        }
      }
    }

    if (i<3) {
      printf("####################\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
unordered_map<int,list<int>> adjlist;
long long int p=1e9+7;
int n;
long long dp[100001][2];
void dfs_helper(int i,bool *visited)
{
      visited[i]=true;
      long long int w=1,b=1;
      for(auto j:adjlist[i])
      {
           if(!visited[j])
           {
               dfs_helper(j,visited);
               w=((w)*((dp[j][0]+dp[j][1])))%p;
               b=((b)*(dp[j][0]))%p;

           }
      }
      dp[i][0]=w;
      dp[i][1]=b;

}
void dfs(int n)
{
    bool visited[n+1];
    for(int i=1;i<=n;i++)
      visited[i]=false;
      dfs_helper(1,visited);
     

}

int main()
{

 
  cin>>n;
  for(int i=0;i<n-1;i++)
  {
      int x,y;
      cin>>x>>y;
      adjlist[x].push_back(y);
      adjlist[y].push_back(x);
  }
  for(int i=0;i<=n;i++)
  {
      dp[i][0]=dp[i][1]=1;
  }
  dfs(n);
  long long int ans=(dp[1][0]%p+dp[1][1]%p)%p;
  cout<<ans<<endl;
  

}

Measured memory_bytes: 20772
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

S = input()
SwoX = S.replace('x', '')

if SwoX != SwoX[::-1]:
    print(-1)
else:
    i = 0
    j = len(S)-1
    ans = 0
    while(i < j):
        if (S[i] == S[j] == 'x') or (S[i] != 'x' and S[j] != 'x'):
            i += 1
            j -= 1
        else:
            ans += 1 
            if S[i] == 'x':
                i += 1
            else:
                j -= 1
    print(ans)
        
            
            
        


Measured memory_bytes: 7120
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		
		Set<Integer> color = new HashSet<Integer>();

		color.add(scanner.nextInt());
		color.add(scanner.nextInt());
		color.add(scanner.nextInt());
		System.out.println(color.size());
		scanner.close();
	}

}


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

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}

void sout(char *s) { while (*s) pc(*s++); }

typedef struct { int parent; int depth; int k; int *c; } TREE;
TREE tbl[100002];

void calc_depth(int node, int d)
{
	int i;
	tbl[node].depth = d;
	for (i = 0; i < tbl[node].k; i++) calc_depth(tbl[node].c[i], d+1);
}

int main()
{
	int n, i, j, k, id;
	int root;

	n = in();
	for (i = 0; i < n; i++) {
		id = in(), tbl[id].k = k = in();
		tbl[id].c = malloc(k << 2);
		for (j = 0; j < k; j++) {
			int _c = in();
			tbl[_c].parent = id+1;
			tbl[id].c[j] = _c;
		}
	}
	for (root = 0; root < n; root++) {
		if (tbl[root].parent == 0) break;
	}
	calc_depth(root, 0);

	for (i = 0; i < n; i++) {
		sout("node "), out(i);
		sout(": parent = ");
		if (i == root) sout("-1");
		else out(tbl[i].parent - 1);
		sout(", depth = "), out(tbl[i].depth);
		sout(", ");
		if (i == root)          sout("root");
		else if (tbl[i].k == 0) sout("leaf");
		else                    sout("internal node");
		sout(", [");
		if (tbl[i].k > 0) {
			out(tbl[i].c[0]);
			for (j = 1; j < tbl[i].k; j++) {
				pc(','), pc(' '), out(tbl[i].c[j]);
			}
		}
		sout("]\n");
	}
	return 0;
}


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

int main() {
	int n;
	vector<int> r;
	cin >> n;
	for (int i; i<n; i++)
	{
		double xa,ya,ra,xb,yb,rb;
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		if (pow(xa-xb,2)+pow(ya-yb,2) > pow(ra+rb,2))
		{
			r.push_back(0);
		} else if (pow(xa-xb,2)+pow(ya-yb,2) < pow(ra-rb,2)) {
			(ra > rb) ? r.push_back(2) : r.push_back(-2);
		} else {
			r.push_back(1);
		}
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll N;
ll a[100000];

int main()
{
	cin>>N;
	rep(i,N) cin>>a[i];
	sort(a,a+N);
	ll cnt=0;
	rep1(i,N-1){
		if(a[i]==a[i-1]) cnt++;
	}
	cout<<N- ((cnt+1)/2)*2 <<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    int h,w;
    int x[8] = {-1,-1,-1,0,0,1,1,1};
    int y[8] = {-1,0,1,-1,1,-1,0,1};
    cin >> h >> w;
    char f[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> f[i][j];
        }
    }
    string ans[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int cnt = 0;
            if(f[i][j] == '.'){
                for(int s = 0; s < 8; s++){
                    if(i + x[s] >= 0 && i + x[s] <= h-1 && j + y[s] >= 0 && j + y[s] <= w-1 && f[i+x[s]][j+y[s]] == '#'){
                        cnt++;
                        
                    }
                }
                ans[i][j] = to_string(cnt);
            }else{
                ans[i][j] = '#';
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m; cin>>n>>m;
    vector<string> v(n);
    for (int i=0; i<n; i++){
        cin>>v[i];
    }
    int dp[n][m];
    for (int i=0; i<n; i++)for (int j=0; j<m; j++)dp[i][j] = 10000;
    int cnt = 0;
    if (v[0][0] == '#')dp[0][0] = 1;
    else dp[0][0] = 0;
    for (int i=1; i<m; i++){
        if (v[0][i] == '#' && v[0][i-1]=='.')dp[0][i] = dp[0][i-1] + 1;
        else dp[0][i] = dp[0][i-1];
    }
    for (int i=1; i<n; i++){
        if (v[i][0] == '#' && v[i-1][0]=='.')dp[i][0] = dp[i-1][0] + 1;
        else dp[i][0] = dp[i-1][0];
    }
    for (int i=1; i<n; i++){
        for (int j=1; j<m; j++){
            if (v[i][j] == '#' && v[i-1][j]=='.')dp[i][j] = min(dp[i][j], dp[i-1][j] + 1);
            else dp[i][j] = min(dp[i-1][j], dp[i][j]);
            if (v[i][j] == '#' && v[i][j-1] == '.')dp[i][j] = min(dp[i][j], dp[i][j-1] + 1);
            else dp[i][j] = min(dp[i][j], dp[i][j-1]);
        }
    }
    // for (int i=0; i<n; i++){
    //     for (int j=0; j<m; j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[n-1][m-1]<<endl;

}

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

int main() {
  ll n,m,a,b;
  cin>>n>>m;
  vector<ll> good(n,2);
  vector<ll> h(n);
  rep(i,n){
    cin>>h[i];
  }
  rep(i,m){
    cin >>a>>b;
    a--,b--;
    if(h[a]<h[b]){
      good[a]=0;
      if(good[b]==2){
        good[b]=1;
      }
    }else if(h[a]>h[b]){
      if(good[a]==2){
        good[a]=1;
      }
      good[b]=0;
    }else{
      good[a]=0;
      good[b]=0;
    }
  }
  ll count =0;
  for(auto au:good){
    if(au>0){
      count++;
    }
  }
  cout <<count<<endl;
}


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

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

int N, K;
int A[200000], B[200000];
multiset<int> M;
int main() {
	cin >> N;
	REP(i, 0, N) {
		cin >> A[i];
		M.insert(A[i]);
	}
	cin >> K;
	REP(i, 0, K) {
		cin >> B[i];
	}
	bool ok = true;
	REP(i, 0, K) {
		auto it = M.find(B[i]);
		if (it == M.end()) {
			ok = false;
			break;
		} else {
			M.erase(it);
		}
	}
	cout << YESNO(ok) << endl;
	return 0;
}

Measured memory_bytes: 11264
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			double t = sc.nextInt();
			double x = sc.nextInt();
			
			double y = t/x;
 
			System.out.println(y);
 
		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 22868
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
    private static final int MOD = 1000000007;

    private long pow(long a, long n) {
        long ret = 1;
        long base = a;
        while (n > 0) {
            if ((n & 1) > 0) {
                ret = (ret * base) % MOD;
            }
            base = (base * base) % MOD;
            n >>= 1;
        }
        return ret;
    }

    private void add(Map<String, int[]> cnt, String key, int i) {
        int[] v = cnt.computeIfAbsent(key, k -> new int[]{0, 0});
        ++v[i];
    }

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

    private void solve() {
        int n = sc.nextInt();
        long adt = 0;
        Map<String, int[]> cnt = new HashMap<>();
        for (int i = 0; i < n; i++) {
            long a = sc.nextLong();
            long b = sc.nextLong();
            if (a == 0 && b == 0) {
                ++adt;
                continue;
            }

            if (a == 0L) {
                add(cnt,"0,0", 0);
            } else if (b == 0L) {
                add(cnt, "0,0", 1);
            } else {
                if ((a > 0 && b > 0) || (a < 0 && b < 0)) {
                    a = Math.abs(a);
                    b = Math.abs(b);
                    long g = gcd(a, b);
                    String key = (a/g) + "," + (b/g);
                    add(cnt,key, 0);
                } else {
                    a = Math.abs(a);
                    b = Math.abs(b);
                    long g = gcd(a, b);
                    String key = (b/g) + "," + (a/g);
                    add(cnt, key, 1);
                }
            }
        }

        long ans = 1;
        for (int[] v : cnt.values()) {
            ans = (ans * ((pow(2, v[0]) + pow(2, v[1]) - 1 + MOD) % MOD)) % MOD;
        }

        ans = (ans + adt - 1 + MOD) % MOD;
        out.println(ans);
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 85420
#include<stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>

using namespace std;

#define BUF_SIZE 1024

struct Node{
	int data;
	Node* prev;
	Node* next;
};

class ConnectedList{
public:
	ConnectedList(){
		motherNode = new Node();
		motherNode->data = -1;
		motherNode->prev = motherNode;	
		motherNode->next = motherNode;
	};
	~ConnectedList(){
		Node* tmpNode = motherNode->next;
		Node* nextNode;
		while(tmpNode != motherNode){
			nextNode = tmpNode->next;
			delete tmpNode;
			tmpNode = nextNode;
		}
		delete motherNode;
	};
	void insertNode(int x){
		Node* tmpNode = motherNode->next;
		motherNode->next = new Node();
		motherNode->next->data = x;
		motherNode->next->next = tmpNode;
		motherNode->next->prev = motherNode;
		tmpNode->prev = motherNode->next;
	};
	void deleteNode(int x){
		Node* tmpNode = motherNode->next;
		while(tmpNode != motherNode && tmpNode->data != x){
			tmpNode = tmpNode->next;
		}
		if(tmpNode != motherNode){	
			tmpNode->prev->next = tmpNode->next;
			tmpNode->next->prev = tmpNode->prev;
			delete tmpNode;
		}
	};

	void deleteFirst(){
		Node* tmpNode = motherNode->next;
		motherNode->next = motherNode->next->next;
		motherNode->next->prev = motherNode;
		delete tmpNode;	
	};

	void deleteLast(){
		Node* tmpNode = motherNode->prev;
		motherNode->prev = motherNode->prev->prev;
		motherNode->prev->next = motherNode;
		delete tmpNode; 
	};

	void showList(){
		Node* tmpNode = motherNode->next;
		printf("%d",tmpNode->data);
		tmpNode = tmpNode->next;
		while(tmpNode != motherNode){
			printf(" %d",tmpNode->data);
			tmpNode = tmpNode->next;
		}
		printf("\n");
	}

private:
	Node* motherNode;
};


int main(){

	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));

	ConnectedList list;

	for(int i = 0; i < n; i++){

		fgets(buf,BUF_SIZE,stdin);

		if(buf[6] == 'F'){
			list.deleteFirst();
		}else if(buf[6] == 'L'){
			list.deleteLast();
		}else{
			int S = 0;
			
			if(buf[0] == 'i'){	//insert x

				for(int i = 0; buf[i] != '\0';i++){
					if(buf[i] >= '0' && buf[i] <= '9'){
						S = 10*S + (buf[i] - '0');
					}
				}
				list.insertNode(S);
			}else{	
				for(int i = 0;buf[i] != '\0';i++){
					if(buf[i] >= '0' && buf[i] <= '9'){
						S = 10*S + (buf[i] - '0');
					}
				}
				list.deleteNode(S);
			}

		}

	}

	list.showList();

}


Measured memory_bytes: 34468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for (int i = 0; i <= n / r; i++) {
		int t = n - (i * r);
		for (int j = 0; j <= t / g; j++) {
			int u = t - (j * g);
			if (u % b == 0)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
constexpr int MOD = 1000000007;
constexpr ll INF = 50000000000000000;
typedef std::pair<int,int> P;
constexpr ll SIZE= 100010;

ll N,M;
ll ans=0;
string S,T;
bool F=true;
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main() {
    std::ios_base::sync_with_stdio(false);
    cin>>N>>M>>S>>T;
    ll G=gcd(N,M);
    ll L=N/G*M;
    ll Q=(L/M)/gcd(L/M,L/N)*(L/N);
    ll loop=min(N,M);
    ans=L;
    DEB(loop)DEB(Q)END
    for(int i=0,j=0;j<T.size()&&i<S.size();i+=Q/(L/N),j+=Q/(L/M)){
        DEB(i)DEB(j)DEB(S[i])DEB(T[j])END
        if(S[i]!=T[j]){
            F=false;
            break;
        }
    }
    cout<<(F?ans:-1)<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int n,k,a[105];

int main(){
	cin>>n>>k;
	for (int i=1;i<=n;++i) cin>>a[i];
	dp[0]=-1;
	for (int i=1;i<=k;++i){
		dp[i]=-1;
		for (int j=1;j<=n;++j){
			if (i-a[j]<0) continue;
			if (dp[i-a[j]]==-1){
				dp[i]=1;break;
			}
		}
	}
	cout<< (dp[k]==1? "First":"Second") << endl;
	return 0; 
}


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

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int i= 0; i < M; i++) {
    cin >> t.at(i);
  }
  
  map<string, int> counts;
  map<string, int> countt;
  for (int i = 0; i < N; i++) {
    if (counts.count(s.at(i))) counts[s.at(i)] = counts.at(s.at(i)) + 1;
    else counts[s.at(i)] = 1;
  }
  for (int i = 0; i < M; i++) {
    if (countt.count(t.at(i))) countt[t.at(i)] = countt.at(t.at(i)) + 1;
    else countt[t.at(i)] = 1;
  }
  int max = 0;
  for (auto p : counts) {
    int tmp;
    if (countt.count(p.first)) tmp = p.second - countt.at(p.first);
    else tmp = p.second;
    if (tmp > max) max = tmp;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define max(a,b)((a)>(b)?(a):(b))
#define int long long
const int N=16;
int n,g[N][N],a[1<<N],f[1<<N];
signed main(){
	int u,v;
	scanf("%lld",&n);
	for(u=0;u<n;u++)for(v=0;v<n;v++)scanf("%lld",&g[u][v]);
	for(int I=0;I<(1<<n);I++){
	  for(u=0;u<n;u++)if(I&1<<u)
	  for(v=u;v<n;v++)if(I&1<<v)
		a[I]+=g[u][v];
	}
	for(int I=0;I<(1<<n);I++){
	  for(int II=I;II;II=II-1&I)
		f[I]=max(f[I],f[I-II]+a[II]);
	}printf("%lld",f[(1<<n)-1]);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];
  sort(ALL(a));


  vll same(1000001);
  REP(i,n-1){
    if(a[i]==a[i+1])
      same[a[i]]=1;
  }

  vll is(1000001);
  ll ans=0;
  REP(i,n){
    if(is[a[i]]==1)
      continue;

    for(ll j=1; j*a[i]<=1000000; j++){
      is[j*a[i]]=1;
    }
    if(same[a[i]]==1)
      continue;

    ans++;
  }
  cout<<ans<<endl;

}



Measured memory_bytes: 20320
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
#define EPS (1e-7)
using namespace std;
#define ll long long


int main() {

	string S, simplize = "";
	int N;
	cin >> N;
	vector<ll> T(N);
	int ans = 0;
		
	for (auto i = 0; i < N; i++)
	{
		cin >> T[i];
	}

	ll temp=T[0];
	for (auto i = 1; i < N; i++)
	{
		temp = boost::math::lcm(temp, T[i]);
	}

	
	cout << temp << endl;
	return 0;
}

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

# 左から何個、右から何個を全探索
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l + r > n:
            continue
        suteru = k - l - r
        get = []
        for i in range(l):
            get.append(v[i])
        for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
        get.sort()
        minus = 0
        while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
        ans = max(ans, sum(get[minus:]))
print(ans)


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

int main() {
    int h = 0, m = 0, s;
    cin >> s;
    while (s >= 3600) {
    	h = h + 1;
    	s = s - 3600;
    }
    while (s >= 60) {
    	m = m + 1;
    	s = s - 60;
    }
    cout << h << ':' << m << ':' << s << endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n; cin >> n;
    for(int i=0;i<=(n/7);i++){
        n -= i*7;
        if(n%4==0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

inline int read(){
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
} 

long long n, sum=100, total=0;

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    //freopen(".in","r",stdin);
	//freopen(".out","w",stdout); 
	
	cin >> n;
	
	do{
		sum*=1.01;
		total++;
		if(sum>=n){
			cout << total;
			return 0;
		}
	}while(1);
	 
	return 0;
}

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

int main(){
  int N; cin >> N;
  vector<ll> L(N);
  for(int i=0;i<N;i++){
    ll Li; cin>>Li; L[i]=Li;
  }
  sort(L.begin(),L.end());
  int a=0;
  for(int i=0;i<N-2;i++)
    for(int j=i+1;j<N-1;j++)
      for(int k=j+1;k<N;k++){
        if(L[i]==L[j]||L[i]==L[k]||L[j]==L[k]) continue;
        if(L[k]<L[i]+L[j]) a++;
      }
  cout << a << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,sum;
  cin>>a>>b;
  sum=0;
  for(int i=0;i<2;i++){
    if(a>b){
      sum+=a;
      a--;
    }
    else{
      sum+= b;
      b--;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;


int main(){
  ll n,m;
  cin>>n>>m;

  vector<ll>h(n);
  vector<bool> c(n,1);
  ll ans=0;
  //vector<ll>a(m);
  //vector<ll>b(m);
  
  rep(i,n){
    cin>>h[i];
  }

  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    if(h[a]>h[b]){
      c[b]=0;
    }
    else if(h[a]<h[b]){
      c[a]=0;
    }
    else{
      c[a]=0;
      c[b]=0;
    }
  }

  rep(i,n){
    if(c[i]==1) ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 4044
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> line(200020, 0);
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		++line[a + b];
	}
	for (int i = 0; i < line.size()-1; ++i) {
		line[i + 1] += line[i] / 2;
		line[i] %= 2;
		if (line[i]) {
			cout << i << " " << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3416
#include<iostream>
#include<list>
#include<stack>
using namespace std;

int main() {
  int N, Q; cin >> N >> Q;
  list<int> E[N];
  int a, b, p, x;
  long counter[N]; for (int i = 0; i < N; i++) counter[i] = 0;
  for (int i = 0; i < N-1; i++) {
    cin >> a >> b; a--; b--;
    E[a].push_back(b); E[b].push_back(a);
  }
  for (int q = 0; q < Q; q++) {
    cin >> p >> x; p--;
    counter[p] += x;
  }
  bool visited[N]; for (int i = 0; i < N; i++) visited[i] = false;
  visited[0] = true;
  stack<int> S; S.push(0);
  while (!S.empty()) {
    int u = S.top(); S.pop();
    for (auto it = E[u].begin(); it != E[u].end(); it++) {
      if (!visited[*it]) {
        visited[*it] = true;
        counter[*it] += counter[u];
        S.push(*it);
      }
    }
  }
  for (int i = 0; i < N; i++) cout << counter[i] << endl;
}

Measured memory_bytes: 23288
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define deb(x) cerr<<#x<<x<<"\n"
using namespace std;
long mod = 1000000007;

//vector<long> pre;


long modPow(long a, long x, long p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long modInverse(long a, long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
long modBinomial(long n, long k, long p) {
// calculates C(n,k) mod p (assuming p is prime).

    long numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    long denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}

int main(){
    int n,k;
    cin>>n>>k;
    //pre.resize(n+1);
    //pre[0]=1;
	/*for(int i=1;i;i<=n;i++){
		pre[i]  = ((pre[i-1]%mod) * (i%mod))%mod;
	}*/
	for(int i=1;i<=k;i++){
		long ans = modBinomial(n-k+1,i,mod);
		deb(ans);
		ans = (((ans+mod)%mod) * ((modBinomial(k-1,i-1,mod)+mod)%mod))%mod;
		cout<<ans<<"\n";
	}

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define MOD (1000000007ll)
typedef pair<ll, int> PLI;

int main(void){
	int n,a;
	cin >> n >> a;
	cout << (((n%500)>a)?"No":"Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int T;
  cin >> T;
  while(T--) {
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    int dp[n][n];
    memset(dp,0,sizeof(dp));
    for(int i=0; i<n; i++) dp[i][(i+1)%n]=abs(a[i]-a[(i+1)%n]);
    int ans=0;
    for(int i=2; i<n; i++) {
      for(int j=0; j<n; j++) {
    for(int k=j; k<i+j+1; k++) {
      int x=(i+j)%n;
      if(k==j) dp[j][x]=max(dp[j][x],dp[j][(i+j-1)%n]+abs(a[j]-a[x]));
      else dp[j][x]=max(dp[j][x],dp[j][k%n]+dp[k%n][x]);
      ans=max(ans,dp[j][x]);
    }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1204
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val X = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    val sorted = X.sorted()

    val a = Math.floor((1.toDouble() + N.toDouble()) / 2.0).toInt() - 1
    val b = Math.ceil((1.toDouble() + N.toDouble()) / 2.0).toInt() - 1
    for (i in 0 until N) {
        if (X[i] <= sorted[a]) {
            println(sorted[b])
        } else {
            println(sorted[a])
        }
    }
}

Measured memory_bytes: 98568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
   int n;
   cin >> n;
   vector<int> v(n);
   rep(i,n) cin >> v[i];
   sort(v.begin(),v.end());
   int ans1 = v[n-1],ans2;
   int find = v[n-1]/2;
   int diff = 1e9;
   for (int i = 0; i < n-1;i++){
       if (abs(find-v[i]) <= diff){
           diff = find-v[i];
           ans2 = v[i];
       }
   }
   cout << ans1 << " " << ans2 << endl;
   return 0;

}

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

long long f(ll a, ll b, ll x) {
	return a * x / b - a * (x / b);
}

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	ll x = min(n, b - 1);

	cout << f(a, b, x);

	return 0;
}
	

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  rep(i, n) {
    string s; cin >> s;
    unordered_set<string> se;
    reps(j, s.size()) {
      string x = s.substr(0, j);
      string y = s.substr(j);
      string rx = x, ry = y;
      reverse(all(rx)), reverse(all(ry));
      se.insert(x + y);
      se.insert(y + x);
      se.insert(x + ry);
      se.insert(y + rx);
      se.insert(rx + y);
      se.insert(ry + x);
      se.insert(rx + ry);
      se.insert(ry + rx);
    }
    cout << se.size() << '\n';
  }
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1e9
const int MOD = 998244353;

// bit全探索
int main(void){
    string org;
    char op[3];
    int res = 0;
    cin >> org;

    FOR(b,0,(1 << 3)){
        res = org[0] - '0';
        REP(i,3){
            if((b >> i) & 1){
                res += (org[i+1] - '0');
                op[i] = '+';
            }else{
                res -= (org[i+1] - '0');
                op[i] = '-';
            }
        }
        if(res == 7) break;
    }
    cout << org[0] << op[0] << org[1] << op[1] << org[2] << op[2] << org[3] << "=7" << endl;
    return 0;
}

Measured memory_bytes: 3624