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

#define pb push_back
#define mp make_pair
#define ll long long int
#define all(x) x.begin(), x.end()

const int mod = (int)(1e9) + 7;

long long int ans = 1;
unordered_set<int> seen;
unordered_map<int, int> cc;
int n, k;
void dfs(int start, vector<vector<int>> & graph, int parent) {

    // seen before //
    if(seen.find(start) != seen.end()) return;
    seen.insert(start);

    cc[start] = 0; // first time for this node

    // find no. of culprits
    if(parent == -1) {
        ans = k;
        // cout << "mul by:" << k << "\n";
    } else {
        int reduc = 1; // since there's a valid parent
        reduc += cc[parent]; // excluding self
        ans *= (k-reduc);
        // cout << "mul by:" << k-reduc << "\n";
    }

    ans %= mod;

    // find if leaf elig now
    if(graph[start].size() == 1 && seen.find(graph[start][0]) != seen.end()) {
        return;
    }
    
    int res = 0;

    for(auto child: graph[start]) {
        if(seen.find(child) != seen.end()) cc[start]++;
    }

    for(auto child: graph[start]) {
        if(seen.find(child) == seen.end()) {
            dfs(child, graph, start);
            cc[start]++;
        }
    }

    return;
}

void solve() {
    cin >> n >> k;
    vector<vector<int>> graph(n);
    for (int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    dfs(0, graph, -1);
    cout << ans%mod << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);

    solve();
    return 0;
}


Measured memory_bytes: 18632
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> a(2, vector<int>(n));
	rep(i, 0, 2) {
		rep(j, 0, n)cin >> a[i][j];
	}
	vector<vector<int>> cell_max(2, vector<int>(n, 0));
	cell_max[0][0] = a[0][0];
	cell_max[1][0] = cell_max[0][0] + a[1][0];
	rep(i, 0, 2) {
		rep(j, 1, n) {	
			if(i==0) cell_max[i][j] = a[i][j] + cell_max[i][j - 1];
			else
				cell_max[i][j] = a[i][j] + max(cell_max[i - 1][j], cell_max[i][j - 1]);
		}
	}
	cout << cell_max[1][n - 1] << endl;
}

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

using namespace std;
#define ll long long int
const int mod = 1e9+7;
int main()
{
    ll n,k;
    cin >> n >> k;

    ll ans = 0;
    for(ll i=k;i<=n+1;i++){
        ans += i*(n+1-i)+1;
        ans %= mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  sort(ALL(vec),greater<int>());
  int A = 0, B = 0;
  for (int i = 0; i < N; i++)
  {
    if(i%2 == 0)
    A += vec[i];
    else
    B += vec[i];
  }
  cout<<A-B<<endl;
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
'use strict';
(function(stdin) {
   for(var i =1;i<=9;i++){
    for (var j=1;j<=9;j++){
        console.log([i,'x',j,'=',i*j].join(''));
    }
   }

  
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7636
//
//  main.cpp
//  A
//
//  Created by Sultan.
//  Copyright © 2017 Sultan. All rights reserved.
//
//  CF Handle : 2017_Scayre_TBIL_777
//
//  ARSEN TOKSYN ZVER UUUU!!!!                BIZ SAGAN SENEMIZ!!!                   TaldykBIL,ALGA!!!
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>

#define ll long long
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf 1e9 + 7;

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp make_pair

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb(x) push_back(x)
#define ppb(x) pop_back(x)

#define endl "\n"

#define in(x) insert(x)

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)

#define all(x) x.begin(),x.end()

using namespace std;

string s,s1;

int main() {
    
    cin >> s;
    
    cin >> s1;
    
    if(s[0]==s1[2] && s[1]==s1[1] && s[2]==s1[0]){
        cout << "YES" << endl;
    }
    
    else cout << "NO" << endl;
    
    return 0;
}


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

using namespace std;

using ll = unsigned long long int;
using pii = pair<int, int>;

ll arr[100010] = {};


int main() {

	ll a, b, c, d, n;
	cin >> a >> b >> c >> d >> n;

	b = min(a * 2, b);
	c = min(b * 2, c);
	d = min(c * 2, d);

	ll e = n / 2,ans = 0;

	ans += e * d;
	if (n % 2) {
		ans += c;
	}

	cout << ans << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  REP(i, n-1) ans *= k-1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	rr := r.nextInt()

	fmt.Fprintln(stdout, rr*rr)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5; // check bounds
const int M = 1e9 + 7;
const char nl = '\n';

template< typename T > inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template< typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> void ckmin(T& a, T b) {a = min(a, b);}
template <class T> void ckmax(T& a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



void solve() {
	int n; cin >> n;
	int ans = 0;
	set<int> s;
	vector<int> v(n);
	vector<bool> w(n, true);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; ++i) {
		if (i > 0 && v[i] == v[i-1]) {
			w[i-1] = w[i] = false;
		}
		for (int j = 1; j * j <= v[i] + 10; ++j) {
			if (v[i] % j == 0 && s.find(j) != s.end()) {
				w[i] = false;
				break;
			}
			if (v[i] % j == 0 && s.find(v[i] / j) != s.end()) {
				w[i] = false;
				break;
			}
		}
		s.insert(v[i]);
	}
	for (int i = 0; i < n; ++i)
		if (w[i]) ++ans;
	cout << ans << nl;
}

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

	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


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

int main() {

     int K,A,B;
     cin >> K >> A >> B;
     
     if( (B-A)/K >= 1 )
       cout << "OK" << endl;
  
     else if (K == 1)
       cout << "OK" << endl;
  
     else if (A%K == 0 || B%K == 0)
       cout << "OK" << endl;
  
     else if (A%K > B%K)
       cout << "OK" << endl;
  
     else
       cout << "NG" << endl;
}


Measured memory_bytes: 3592
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
fact = [1]
for i in range(0,N):
  fact.append(fact[i] * (i+2))
p = 0
q = 0

def number(a):
  res = 0
  global fact
  l = len(a)
  for i in range(l-2):
    res += (a[i] - 1) * fact[l-2-i]
    for j in range(i+1, l-2):
      if a[j] > a[i]:
        a[j] -= 1
  if a[l-1] < a[l-2]:
    res += 2
  else:
    res += 1
  return res
    
p, q = number(P), number(Q)
print(abs(q-p))

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int a, b, c;
	while(cin >> a >> b >> c){
		int sum = a + b;
		int ret = 0;
		for(int i=1; i<= 10; i++) if(sum+i <= 20 && c != i && a != i && b != i) ret++;
		if(0.50 <= ret/7.) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

using namespace std;

using ll  = long long;

ll d = 1e9+7;

int main() {

	ll N;
	cin>>N;
	vector<ll> A(N);
	for (auto &x : A) {
		cin>>x;
	}
	
	ll ans = 0;
	ll y = 0;
	for (ll c = 0;c < 60;++c) {
		y = 1LL<<c;
		ll a = 0, b = 0;
		for (auto &x : A) {
			if (x&y) a += 1;
			else b += 1;
		}
		
		ans += ((y%d)*((a*b)%d))%d;
	}
	
	cout<<ans%d<<endl;
	return 0;
}


Measured memory_bytes: 2560
import sys
readline = sys.stdin.readline

N = int(readline())
G = [[] for i in range(N)]

for i in range(N - 1):
  a,b,c = map(int,readline().split())
  G[a - 1].append((b - 1, c))
  G[b - 1].append((a - 1, c))
  
Q,K = map(int,readline().split())

dist = [0] * N
stack = [(K - 1, -1, 0)]
while stack:
  v,parent,cost = stack.pop()
  dist[v] = cost
  for child, c in G[v]:
    if child == parent:
      continue
    stack.append((child, v, cost + c))
    
for i in range(Q):
  x,y = map(int,readline().split())
  print(dist[x - 1] + dist[y - 1])


Measured memory_bytes: 50072
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long 
signed main() 
{
    
    IOS;    
    int n;cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(x&1)if(i&1)ans++;
    }
    cout<<ans;
    
    return 0; 
} 

Measured memory_bytes: 3608
def main():
    
    n,k=map(int,input().split())
    h=list(map(int,input().split()))
 
    # dp=[9999999999]*n
    # dp[0]=0
    # dp[1]=abs(h[1]-h[0])
 
    # for i in range(2,n):
    #     for j in range(1,k+1):
    #         if i-j>=0:
    #             dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
    #         else:
    #             break
 
    # print(dp[n-1])
 
 
    #part2
 
    dp=[9999999999]*n
    dp[0]=0
 
    for i in range(n):
        for j in range(1,k+1):
            if i+j<n:
                dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
            else:
                break
 
    print(dp[n-1])
 
 
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 52448
import copy

N = input()
S = input()

key_list = range(0, 1000)
key_list = tuple(map(lambda key: '0' * (3 - len(str(key))) + str(key), key_list))

ans_list = []
for key in key_list:
    flg = True
    cS = copy.copy(S)
    for i in key:
        index = cS.find(i)
        if index == -1:
            flg = False
            break
        cS = cS[index+1:]
    if flg:
        ans_list.append(key)
        
print(len(ans_list))


Measured memory_bytes: 3700
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = false;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		int[] NM = readLineInt();
		int N = NM[0];
		int K = NM[1];
		boolean[] ita = new boolean[N];
		for(int k=0;k<K;k++) {
			int d = readLineInt()[0];
			int[] a = readLineInt();
			for(int dd=0;dd<d;dd++) {
				ita[a[dd]-1]=true;
			}
		}
		
		int ans = 0;
		for(int i=0;i<N;i++) {
			if(!ita[i]) {ans++;}
		}
		
		print(ans);
	}
	
	//functions here
	//note that all methods should be STATIC


	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static int[] sort(int[] base) {
		int[] copy = array_copy(base);
		Arrays.sort(copy);
		return copy;
	}
	private static int[] array_copy(int[] base) {
		int[] copy = new int[base.length];
		for(int i=0;i<base.length;i++) {
			copy[i] = base[i];
		}
		return copy;
	}
	private static int[] asArray(ArrayList<Integer> ints) {
		int[] intlist = new int[ints.size()];
		for(int i=0;i<intlist.length;i++) {
			intlist[i] = ints.get(i);
		}
		return intlist;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


Measured memory_bytes: 33620
#include<iostream>
#include<string>
#include<vector>
#include<cmath>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
	char c;cin >> c;
	cout << (char)(c+1) << endl;

	return 0;
}


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

int main(){
  int N, M, K[30], A[30][30], l, m;
  
  cin >> N >> M;
  for(int i = 0; i < N; i++){
    cin >> K[i];
    for(int j = 0; j < K[i]; j++){
      cin >> A[i][j];
    }
  }
  l = 0; m = 0;
  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      for(int k = 0; k < K[j]; k++){
        if(A[j][k] == i+1){
          l += 1;
        }
      }
    }
    if(l == N){
      m += 1;
    }
    l = 0;
  }
  
  cout << m << endl;
  return 0;
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int dp[100000] ;
    memset(dp, 0, sizeof(dp));
    dp[0] = 0;

    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i >= a[j] && dp[i - a[j]] == 0)
            {
                dp[i] = -1;
            }
        }
    }

    (dp[k] == -1 ? cout << "First" << endl : cout << "Second" << endl);
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n;
    cin>>n;
    pair<string,int>sad[2000];
    for(int i=0;i<n;i++)
    {
        cin>>sad[i].fi>>sad[i].se;
    }
    string s;
    cin>>s;
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        if(s==sad[i].fi)
        {
            for(int j=i+1;j<n;j++)
            {
                cnt+=sad[j].se;
            }
            break;
        }
    }
    cout<<cnt<<nl;
    return 0;
}


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

const int MAXN = 110;
const int MAXA = 1010;
const long long INF = 100000000000000000;

int n, w;
int t[MAXN], c[MAXN];
long long dp[MAXN * MAXA];

int main(){
	for(int i = 1; i <= 100000; i++)
		dp[i] = INF;
	scanf("%d %d", &n, &w);	
	for(int i = 1; i <= n; i++)
		scanf("%d %d", &t[i], &c[i]);
	for(int i = 1; i <= n; i++)
		for(int j = 100000; j >= c[i]; j--)
			dp[j] = min(dp[j], dp[j - c[i]] + t[i]);
	int ans = 100000;
	while(dp[ans] > w)
		ans--;
	printf("%d\n", ans);
	//for(int i = 0; i < 100; i++) printf("dp[%d] = %d\n", i, dp[i]);
}

Measured memory_bytes: 1152
mod=10**9+7
N=int(input())
a=[int(i) for i in input().split()]
F=1
for i in range(1,N+1):
  F=(F*i)%mod

def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod
  
inv=[0]*(N)
for i in range(N):
  inv[i]=power(i+1,mod-2)
S_inv=[0]*(N+1)
for i in range(N):
  S_inv[i+1]=S_inv[i]+inv[i]
ans=0
for i in range(N):
  p=S_inv[i+1]+S_inv[N-i]-1
  ans=(ans+a[i]*F*p)%mod
print(ans)

Measured memory_bytes: 16012
n = int(input())
m = list(map(int, input().split()))

hantei = 10 ** 18
kekka = 1
m.sort()
for x in range(n):
    kekka = kekka * m[x]
    if kekka > hantei:
        print("-1")
        exit()

print(kekka)

Measured memory_bytes: 88796
import sys

D, G = map(int, input().split())
pc = []
for i in range(D):
    pc.append(list(map(int, input().split())))

# print(pc)
ans = sys.maxsize
for i in range(2**D):
    S = bin(i)[2:]
    for j in range(D - len(S)):
        S = "0" + S
    # print(S)

    tmp_p = 0
    tmp_ans = 0
    max_k = 0
    for k in range(D):
        if(S[k:k+1] == "1"):
            tmp_p += pc[k][0] * 100 * (k + 1) + pc[k][1]
            tmp_ans += pc[k][0]
        else:
            if(max_k < k):
                max_k = k

    rest = G - tmp_p
    # print(G, tmp_p)
    if(rest >= 0):
        t = -(-1 * rest // (100 * (max_k + 1)))
        if(t < pc[max_k][0]):
            tmp_ans += t
            if(tmp_ans < ans):
                ans = tmp_ans
    else:
        if(tmp_ans < ans):
            ans = tmp_ans

print(ans)

Measured memory_bytes: 3064
import sys
from collections import defaultdict

_,*s=sys.stdin.read().split()
intl=defaultdict(int)
for p in s:
  intl[p[0]]+=1

march=list(intl[w] for w in 'MARCH')
ans=0
for i in range(5):
  for j in range(i+1,5):
    for k in range(j+1,5):
      ans+=march[i]*march[j]*march[k]
print(ans)

Measured memory_bytes: 17264
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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(x) (x).begin(),(x).end()
signed main(){
    int p,q,r,s;
    cin>>p>>q>>r>>s;
    int n;
    cin>>n;
    int a=min(p*8,min(q*4,min(r*2,s)));
    int b=min(p*4,min(q*2,r));
    cout<<n/2*a+n%2*b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  long long MX=1e18;
  cin>>n;
  vector<long long> a(n);
  long long ans=1;
  bool ng=false;
  for(int i=0;i<n;i++){
    long long a;
    cin>>a;
    if(a==0){
      cout<<0<<endl;
      return 0;
    }
    if(ng || MX/ans<a){
      ng=true;
    }
    ans*=a;
  }
  if(ng) cout<<-1<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 4056
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int start=0,end=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='A') {
			start=i;
			break;
		}
	}
	for(int i=0;i<s.length();i++){
		if(s[i]=='Z') end=i;
	}
	cout<<end-start+1;
	return 0;
} 

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

int n;
string s;

int main() {
	int stock = 0;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		if (s == "A") stock++;
		else stock--;
		if (stock < 0) { cout << "NO" << endl; return 0; }
	}
	if (stock == 0) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	int n;
	int cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x%2==1)cnt++;
	}
	if(cnt%2==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline char nchar() {
	static const int bufl=1<<20;
	static char buf[bufl],*a=NULL,*b=NULL;
	return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
}
inline int read() {
	int x=0,f=1;
	char c=nchar();
	for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=nchar()) x=x*10+c-'0';
	return x*f;
}
template<typename T> inline T& Min(T &x,const T &y) {return x>y?(x=y):x;}
const int maxn=1e5+10;
int n,k,a[maxn];
int f(int x) {
	return (x+k-2)/(k-1);
}
int main() {
	n=read(),k=read(),generate_n(a+1,n,read);
	int p=find(a+1,a+n+1,1)-a,ans=INT_MAX;
	for (int i=max(p-k+1,1);i<=n && i<=p;++i) {
		int r=min(i+k-1,n);
		Min(ans,f(i-1)+f(n-r)+1);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
    int n, k;
    std::cin >> n >> k;

    auto hs = std::vector<uint64_t>();
    hs.reserve(n);

    for(int i = 0; i < n; ++i) {
        int h;
        std::cin >> h;
        hs.push_back(h);
    }

    std::sort(hs.begin(), hs.end(), std::greater<uint64_t>());

    uint64_t answer = 0;

    for(int i = k; i < n; ++i) {
        answer += hs[i];
    }

    std::cout << answer << std::endl;

    return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;
public class Main{
    static tree[] wd;
	public static void main(String[] args) {
	    int x,i,j,n,pn,swi=0,root = 0,hz;
	// TODO Auto-generated method stub
     Scanner sca = new Scanner(System.in);
     n=sca.nextInt();
     wd=new tree[n];
    for(j=0;j<n;j++){
    	x=sca.nextInt();
	if(j==0)root=x;
    	pn=sca.nextInt();
	wd[x]=new tree(x,pn);
    	for(i=0;i<pn;i++) {
	    hz=sca.nextInt();
	    if(hz==root) root=x;
	    wd[x].setchil(hz,i);
    	}
    	if(swi==0&&pn!=0){
    		swi=-1;
    		root=x;
    	}
    }
    chain(root,-1);
     for(i=0;i<n;i++){
    	 System.out.print("node "+i+": parent = "+ wd[i].getpar()+", depth = "+serdepth(i,0)+", ");
	 if(wd[i].getpar()==-1){
    	System.out.print("root, [");
	 }else if(wd[i].getn()==0){
    	 System.out.print("leaf, [");
    	}else{
    		System.out.print("internal node, [");
    	}
	 for(j=0;j<wd[i].getn();j++){
	     System.out.print(wd[i].getchil(j));
	     if(j+1<wd[i].getn()){
    			System.out.print(", ");
    		}
    	}
	   System.out.println("]");	   
   
     }
	}
    public static void chain(int chi,int p){
	int i;
	wd[chi].setpar(p);
	if(wd[chi].getn()==0)return;
	for(i=0;i<wd[chi].getn();i++){
	    chain(wd[chi].getchil(i),chi);
	}
	}
	public static int serdepth(int x,int cnt){
	    if(wd[x].getpar()==-1)return cnt;
		cnt++;
		return serdepth(wd[x].getpar(),cnt);
	}
    
}
class tree{
    int node,par,n,i;
    int[]children;
    tree(int node,int n){
	this.n=n;
	this.node=node;
	children= new int[n];
    }
    public void setchil(int c,int p){
	children[p]=c;
    }
    public int getchil(int c){
	return children[c];
    }
    public void setpar(int p){
	par=p;
    }
    public int getpar(){
	return par;
    }
    public int getn(){
	return n;
    }
    
}



Measured memory_bytes: 140068
import sys
import numpy as np
input = sys.stdin.readline

N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))


A_list.insert(0, 0)
B_list.insert(0, 0)
A_cumsum = np.cumsum(A_list)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M



for i in range(N+1):
    if A_cumsum[i] > K:
        break
    while B_cumsum[j] > K - A_cumsum[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 59220
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

int p[200001],r[200001];
void init(){rep(i,200001)p[i]=i,r[i]=0;}
int find(int x){return (p[x]==x)?x:(p[x]=find(p[x]));}
void unite(int x,int y) {
  x=find(x),y=find(y);
  if(x==y)return;
  if(r[x]<r[y])p[x]=y;
  else{p[y]=x;if(r[x]==r[y])r[x]++;}
}
bool same(int x,int y){return find(x)==find(y);}

void Main() {
  init();
  ll n,m;
  cin >> n >> m;
  rep(i,m) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    unite(x,y);
  }
  ll cnt=0;
  rep(i,n) {
    if(find(i)==i) cnt++;
  }
  pr(cnt-1);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 5204
a,b=map(int,input().split())
 
def prime_factorization(n):
  if n==1:
    return [1]
  else:
    i=2
    ans=[]
    k=int(n**0.5)+1
    for j in range(2,k+1):
      if n==1: break
      if n%j==0:
        n//=j
        ans.append(j)
        while n%j==0:
          n//=j
    if len(ans):
      ans.append(1)
      if n!=1:
        ans.append(n)
      return ans
    else:
      return [1,n]

A=prime_factorization(a)
B=prime_factorization(b)
 
print(len(set(A)&set(B)))

Measured memory_bytes: 9488
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
	int N,M,X,Y;
	cin >> N >> M >> X >> Y;
	vector<int> x;
	vector<int> y;

	REP(i,N){
		int a; cin >> a;
		x.PB(a);
	}

	REP(i,M){
		int a; cin >> a;
		y.PB(a);
	}
	bool ans = false;
	for(int z=X+1;z<=Y;++z){
		bool nans = true;
		REP(i,x.size()){
			if (x[i] >= z) nans = false;
		}
		REP(j,y.size()){
			if (y[j] < z) nans = false;
		}
		ans =  nans || ans;
	}

	if (ans) printf("No War\n");
	else printf("War\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define ar array
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b;
}



Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
using namespace std;
const int MOD=1000000007;
int n,m,t;
int g,h;
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	g=n/gcd(n,t),h=m/gcd(m,t);
	long long res=1;
	res=(res+ksm(2,g)-1)%MOD;
	res=(res+ksm(2,h)-1)%MOD;
	res=(res+ksm(2,gcd(g,h))-2)%MOD;
	res=ksm(res,1LL*(n/g)*(m/h))%MOD;
	printf("%lld",res);
	return 0;
}

Measured memory_bytes: 3788
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

result = 0
for i in range(N):
    A = list(map(int, input().split()))
    if sum(A[j] * B[j] for j in range(M)) + C > 0:
        result += 1

print(result)

Measured memory_bytes: 3060
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var count = 0;
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s == "E869120") count++;
        }
        Console.WriteLine(count);
    }
}



Measured memory_bytes: 8020
import java.util.*;
 
class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int count=0;
	for(int i = 1; i <= b; i++) {
		if((a * i) % b == c) {
			count++;
			break;
		}
	}
	if(count==1)System.out.println("YES");
	else System.out.println("NO");
}
}


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

using namespace std;

int main() {

	int N, M;
	int *H, *MaxH;
	int x, y, total=0;

	cin >> N >> M;

	H = new int[N];
	MaxH = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> H[i];
		MaxH[i] = 0;
	}

	for (int i = 0; i < M; i++) {
		cin >> x >> y;
		MaxH[x - 1] = max(MaxH[x - 1], H[y - 1]);
		MaxH[y - 1] = max(MaxH[y - 1], H[x - 1]);
		}

	for (int j = 0; j < N; j++) {
		if(H[j] > MaxH[j]) total += 1;
	}

	cout << total;

	return 0;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    // int n; cin >> n;
    // vstr s(n);
    // rep(i,n) cin >> s[i];
    // map<char,int> map;

    // rep(i,n){
    //     rep(j,s[i].size()) map[s[i][j]]++;
    // }   
    // string res;

    int n; cin >> n;
    vstr s(n);
    vvint word(n,vint(26,0));

    rep(i,n){
        cin >> s[i];
    }
    rep(i,n){
        rep(j,s[i].size()){
            word[i][s[i][j]-'a']++;
        }
    }
    //cout<<word[0][0]<<' '<<word[1][0]<<endl;
    rep(i,26){
        int max=INF;
        rep(j,n){
            chmin(max,word[j][i]);
        }
        char c='a'+i;
        rep(i,max) cout<<c;
    }
    cout<<endl;



}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i= 0;i<N;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  a.push_back(1000000);
  
  vector<int> ans;
  if(N>=2){
  for(int i =0;i<N;i++){
     int c = 0;
    if(i>=1 && a[i]==a[i-1]){
      continue;
    }
    for(int j = i;j<N+1;j++){
      if(a[j] <= a[i] +2){
        c++;
      }
      else if(a[j] > a[i] +2){/*aの末尾に大きい数字を足さないとa ={2,4}のようなケースでは、
      else if文を満たすa[j]が存在しないので、ans配列が空集合になりREとなる*/
        ans.push_back(c);
        ans.push_back(c);
        break;
       }
      }
     }
   sort(ans.begin(),ans.end());
   cout << ans[ans.size()-1] << endl;
  }
  if(N == 1) cout << 1 << endl;
}


Measured memory_bytes: 1656
package main

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

func main() {
	var wtr = bufio.NewWriter(os.Stdout)

	var H, W int
	fmt.Scan(&H, &W)
	S := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scan(&S[i])
	}
	Ans := make([]string, H)
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			var sum int
			if S[i][j] == '.' {
				if i-1 >= 0 && j-1 >= 0 && S[i-1][j-1] == '#' {
					sum++
				}
				if i-1 >= 0 && S[i-1][j] == '#' {
					sum++
				}
				if i-1 >= 0 && j+1 < W && S[i-1][j+1] == '#' {
					sum++
				}
				if j-1 >= 0 && S[i][j-1] == '#' {
					sum++
				}
				if j+1 < W && S[i][j+1] == '#' {
					sum++
				}
				if i+1 < H && j-1 >= 0 && S[i+1][j-1] == '#' {
					sum++
				}
				if i+1 < H && S[i+1][j] == '#' {
					sum++
				}
				if i+1 < H && j+1 < W && S[i+1][j+1] == '#' {
					sum++
				}
				Ans[i] += strconv.Itoa(sum)
			} else {
				Ans[i] += "#"
			}
		}
	}
	for _, v := range Ans {
		fmt.Fprintln(wtr, v)
	}
	_ = wtr.Flush()
}


Measured memory_bytes: 1924
#include <memory.h>
#include <iostream>
#include <vector>
using namespace std;

#define ll long long
#define N 100002
#define M 3000000

struct Node {
	Node *l, *r;
	ll sum;
	int cc;
};

Node nodePool[M];

Node *newNode() {
	static int nodePos = 0;
	Node &cur = nodePool[nodePos];
	cur.l = cur.r = NULL;
	cur.sum = cur.cc = 0;
	return &nodePool[nodePos++];
}

Node *init(int l, int r) {
	if (l == r) {
		return newNode();
	}
	Node *node = newNode();
	int mid = (l + r) / 2;
	node->l = init(l, mid);
	node->r = init(mid + 1, r);
	return node;
}

int a[N], b[N], c[N], d[N];
vector<int> adj[N];
Node *seg[N];

Node* update(Node *par, int l, int r, int ind, int val) {
	if (l == r) {
		Node *cur = newNode();
		cur->sum = par->sum + val;
		cur->cc = par->cc + 1;
		return cur;
	}
	Node *cur = newNode();
	int mid = (l + r) / 2;
	if (ind <= mid) {
		cur->r = par->r;
		cur->l = update(par->l, l, mid, ind, val);
	}
	else {
		cur->l = par->l;
		cur->r = update(par->r, mid + 1, r, ind, val);
	}
	cur->sum = cur->l->sum + cur->r->sum;
	cur->cc = cur->l->cc + cur->r->cc;
	return cur;
}
#define T 20
int depth[N];
int anc[N][T];

int getLca(int x, int y) {
	if (depth[x] < depth[y]) {
		swap(x, y);
	}
	int diff = depth[x] - depth[y];
	for (int i = 0; i < T; ++i) {
		if (diff&(1 << i)) {
			x = anc[x][i];
		}
	}
	if (x != y) {
		for (int i = T - 1; i >= 0; --i) {
			if (anc[x][i] != anc[y][i]) {
				x = anc[x][i], y = anc[y][i];
			}
		}
		x = anc[x][0];
	}
	return x;
}
void dfs(int cur, int p,int n) {
	if (cur == 1) {
		seg[cur] = init(1,n);
	}
	int sz = adj[cur].size(), id, ch;
	anc[cur][0] = p;
	for (int i = 1; i < T; ++i) {
		anc[cur][i] = anc[anc[cur][i - 1]][i - 1];
	}
	for (int i = 0; i < sz; ++i) {
		id = adj[cur][i];
		ch = a[id] ^ b[id] ^ cur;
		if (ch == p) {
			continue;
		}
		depth[ch] = depth[cur] + 1;
		seg[ch] = update(seg[cur], 1, n, c[id], d[id]);
		dfs(ch, cur, n);
	}
}

pair<ll, ll> query(Node *cur, int l, int r, int ind) {
	if (l == r) {
		return make_pair(cur->sum, cur->cc);
	}
	int mid = (l + r) / 2;
	if (ind <= mid) {
		return query(cur->l, l, mid, ind);
	}
	else {
		return query(cur->r, mid + 1, r, ind);
	}
}
void solve() {
	int n, q; scanf("%d %d", &n, &q);
	for (int i = 0; i < n - 1; ++i) {
		scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
		adj[a[i]].push_back(i);
		adj[b[i]].push_back(i);
	}

	dfs(1, 0, n);
	while (q--) {
		int x, y, u, v;
		scanf("%d %d %d %d", &x, &y, &u, &v);
		int lca = getLca(u, v);
		ll ret = seg[u]->sum + seg[v]->sum - 2 * seg[lca]->sum;
		pair<ll, ll> q = query(seg[u], 1, n, x);
		pair<ll, ll> tmp = query(seg[v], 1, n, x);
		q.first += tmp.first;
		q.second += tmp.second;
		tmp = query(seg[lca], 1, n, x);
		q.first -= tmp.first * 2;
		q.second -= tmp.second * 2;
		ret -= q.first;
		ret += q.second*y;
		printf("%lld\n", ret);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}

Measured memory_bytes: 86528
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B;
  char op;
  cin >> A >> op >> B;
  if(op == '+'){
    cout << A + B << endl;
  }
  else{
    cout << A - B << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

int main(int argc, char const *argv[]) {
    ll N;
    ll T, A;
    ll x = 1;
    ll y = 1;
    ll n;
    std::cin >> N;
    for (size_t i = 0; i < N; i++) {
        std::cin >> T >> A;
        // n = std::max(std::ceil((double)x / T), std::ceil((double)y / A));
        n = std::max((x + T - 1) / T, (y + A - 1) / A);
        x = n * T;
        y = n * A;
    }
    std::cout << x + y << '\n';
    return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
lim = int(1e5) + 1
inf = float("inf")

# DP
dp = [[inf for _ in range(lim)] for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(lim):
        if wv[i][1] <= j:
            dp[i+1][j] = min(dp[i][j - wv[i][1]] + wv[i][0], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]
        
for i in range(lim):
    if dp[N][i] <= W:
        ans = i
print(ans)

Measured memory_bytes: 340992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
typedef unsigned long long ULL;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    const ULL MAX = 1000000000000000000;
    int n;
    ULL tmp;
    cin >> n;
    ULL ans = 1;
    rep(i,n) {
        cin >> tmp;
        if (tmp == 0) {
            cout << 0 << endl;
            return 0;
            }

        if (log10(tmp) + log10(ans) > 18) ans = MAX + 1;
        else {
            ans *= tmp;
        }
    }

    if (ans > MAX) {
            cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int ans = 0;
    int tmp = 0;
    string S;
    cin >> S;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'R') {
            tmp++;
        } else {
            tmp = 0;
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

ll n;
vector<ll> x;
vector<ll> y;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n; 
    for(int i = 0; i < n; ++i){
        ll a, b; cin >> a >> b;
        x.pb(a + b); y.pb(a - b);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    cout << max(y[n - 1] - y[0], x[n - 1] - x[0]);
    return 0;
}

Measured memory_bytes: 6708
#include <sstream>
#include <iostream>
#include <map>
using namespace std;

map<string, int> prefix;

void init(){
    prefix["yotta"] = 24;
    prefix["zetta"] = 21;
    prefix["exa"] = 18;
    prefix["peta"] = 15;
    prefix["tera"] = 12;
    prefix["giga"] = 9;
    prefix["mega"] = 6;
    prefix["kilo"] = 3;
    prefix["hecto"] = 2;
    prefix["deca"] = 1;
    prefix["deci"] = -1;
    prefix["centi"] = -2;
    prefix["milli"] = -3;
    prefix["micro"] = -6;
    prefix["nano"] = -9;
    prefix["pico"] = -12;
    prefix["femto"] = -15;
    prefix["ato"] = -18;
    prefix["zepto"] = -21;
    prefix["yocto"] = -24;
}

int main(){
    init();
    int N;
    for(cin >> N, cin.ignore(); N--;){
        stringstream ss;
        string str, tk1, tk2;
        int exp = 0;
        getline(cin, str);
        ss << str;
        ss >> tk1 >> tk2;
        if(prefix.find(tk2) != prefix.end()){
            exp += prefix[tk2];
            ss >> tk2;
        }
        bool av = false, dot = false;
        string mt;
        for(string::iterator it = tk1.begin(); it != tk1.end(); ++it){
            if(*it == '.'){
                dot = true;
            }
            if(av && !dot){
                ++exp;
            }
            if(*it != '.' && (av || '1' <= *it && *it <= '9')){
                av = true;
                mt.push_back(*it);
            }
            if(*it == '0' && !av){
                --exp;
            }
        }
        if(mt.size() > 1){
            mt.insert(1, 1, '.');
        }
        cout << mt << " * 10^" << exp << ' ' << tk2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1276