akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

long long lcm(long long a, long long b)
{
	return a * b / gcd(a, b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}

int main()
{
	int k;
	cin >> k;
	int a, b;
	cin >> a >> b;
	if (a % k == 0)
	{
		cout << "OK";
	}
	else
	{
		cout << ((b - a) >= (k - (a % k)) ? "OK" : "NG");
	}
}



Measured memory_bytes: 34196
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        c: chars,
    }
    println!("{}", (c[0] as u8 + 1) as char);
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
typedef long long ll;
#define mp make_pair
vector<pair<ll,int> > e;
map<ll,int> ret;
int n;
inline void die(){
    puts("-1");
    exit(0);
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        ret[x]=i;
        e.push_back(mp(x,i));
    }
    sort(e.begin(),e.end());
    reverse(e.begin(),e.end());
    ll x=e.back().first;
    vector<int> siz(n,1);
    vector<ll> dp(n,0);
    vector<pair<int,int> > ans;
    for(int i=0;i<e.size();i++){
        pair<ll,ll> c=e[i];
        if(c.first==x) continue;
        if(siz[c.second]*2>=n){
        	die();
		}
        ll need=c.first+2*siz[c.second]-n;
        if(!ret.count(need)){
        	die();
		}
        int par=ret[need];
        dp[par]+=dp[c.second]+siz[c.second];
        siz[par]+=siz[c.second];
        ans.push_back(mp(c.second+1,par+1));
    }
    if(dp[e.back().second]!=x){
    	die();
	}
    for(int i=0;i<ans.size();i++){
    	if(ans[i].first>ans[i].second){
    		swap(ans[i].first,ans[i].second);
		}
	}   
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}
    return 0;
}


Measured memory_bytes: 12144
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        //String[] str = new String[N];
        int[] a = {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};
        
        System.out.println(a[N-1]);
    }
}

Measured memory_bytes: 35620
gets.chomp.each_char.with_index do |s,i|
  if i%2==0
    unless [?R,?U,?D].include? s
      puts 'No'
      exit
    end
  else
    unless [?L,?U,?D].include? s
      puts 'No'
      exit
    end
  end
end
puts 'Yes'


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N;i++)
        cin >> A[i];
    vector<int> ans(N,0);

    for (int i = 0; i < N;i++)
        ans[A[i]-1] = i+1;

    for (int i = 0; i < N;i++)
        cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 1536
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
    return input().split()
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7
alp=string.ascii_lowercase
d_al=dict([(i,j) for j,i in enumerate(alp)])

s=[d_al[i] for i in input()]
t=[d_al[i] for i in input()]
Ss=set(s)
St=set(t)
ns=len(s)
nt=len(t)
ss=s*2
#print(ss)

g=[{} for _ in range(ns)]
pos=[-1]*26
for i in range(ns*2)[::-1]:
    for j in Ss:
        if i<ns:
            g[i][j]=pos[j]-i
    pos[ss[i]]=i
#for i in range(len(g)):
#    print(g[i])

if len(St-Ss)!=0:
    ans=-1
else:
    cur=0
    cur+=g[-1][t[0]]-1
    #print(cur)
    for i in range(1,nt):
        #print(cur,s[cur%ns],'tg=',t[i],g[cur%ns][t[i]])
        cur+=g[cur%ns][t[i]]
    ans=cur+1
print(ans)


Measured memory_bytes: 376668
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO  freopen("C:\\Users\\sourav\\Documents\\cp files\\input.txt", "r", stdin); freopen("C:\\Users\\sourav\\Documents\\cp files\\output.txt", "w", stdout); 
#define maxn 1000000
 
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


signed main()
{
	
	
 	FLASH
 	int n , k;
 	cin>>n>>k;
 	int arr[n];
 	for (int i = 0; i < n; ++i)
 			{
 				/* code */
 				cin>>arr[i];
 			}		
 			int dp[n];
 			memset(dp , mod , sizeof(dp));
 			dp[0] = 0;
 			dp[1] = abs(arr[1] - arr[0]);
 			for(int i = 2; i < n; i++)
 			{
 				for(int j = i - 1; j >= max((int)0 , i - k); j--)
 				{
 					dp[i] = min(dp[i] , dp[j] + abs(arr[i] - arr[j]));
 				}
 			}
 			cout<<dp[n - 1];
}

Measured memory_bytes: 1792
#include<stdio.h>

long ruijo(long n, long k){
if(k == 0) return 1;
else return n*ruijo(n,k-1);
}

int main(void){

long N, K;

scanf("%ld %ld",&N, &K);

printf("%ld", K*ruijo(K-1,N-1));

return 0;
}

Measured memory_bytes: 128
w,h=map(int,input().split())
p=[int(input()) for _ in range(w)]
q=[int(input()) for _ in range(h)]
p.sort(reverse=True)
q.sort(reverse=True)
ans=0
c,r=w+1,h+1
while p or q:
  if q and (not p or p[-1]>q[-1]):
    ans+=q.pop()*c
    r-=1
  else:
    ans+=p.pop()*r
    c-=1
print(ans)

Measured memory_bytes: 17332
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const [n, k] = inputs[0].split(' ').map(BigInt);
  const city = inputs[1].split(' ').map(BigInt);
  let roopSet = new Set<number>();
  let roop: number[] = [];
  let roopStart = 0;
  let teleport = 1;
  let isRoopExist = false;

  for (let i = 1; i <= k; i++) {
    if (!roopSet.has(teleport)) {
      roopSet.add(teleport);
    } else if (i < k && roopSet.has(teleport)) {
      roopSet.forEach((value) => roop.push(value));
      roop = roop.slice(roop.indexOf(teleport), roop.length);
      isRoopExist = true;
      break;
    }
    teleport = Number(city[teleport - 1]);
    roopStart++;
  }

  if (isRoopExist) {
    teleport = roop[Number((k - BigInt(roopStart)) % BigInt(roop.length))];
  }

  console.log(teleport);
}


Measured memory_bytes: 65548
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
    //code here...
    
    int n;
    
    cin >> n;
    int ara[n+1], ans=0;
    for(int K=1; K<=n; K++){
		cin >> ara[K];
		if(K%2==1 && ara[K]%2==1) ans++;
	}
	
	cout << ans << "\n";
}


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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}




Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

int N, Q;

int main() {
    cin >> N >> Q;
    set<P> D;
    vector<tuple<int,int,int>> X;
    rep(i,N) {
        int s, t, x;
        cin >> s >> t >> x;
        X.emplace_back(x,s-x,t-x);
    }
    rep(i,Q) {
        int d;
        cin >> d;
        D.insert(P(d,i));
    }
    vector<int> res(Q,-1);
    sort(ALL(X));
    rep(i,N) {
        int s, t, x;
        tie(x,s,t) = X[i];
        if (D.empty()) continue;
        auto it = D.lower_bound(P(s,-1));
        while(D.size() && it != D.end()) {
            if (it->first >= t) break;
            res[it->second] = x;
            D.erase(it++);
        }
    }
    rep(i,Q) cout << res[i] << endl;
}

Measured memory_bytes: 15796
def solve():
    h = read()
    result = think(h)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h):
    n = len(h)
    invalid = 10 ** 20

    dp = [[0 for x in range(2)] for y in range(len(h))]
    dp[0][0] = h[0]
    dp[0][1] = h[0] - 1
    for i in range(1, len(h)):
        dp[i][0] = h[i]
        dp[i][1] = h[i] - 1

        if dp[i][0] < dp[i - 1][0] and dp[i][0] < dp[i - 1][1]:
            dp[i][0] = invalid
        elif dp[i][0] < dp[i - 1][0] and dp[i][0] >= dp[i - 1][1]:
            dp[i][0] = h[i]
        elif dp[i][0] >= dp[i - 1][0] and dp[i][0] >= dp[i - 1][1]:
            dp[i][0] = h[i]
        elif dp[i][0] >= dp[i - 1][0] and dp[i][0] < dp[i - 1][1]:
            dp[i][0] = h[i]

        if dp[i][1] < dp[i - 1][0] and dp[i][1] < dp[i - 1][1]:
            dp[i][1] = invalid
        elif dp[i][1] < dp[i - 1][0] and dp[i][1] >= dp[i - 1][1]:
            dp[i][1] = h[i] - 1
        elif dp[i][1] >= dp[i - 1][0] and dp[i][1] >= dp[i - 1][1]:
            dp[i][1] = h[i] - 1
        elif dp[i][1] >= dp[i - 1][0] and dp[i][1] < dp[i - 1][1]:
            dp[i][1] = h[i] - 1

    return dp[n - 1][0] < invalid or dp[n - 1][1] < invalid


def write(result):
    if result:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    solve()

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

#ifdef _DEBUG
    #include "/home/v-o_o-v/deb.h"
    #define deb(x...)cerr << "[" << #x << "] = [";_print(x);
#else
    #define deb(x...)
#endif

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
   
    ll n;
    cin >> n;
    if(n <= 26){
        cout << (char)('a' + n - 1) << '\n';
        return 0;
    }
    string ans;
    while(n){
        n -= 26;
        if(n < 0){
            n += 26;
            if(n % 26 == 0)ans += 'z';
            else ans += (n % 26 - 1 + 'a');
            break;
        }
        if(n % 26 == 0)ans += 'z';
        else ans += (n % 26 - 1 + 'a');
        n = ceil(n / (long double)26);
    }
    reverse(all(ans));
    cout << ans << '\n';
    return 0;
}
// Write Here


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;

int main() {
  string a[3];
  cin >> a[0] >> a[1] >> a[2];
  int p = 0;
  for (;;) {
    if (a[p].size() == 0) {
      cout << static_cast<char>(p + 'A') << endl;
      return 0;
    }
    int q = a[p][0] - 'a';
    a[p] = a[p].substr(1);
    p = q;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//https://atcoder.jp/contests/arc061/tasks/arc061_a
typedef long long ll;
int main()
{
    string input;
    cin >> input;
    ll len = (input.length() - 1);
    ll res = stol(input);
    for (int bit = 1; bit < (1 << len); bit++)
    {
        ll temp = 0;
        for (ll i = 0; i < len; i++)
        {
            temp *= 10;
            temp += input.at(i) - '0';
            if (bit & (1 << i))
            {
                res += temp;
                temp = 0;
            }
        }
        temp *= 10;
        temp += input.at(len) - '0';
        res += temp;
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int main()
{
    int n,m,sum=0,i;
    cin >> n >> m;
    int arr[m];
    for(i=0; i<m; i++)
    {
        cin >> arr[i];
        sum+=arr[i];
    }
    if(sum<=n)
        cout << n-sum;
    else
        cout << -1;
    return 0;

}

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

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

    string S;
    cin >> S;
    int o0 = 0, o1 = 0, e0 = 0, e1 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (S[i] == '0') e0++;
            else
                e1++;
        } else {
            if (S[i] == '0') o0++;
            else
                o1++;
        }
    }
    cout << min(o0 + e1, o1 + e0) << endl;

    return 0;
}


Measured memory_bytes: 512
// B - 754
// https://atcoder.jp/contests/abc114/tasks/abc114_b
// +build ignore

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	var tmp int
	ans := 753
	fmt.Scan(&s)
	if len(s) < 3 {
		si, _ := strconv.Atoi(s)
		ans = 753 - si
		fmt.Println(ans)
	} else {
		for i := 0; i < (len(s) - 2); i++ {
			// Index of string
			// 0   1   2   3   4   5
			// | A | B | C | D | E |
			si, _ := strconv.Atoi(s[i : i+3])
			tmp = 753 - si
			if tmp < 0 {
				tmp *= -1
			}
			if tmp < ans {
				ans = tmp
			}
		}
		fmt.Println(ans)
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <unordered_map>
#include <queue>
#include <map>
#include <sstream>
#include <set>
#include <cstdlib>
#include <ctime>
#include <unordered_set>
#include <bitset>
#include <chrono>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
//#pragma GCC optimize(3, "Ofast", "inline")
#define MAX_INF 0x3f3f3f3f
template <class T, class C>
void print(C name, T a)
{
	cout << name << ": " << a << endl;
}
template <class T>
T gcd(T a, T b)
{
	return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b, ll p)
{
	ll ans = 1;
	a %= p;
	while (b)
	{
		if (b & 1)
			ans = ans * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return ans;
}
template <typename _Tp>
void read(_Tp &x)
{
	char ch;
	bool flag = 0;
	x = 0;
	while (ch = getchar(), !isdigit(ch))
		if (ch == '-')
			flag = 1;
	while (isdigit(ch))
		x = x * 10 + ch - '0', ch = getchar();
	if (flag)
		x = -x;
}
template <class T>
void print(T x)
{
	if (x < 0)
	{
		x = -x;
		putchar('-');
	}
	if (x > 9)
		print(x / 10);
	putchar(x % 10 + '0');
}
const ll mod = 998244353;
const ll inf = 1e18;
ll add(ll x, ll t)
{
	x %= mod;
	t %= mod;
	return (x + t) % mod;
}
ll del(ll ans, ll x)
{
	ans %= mod;
	ans += mod;
	x %= mod;
	return (ans - x) % mod;
}
ll mul(ll ans, ll x)
{
	ans %= mod;
	x %= mod;
	return (ans * x) % mod;
}
#define fir(i, a, b) for (int i = a; i <= b; i++)
const int maxn = 1e5 + 20, N = 2010, M = 3000 + 10;
ll a[maxn];
int main()
{
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);d=abs(d);
	ll temp=x/d;
	if(temp>=k)
	{
		cout<<x-k*d<<endl;
	}
	else 
	{
		if((k-temp)&1)
		cout<<abs(x-d*(temp+1))<<endl;
		else
		cout<<abs(x-d*temp)<<endl;
	}
}

Measured memory_bytes: 3196
#include <iostream>

int main(){
    int A,B, Max = 0;
    scanf("%d %d", &A, &B);
    Max = A + B;
    if((A - B) > Max){
        Max = A - B;
    }
    if((A * B) > Max){
        Max = A * B;
    }
    printf("%d", Max);

    return 0;
}

Measured memory_bytes: 760
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    friends = [set() for _ in range(n+1)]
    blocks = [set() for _ in range(n+1)]
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a] |= {b}
        friends[b] |= {a}
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        blocks[c] |= {d}
        blocks[d] |= {c}
    for i in range(1, n+1):
        nf = len(friends[i])
        nb = sum([uf.same(i, b) for b in blocks[i]])
        ans = uf.size(i) - 1 - nf - nb
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 138780
#include <bits/stdc++.h>
 
using namespace std;
 
 
//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
 
#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
 
//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vch;
typedef vector<long long> vll;
typedef vector<string> vstr;
 
 
int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b){ll ans=1; rep(i, b){ans=ans*a%MOD;} return ans;}
 
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};
 
 
 
 
template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}
 
 
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}
 
 
 
 
int main(){
 
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vint a(n);
    int four = 0;
    int two = 0;
    rep(i, n){
        cin >> a[i];   
    }
    rep(i, n){
        if(a[i]%4==0){
           four++;
        }
        else if(a[i]%2==0){
            two++;
        }
    }


    bool ok = false;
    dpp(four);

    if(n/2 <= four + two/2)
        ok = true;

    
    Judge(ok);


 
    return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    int diff;
    if(a > b) diff = a - b;
    else diff = b - a;

    int check = diff;
    int i = 1;

    if (diff == c)
    {
        cout << "YES" << endl;
        return 0;
    }

    while(true){
        check += diff;
        check %= b;

        if(check == c){
            cout << "YES" << endl;
            break;
        }

        if(check == diff){
            cout << "NO" << endl;
            break;
        }
    }
    return 0;
}

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

istringstream iss;
int a;

bool parse(){
	char ch;
	iss >> ch;

	if( isalpha( ch ) ){
		if( ch == 'T' ) return true;
		if( ch == 'F' ) return false;
		return ( a >> (ch - 'a') ) & 1;
	}
	
	if( ch == '-' ){
		return !parse();
	}

	bool f1 = parse();
	iss >> ch;
	if( ch == '-' ) iss.ignore();
	bool f2 = parse();
	iss.ignore();
	if( ch == '*' )	return f1 && f2;
	if( ch == '+' ) return f1 || f2;
	return f1 <= f2;
}

bool solve(const string &input){
	for( a = 1 << 11; a--; ){
		iss.clear();
		iss.str(input);

		bool left = parse();
		iss.ignore();
		bool right = parse();
		if( left != right ){ return false; }
	}
	return true;
}


int main(){
	string s;
	while( cin >> s, s[0] != '#' ){
		cout << (solve(s) ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 960
val MOD = 1000000007

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toLong() }

    var ans = 0L

    for (i in 0..60) {
        val bits = aa.map { (it shr i) and 1L }.sum()
        val sum = (bits * (n - bits) % MOD) * ((1L shl i) % MOD)
        ans += sum % MOD
        ans %= MOD
    }

    println(ans)
}

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

int main() {
  string S;
  cin >> S;
  if(S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int uc = 0;
  for(int i = 1; i < S.size(); ++i) {
    if(S[i] == 'C') {
      if(i < 2 || S.size() - 2 < i) {
        cout << "WA" << endl;
        return 0;
      }
      uc++;
      if(uc > 1) {
        cout << "WA" << endl;
        return 0;
      }
    } else if(!('a' <= S[i] && S[i] <= 'z')) {
      cout << "WA" << endl;
      return 0;
    }
  }
  if(uc == 0) {
    cout << "WA" << endl;
    return 0;
  }
  cout << "AC" << endl;
  return 0;
}


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

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


//解答方針（着眼点）
//あるedge i がbridge であることは
//そのedge i を除去したとき, a[i] と　b[i]　が異なるグループに属することと
//必要十分である
//-> これは, tree.same(a[i], b[i])により判定できる


int main(){
    int n, m;
    cin >> n >> m;
    
    vector<int> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    
    
    //i -> 切断するedgeを表す
    
    int number_of_bridges = 0;
    
    rep(i, m){
        
        UnionFind tree(n);
        
        //j -> 残すedgeを表す
        
        rep(j, m){
            
            if (j != i) tree.unite(a[j], b[j]);
        }
        
        //a[i] と　b[i]　が異なるグループに属するか否かを判定する
        
        if (tree.same(a[i], b[i])) continue;
        else number_of_bridges++; //edge i を除去したとき, a[i]とb[i]が異なるグループに属する
    }
    
    cout << number_of_bridges << endl;
}


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

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

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

    int q;
    cin >> q;

    int b, m, e;
    for(int i = 0; i < q; i++){
        cin >> b >> m >> e;
        rotate(a+b, a+m, a+e);
    }

    for(int i = 0; i < n; i++)  cout << a[i] << " \n"[i == n-1];
    
    return 0;
}


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

int main(){

    string s;
    int count = 0;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {

        if(s[i] == '1')
            count++;
    }

    cout << count << endl;

    return 0;
    
}

Measured memory_bytes: 256
using namespace std;
#include<iostream>
#include<vector>
int N,M;
int ans=1;
const int DIM=100010;
int cost[DIM];
int h[DIM];



int main(){
    int a,i,j,k,x,y,z;
    int c = 0; 
    long s; 
    cin >> N ; 
    cin >> x; 
    h[1] = x ;
    cost[1] = 0;
    cin >> x; 
    h[2] = x ;
    cost[2] = abs(h[2] - h[1]); 

    for(i=3;i<=N;i++){
        cin >> x; 
        h[i] = x ;
        cost[i] = min( cost[i-1] + abs(h[i] - h[i-1]), cost[i-2] + abs(h[i] - h[i-2]));
    }
    cout << cost[N]  << endl;

}

Measured memory_bytes: 1024
from fractions import gcd

def main():

    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9 + 7


    LCM = 1
    for a in A:
        LCM = LCM * a // gcd(LCM, a)

    total = 0
    for a in A:
        total += LCM // a
        

    print(total % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const double eps = 1e-10;
const double inf = 1e+10;
const double pi = acos(-1.0);
int sgn(double a) { return a < -eps ? -1 : a > eps; }
using P = complex<double>;
istream& operator>>(istream& i, P& p) { double x, y; i >> x >> y; p = P(x, y); return i; }
ostream& operator<<(ostream& o, const P& p) { o << real(p) << ' ' << imag(p); return o; }
bool operator<(const P& p, const P& q) { return sgn(real(p) - real(q)) ? sgn(real(p) - real(q)) < 0 : sgn(imag(p) - imag(q)) < 0; }
bool operator>(const P& p, const P& q) { return q < p; }
bool operator<=(const P& p, const P& q) { return !(p > q); }
bool operator>=(const P& p, const P& q) { return !(p < q); }
bool eq(const P& p, const P& q) { return !(p < q) and !(p > q); }
double dot(const P& p, const P& q) { return real(conj(p) * q); }
double cross(const P& p, const P& q) { return imag(conj(p) * q); }

int ccw(P p0, P p1, P p2) {
  p1 -= p0, p2 -= p0;                         //             (1)
  if (sgn(cross(p1, p2)) > 0) return 1;       //
  if (sgn(cross(p1, p2)) < 0) return -1;      // (-2)---p0---(0)---p1---(2)
  if (sgn(dot(p1, p2) < 0)) return -2;        //
  if (sgn(norm(p1) - norm(p2)) < 0) return 2; //             (-1)
  return 0;
}

bool convex(V<P>& ps) {
  int n = ps.size();
  for (int i = 0; i < n; i++) if (ccw(ps[i], ps[(i + 1) % n], ps[(i + 2) % n]) == -1) return false;
  return true;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<P> ps(n); for (int i = 0; i < n; i++) cin >> ps[i];
  cout << convex(ps) << '\n';
}


Measured memory_bytes: 3376
fun main(args: Array<String>) {
    val n = Integer.parseInt(readLine()) ?: 0
    val vlist = readLine()?.split(" ") ?: listOf()
    val clist = readLine()?.split(" ") ?: listOf()
    var ans = 0
    for(i in 0..n-1) {
      val total = Integer.parseInt(vlist[i] ?: "0") - Integer.parseInt(clist[i] ?: "0")
      if(total > 0) ans += total
    }
    println(ans)
}


Measured memory_bytes: 37968
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
int par[MAXN], a[MAXN];

int find(int cur) {
    if (cur == par[cur]) return cur;
    else return par[cur] = find(par[cur]);
}

void merge(int x, int y) {
     x = find(x);
     y = find(y);
     par[x] = y;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &a[i]);
        par[i] = i;
    }
    for (int i = 0; i < M; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        merge(x, y);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (find(a[i]) == find(i)) ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
T power(T x, long long n, const T& m){
    if(n == 0) return 1;
    if(n == 1) return x;
    T tmp = power(x, n/2, m);
    if(n%2 == 0) return tmp * tmp % m;
    else return tmp * tmp % m * x % m;
}

template<typename T>
T inverse(T x, const T& m){
    return power(x, m-2, m);
}

struct Combination{
private:
    int N;
    long long M;
    vector<long long> f, i;
public:
    void init(int n, long long m){
        N = n; M = m;
        f.resize(N+1); f[0] = 1;
        for(long long j=1; j<=N; j++){
            f[j] = f[j-1]*j%M;
        }
        i.resize(N+1); i[N] = inverse(f[N], M);
        for(long long j=N-1; j>=0; j--){
            i[j] = i[j+1] * (j+1) % M;
        }
    }
    long long fact(int n){
        return f[n];
    }
    long long C(int n, int r){
        return f[n] * i[r] % M * i[n-r] % M;
    }
};

int K;
string S;
Combination C;

signed main(){
    cin >> K >> S;
    C.init(K+S.size(), MOD);
    ll ans = 0;
    ll p1 = 1;
    ll p2 = power(26LL, K, MOD);
    ll inv = inverse(26LL, MOD);
    rep(i, K+1){
        ans += C.C(i+S.size()-1, i) * p1 % MOD * p2 % MOD;
        p1 = p1*25LL%MOD;
        p2 = p2*inv%MOD;
    }
    cout << ans%MOD << endl;
}


Measured memory_bytes: 35596
input_int_array = lambda : [int(s) for s in input().split() if s]

def solve_freq():
    N = int(input())
    W = input_int_array()
    total = sum(W)
    min_val = total
    S1 = 0
    for T in range(N):
        S1 += W[T]
        diff = abs(total-2*S1)
        if min_val < diff:
            break
        min_val = diff
    print(min_val)

solve_freq()

Measured memory_bytes: 3064
(let ((n (read))
      (k (read))
      (a (make-array 1 :element-type 'integer
                       :initial-element 0
                       :fill-pointer 1
                       :adjustable t))
      (b (make-array 0 :element-type 'integer
                       :adjustable t
                       :fill-pointer 0))
      (ans 0))
  (loop for x from 1 upto n do
        (vector-push-extend (+ (aref a (1- x)) (read)) a))
  (loop for x from 0 upto (1- n) do
        (loop for y from (1+ x) upto n do
              (vector-push-extend (- (aref a y) (aref a x)) b)))
  (loop for i from 40 downto 0 do
        (let ((count 0))
          (loop for x across b do
                (if (= (+ ans (expt 2 i)) (logand x (+ ans (expt 2 i)))) (incf count)))
          (if (>= count k) (incf ans (expt 2 i)))))
  (princ ans))


Measured memory_bytes: 24800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }

        long res = 1L << 60;
        long tmp = 1L << 60;
        for(int j = 0; j + K - 1 < N; j++) {
            int left = a[j];
            int right = a[j + K - 1];
            tmp = Math.min(Math.abs(left) + Math.abs(left - right), Math.abs(right) + Math.abs(left - right));
            res = Math.min(res, tmp);
        }
        System.out.println(res);
    }
}


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

using std::ios_base;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::fixed;

using std::vector;
using std::string;
using std::stack;
using std::queue;
using std::deque;
using std::map;
using std::set;
using std::unordered_map;
using std::unordered_set;

using std::tuple;
using std::make_tuple;
using std::pair;
using std::make_pair;

using std::sort;
using std::reverse;
using std::nth_element;

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

const int MAXN = 1000;
const int INF = 1e9;
const int MOD = 1e9+7;
const int64_t L_INF = 4e18;

int n;
string s[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

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

    int64_t ans = 0;
    for (int a = 0; a < n; a++) {
        bool flag = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int k1 = i + a;
                int k2 = j + a;
                if (k1 >= n)
                    k1 -= n;
                if (k2 >= n)
                    k2 -= n;

                flag &= s[k1][j] == s[k2][i];
            }
        }
        if (flag)
            ans += n;
    }

    cout << ans << '\n';
    #ifdef LOCAL
        cerr << "\n== " << 1.0 * clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>
using namespace std ;
int main()
{
    int r,c,m,n;
    cin >> r >> c ;
    m=max(r,c);
    cin >> n ;
    double d = (double)n/m;
    d=ceil(d);
    int x = (int)d ;
    cout << x << endl;
    return 0 ;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)

	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanln(&a[i])
	}

	fmt.Println(logic(a))
}

func logic(nums []int) int {
	m := make(map[int]int)
	for _, num := range nums {
		m[num]++
	}

	result := 0
	for _, v := range m {
		if v%2 != 0 {
			result++
		}
	}
	return result
}

Measured memory_bytes: 8960
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int H, N, A;
int ans;

int main(){
	cin >> H >> N;
	for (int i = 0; i < N; i++){
		cin >> A;
		ans += A;
	}

	if (ans > H){
		cout << "Yes" << endl;
	}
	else if (ans < H){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def cmb(n, r):
    if n - r < r: r = n - r
    if n <= 0: return 0
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p;
            for k in range(p-1,r,p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

a = int(input())

b = [0 for i in range(15)]
j = 0
c = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
d = [0 for i in range(101)]
p = 0
pp = 0
g = 0
gg = 0
ggg = 0
co = 0
for i in range(1,101):
  k = i
  while True:
    if k % c[j] == 0 and k >= c[j]:
      b[j] += 1
      k //= c[j]
    else:
      j += 1
      if j == 15:
        j = 0
        break
  for k in range(15):
    if b[k] >= 74:
      g += 1
    if b[k] >= 24:
      gg += 1
    if b[k] >= 14:
      ggg += 1
    if b[k] >= 4:
      p += 1
    if b[k] >= 2:
      pp += 1
  if i >= 10:
    d[i] = cmb(p, 2)*cmb((pp-2), 1) + cmb(g, 1) + cmb(gg, 1)*cmb((pp-1), 1) + cmb(ggg, 1)*cmb((p-1), 1)
  p = 0
  pp = 0
  g = 0
  gg = 0
  ggg = 0
print(d[a])


Measured memory_bytes: 3192
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,int> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int main()
{

  string s;
  cin>>s;
  int ans=12345;
  for(int i=0 ;i<s.size()-2 ; i++)
  {
      int d = stoi(s.substr(i,3));
      ans=min(ans,abs(d-753));
  }
  cout<<ans;
 go;
}


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

ll d[8][2] = {
    {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}
  };

int main(){
  ll h, w;
  cin >> h >> w;
  string arr[h];
  rep(i, h)cin >> arr[i];
  rep(i, h){
    rep(j, w){
      if(arr[i].at(j) == '.'){
        ll cnt = 0;
        rep(k, 8){
          if(0 <= i+d[k][0] && i+d[k][0] < h && 0 <= j+d[k][1] && j+d[k][1] < w &&
             arr[i+d[k][0]].at(j+d[k][1]) == '#')cnt++;
        }
        arr[i].at(j) = to_string(cnt)[0];
      }
    }
  }
  rep(i, h)cout << arr[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array

int main() {
	int n;
	cin >> n;
	int total=0;
	for (int i=1; i<n; i++) {
		for (int j=i; j<n; j+=i) {
			total++;
		}
	}
	cout << total;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()     //main method
{
    FIO;

       ll n,k;
       cin>>n>>k;
       ll arr[n+1];
       for(ll i=0;i<n;i++){
           cin>>arr[i];
       }
       sort(arr,arr+n);
      ll sum=0;

      for(ll i=0;i<n;i++){
          if(k>0){
              sum+=arr[i];
              k--;
          }
      }
      cout<<sum<<"\n";










    return 0;
}

Measured memory_bytes: 3588
N = int(input())
A_list = [int(_) for _ in input().split()]

c = 10**9+7


def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m


inv = modinv(2, c)

sum_of_a = sum(A_list) % c
sum_of_sq_a = sum([i**2 for i in A_list]) % c

ans = (sum_of_a**2 % c - sum_of_sq_a)*inv %c

print(ans)

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

int main(){
  int N,x;
  cin >> N;
  x = N;
  int fx = 0;
  
  while(x){
    fx += x % 10;
    x /= 10;
  }
  
  if( N % fx == 0 ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define sort(a, b) sort(((a) + 1), ((a) + (b) + 1))
#define ll long long
#define N 100010
using namespace std;

ll m, A, B, ans = INT_MAX, a[N], b[N];

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

inline void work(){
	A = read(), B = read(), m = read();			//长度为A的数列a，长度为B的数列B，进行m次减操作 
	REP(i, 1, A) a[i] = read();					//输入序列a 
	REP(i, 1, B) b[i] = read();					//输入序列b 
	REP(i, 1, m){								//依次枚举每个减去的操作 
		ll x = read(), y = read(), c = read();	//a[x]+b[y]-c
		ans = min(ans, a[x] + b[y] - c);		//记录最小值 
	}
	sort(a, A);									//从小到大排序序列a 
	sort(b, B);									//从小到大排序序列b
	printf("%lld\n", min(ans, a[1] + b[1]));	//输出ans和a[1]+b[1]的最小值 
}

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

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
  int n,m;
  cin >> n >> m;
  int mxl=0;
  int mnr=1000001;
  for(int j=0;j<m;j++){
    int l,r;
    cin >> l >> r;
    mxl=max(mxl,l);
    mnr=min(mnr,r);
  }
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(i>=mxl && i<=mnr)cnt++;
  }

cout << cnt << endl;

}

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


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

using namespace std;

int main(){
  int N, x = 0, max_x = 0;
  string S;

  cin >> N >> S;

  for(int i = 0; i < N; i++){
    if(S[i] == 'I') x++;
    else x--;
    if(max_x < x) max_x = x;
  }

  cout << max_x << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define INF 100000
#define Ma 101
#define NIL -6
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int G[Ma][Ma];
int n;
 
void prim(){
  int i,j;
  int d[Ma];
  int pi[Ma];
  int color[Ma];
  int min,u,v,sum=0;
 
  for(i=0;i<n;i++){
    d[i] = INF;
    pi[i] = NIL;
    color[i] = WHITE;
  }
 
  d[0] = 0;
 
  while(1){
    min = INF;
    u = NIL;
    for(i=0;i<n;i++){
      if(color[i] != BLACK && d[i] < min){
        min = d[i];
        u = i;
      }
    }
    if(u == NIL){
      break;
    }
    color[u] = BLACK;
    for(v=0;v<n;v++){
      if(color[v] != BLACK && G[u][v] != INF){
        if(d[v] > G[u][v]){
          d[v] = G[u][v];
          pi[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i] != NIL)sum += G[i][pi[i]];
  }
  printf("%d\n",sum);
}
 
int main(){
  int e;
  int i,j;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e == -1){
        G[i][j] = INF;
      }else{
        G[i][j] = e;
      }
    }
  }
 
  prim();
  return 0;
}



Measured memory_bytes: 2104
n = int(input())
p = list(map(int, input().split()))
p1 = p.copy()
p1.sort()
cnt = 0
for i in range(n):
  if p[i] != p1[i]:
    cnt += 1
    # print(i)
if cnt == 2 or cnt == 0:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<string> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];;
	}
	int x, y;
	int c = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (A[i][j] == '.') {
				c = 0;
				for (int ii = -1; ii <= 1; ii++) {
					for (int jj = -1; jj <= 1; jj++) {
						x = i + ii;
						y = j + jj;
						if (x >= 0 && x < N && y >= 0 && y < M) {
							if (A[x][y] == '#') {
								c++;
							}
						}
					}
				}
				A[i][j] = ('0' + c);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << A[i] << endl;
	}
}

Measured memory_bytes: 256