akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc138/tasks/abc138_d

import sys
input = sys.stdin.readline

def dfs(lst, start, ans):
    queue = [start]
    visited = [False] * len(ans)
    visited[start] = True

    while queue:
        parent = queue.pop()
        for child in lst[parent]:
            if visited[child]:
                continue
            visited[child] = True
            ans[child] += ans[parent]
            queue.append(child)

    print(*ans)

n,q = map(int, input().split())
start = 0

tree = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

ans = [0]*n
for _ in range(q):
    p, x = map(int,input().split())
    ans[p-1] += x
dfs(tree, start, ans)


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

int main() {
  int64_t n,x,t,a,ans,i;
	cin >> n;

 vector<int64_t> vec(n);


  for (i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
ans=0;
a=1;
for(i = 0; i < n; i++){
	if(a>vec.at(i)){
		ans=ans+a-vec.at(i);
	}
	else{
		a=vec.at(i);
	}
}
	cout << ans << endl;
}




Measured memory_bytes: 4840
N = int(input())
txy = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]
flag = True
for i in range(N):
    nt = txy[i+1][0]
    nx = txy[i+1][1]
    ny = txy[i+1][2]
    t = txy[i][0]
    x = txy[i][1]
    y = txy[i][2]
    move = nt - t
    tmp = abs(nx-x)+abs(ny-y)
    if move >= tmp:
        if abs(move-tmp) % 2 != 0:
            print('No')
            exit()
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 28092
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


int main() {
	int n; std::cin >> n;
	int prev = INT_MAX;
	int count = 0;
	for (auto i = 0; i < n; ++i) {
		int a; std::cin >> a;
		if (prev >= a) {
			++count;
		}
		prev = a;
	}
	std::cout << count << '\n' << n << std::endl;
}


Measured memory_bytes: 3116
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

#define id(i,j) ((i)*n+(j))
int f1[800111],f2[800111];
int gf(int x,int*f){return x==f[x]?x:f[x]=gf(f[x],f);}
void un(int x,int y,int*f){f[gf(x,f)]=gf(y,f);}

int n,d1,d2;

vector<pii>v1,v2;

int cnt[2][2],a[666][666],b[666][666];
int main()
{
	get3(n,d1,d2);n<<=1;
	for(int i=0;i<=n;i++)for(int j=-n;j<=n;j++)
	{
		if(i*i+j*j==d1)v1.pb(mp(i,j));
		if(i*i+j*j==d2)v2.pb(mp(i,j));
	}
	for(int i=0;i<n*n*2;i++)f1[i]=f2[i]=i;
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)
	{
		int ni,nj;
		for(auto&v:v1)
		{
			ni=i+v.ff;nj=j+v.ss;
			if(ni>=0&&ni<n&&nj>=0&&nj<n)
			{
				un(id(i,j)<<1,id(ni,nj)<<1|1,f1);
				un(id(i,j)<<1|1,id(ni,nj)<<1,f1);
			}
		}
		for(auto&v:v2)
		{
			ni=i+v.ff;nj=j+v.ss;
			if(ni>=0&&ni<n&&nj>=0&&nj<n)
			{
				un(id(i,j)<<1,id(ni,nj)<<1|1,f2);
				un(id(i,j)<<1|1,id(ni,nj)<<1,f2);
			}
		}
	}
	
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)
	{
		a[i][j]=gf(id(i,j)<<1,f1)&1;
		b[i][j]=gf(id(i,j)<<1,f2)&1;
		cnt[a[i][j]][b[i][j]]++;
	}
	int k=n*n/4;
	for(int k1=0;k1<2;k1++)for(int k2=0;k2<2;k2++)if(cnt[k1][k2]>=k)
	{
		for(int i=0;i<n&&k;i++)for(int j=0;j<n&&k;j++)if(a[i][j]==k1&&b[i][j]==k2)
		{
			printf("%d %d\n",i,j);
			k--;
		}
		break;
	}
	return 0;
}

Measured memory_bytes: 10240
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int arr[][]=new int[n][3];
		for(int i=0;i<n;i++){
			arr[i]=new int[3];
			for(int j=0;j<3;j++){
				arr[i][j]=sc.nextInt();
			}
		}
		int dp[]=new int[3];
		dp=arr[0];
		for(int i=1;i<n;i++){
			int m[]=new int[3];
			m[0]=Math.max(arr[i][0]+dp[1], arr[i][0]+dp[2]);
			m[1]=Math.max(arr[i][1]+dp[0],arr[i][1]+dp[2]);
			m[2]=Math.max(arr[i][2]+dp[0], arr[i][2]+dp[1]);
			dp=m;
		}
		System.out.println(Math.max(dp[0], Math.max(dp[1],dp[2])));
	}
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	string s;
	cin >> s;

	int sum = 0;
	for (auto x : s)
		sum += (x - '0');
	cout << (sum % 9 == 0 ? "Yes\n" : "No\n");

	return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
const int maxn=100+5;
int a[maxn];
bool c[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    if(n==1) {printf("1 1\n");exit(0);}
    memset(c,0,sizeof(c));
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>=3200) {cnt++;continue;}
        int tmp=0;int co=1;
        while(tmp<3200)
        {
            if(a[i]>=tmp && a[i]<=tmp+399) {c[co]=true;break;}
            co++;tmp+=400;
        }
    }
    int anocnt=0;
    for(int i=1;i<=8;i++) if(c[i]) anocnt++;
    if(anocnt==0) printf("1 %d\n",cnt);
    else printf("%d %d\n",anocnt,anocnt+cnt);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	string A,B;

	cin >> A >> B;

	if(A>B){
		printf(">\n");
	}else if(A<B){
		printf("<\n");
	}else{
		printf("=\n");
	}


	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	long long int n, m, ans, a, b, c;

	cin >> n >> m;

	if (m > 2 * n) {
		a = n * 2;//24690
		b = m - a;//654211
		c = b / 4;//163552
		ans = c + n;
		cout << ans << endl;
	}
	else if (m < 2 * n) {
		cout << m/2 << endl;
	}

	return 0;
}

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

int main() {
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int vx=x2-x1, vy=y2-y1;
int x3=x2-vy, y3=y2+vx;
int x4=x3-vx, y4=y3-vy;
cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

}


Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:isize,
    b:isize,
    c:isize,
    }
    println!("{}",if a+b>=c {"Yes" }else{"No"})
}

Measured memory_bytes: 2164
H,W = map(int,input().split())
lists = []
cnt = 0
for i in range(H):
    S = list(str(input()))
    lists.append(S)
for i in range(H):
    for j in range(W):
        if lists[i][j] == ".":
            lists[i][j] = 0
        elif lists[i][j] == "#":
            cnt += 1
if cnt == (H*W):
    for i in range(H):
        print("".join(lists[i]))
    exit()
for i in range(H):
    for j in range(W):
        if lists[i][j] == "#":
            if i > 0:
                if lists[i-1][j] != "#":
                    lists[i-1][j] += 1
            if j > 0:
                if lists[i][j - 1] != "#":
                    lists[i][j-1] += 1
            if i < H and i != (H-1):
                if lists[i+1][j] != "#":
                    lists[i+1][j] += 1
            if j < W and j != (W-1):
                if lists[i][j+1] != "#":
                    lists[i][j+1] += 1
            if i > 0 and j < W and j != (W-1):
                if lists[i-1][j+1] != "#":
                    lists[i-1][j+1] += 1
            if j > 0 and i < H and i != (H-1):
                if lists[i+1][j-1] != "#":
                    lists[i+1][j-1] += 1
            if i > 0 and j > 0:
                if lists[i-1][j-1] != "#":
                    lists[i-1][j-1] += 1
            if i < H and j <W and j != (W-1) and i != (H-1):
                if lists[i+1][j+1] != "#":
                    lists[i+1][j+1] += 1
str_list = []
for i in range(H):
    m = map(str,lists[i])
    mojiretsu = "".join(m)
    print(mojiretsu)

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    
    VB canSugar(f+1, false), canWater(f+1, false);
    
    FOR(cntA,0,f) FOR(cntB,0,f) {
        ll totalWater = 100 * (cntA * a + cntB * b);
        if (totalWater <= f) {
            canWater[totalWater] = true;
        }
    }
    
    FOR(cntC,0,f) FOR(cntD,0,f) {
        ll totalSugar = cntC * c + cntD * d;
        if (totalSugar <= f) {
            canSugar[totalSugar] = true;
        }
    }
    
    ll bestX = 0;
    ll bestY = 1;
    ll bestSugar = 0, bestWater = 100 * a;
    
    FOR(sugar,0,f) FOR(water,0,f-sugar) {
        if (canSugar[sugar] && canWater[water] && (water / 100) * e >= sugar) {
            ll x = sugar;
            ll y = sugar + water;
            
            if (x * bestY > bestX * y) {
                bestX = x;
                bestY = y;
                
                bestSugar = sugar;
                bestWater = water;
            }
        }
    }
    
    cout << bestSugar + bestWater << ' ' << bestSugar;
    
    return 0;
}

/*************************************************************************/


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

int main(){
  int n,k;
  cin >> n >> k;
  int p[n];
  rep(i,n)cin >> p[i];

  sort(p,p+n);
  int ans=0;
  rep(i,k)ans+=p[i];
  cout <<  ans << endl;
}

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


int main() {
int N,K,X,Y;
cin >> N >> K >> X >> Y;
int ans = 0;
if (N <= K) {
    ans += N*X;
} else {
    ans += K*X;
    ans += (N-K) * Y;
}
cout << ans << endl;


return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 10 ** 9 + 7

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

D = 2000

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

fact,fact_inv = make_fact(10 ** 4,MOD)
fact = fact.tolist()
fact_inv = fact_inv.tolist()

C_to_A = [[] for _ in range(D+D+1)]
remove = 0
for a,b in AB:
    c = a+b
    C_to_A[c].append(D-a)
    remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b]
remove %= MOD

dp = np.zeros(D+D+1,np.int64)
for A in C_to_A[::-1]:
    dp[1:] += dp[:-1].copy()
    np.add.at(dp,A,1)
    dp %= MOD

x = (dp * dp[::-1] % MOD).sum() % MOD
x -= remove
if x&1:
    x += MOD
x //= 2
x %= MOD

print(x)

Measured memory_bytes: 40384
from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    dist = [[-1] * w for _ in range(h)]  # 前処理
    que = deque()
    for i, Si in enumerate(S):
        for j, Sij in enumerate(Si):
            if Sij == '#':
                dist[i][j] = 0
                que.append((i, j))

    while len(que) > 0:
        (x, y) = que.popleft()
        near = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
        for i, j in near:  # 移動先の候補
            if 0 <= i < h and 0 <= j < w and dist[i][j] < 0:
                dist[i][j] = dist[x][y] + 1
                que.append((i, j))
    return max(max(ans) for ans in dist)


h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(bfs(a))


Measured memory_bytes: 116016
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,K;
int a[MAXN];
void Solve() {
    read(K);read(N);
    if(K % 2 == 0) {
        out(K / 2);space;
        for(int i = 2 ; i <= N ; ++i) {
            out(K);space;
        }
        enter;
    }
    else {
        for(int i = 1 ; i <= N ; ++i) a[i] = (K + 1) / 2;
        int t = N / 2;
        int p = N;
        while(t--) {
            --a[p];
            if(a[p] != 0) {
                for(int i = p + 1 ; i <= N ; i++) a[i] = K;
                p = N;
            }
            if(a[p] == 0) --p;
        }
        for(int i = 1 ; i <= N ; ++i) {
            if(a[i] != 0) {
                out(a[i]);space;
            }
        }
        enter;
    }

}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>

using namespace std;

int main(){

    int pattern = 0;

    int a, b, c, x;
    cin >> a >> b >> c >> x;


    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                int total = 500*i + 100*j + 50*k;
                if (total == x) ++pattern;
            }
        }
    }



    cout << pattern << 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;
typedef long long ll;
typedef pair<int, int> P;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	int ans = 0;
	rep(i, n - 1) {
		for (int j = i + 1; j < n; ++j) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日  9/ 9 16:19:42 2018

# Usage
#
"""
def get_input():
    height, width = (int(i) for i in input().split(' '))

    target = [[int(w) for w in input().split(" ")] for h in range(height)]
    size = [height, width]

    return size, target

def oshituke(size, target):
    """
    >>> oshituke([2, 3], [[1,2,3],[0,1,1]])
    """
    res = []
    for h in range(size[0]):
        for w in range(size[1]):
            if target[h][w] % 2 == 1:
                mode = checker(size, h, w)
                if mode == "b":
                    target[h][w] -= 1
                    target[h+1][w] += 1
                    res.append(' '.join([str(i) for i in [h+1, w+1, h+2, w+1]]))
                elif mode == "l":
                    target[h][w] -= 1
                    target[h][w+1] += 1
                    res.append(' '.join([str(i) for i in [h+1, w+1, h+1, w+2]]))

    print(len(res))
    _ = [print(i) for i in res]
    return


def checker(size, now_height, now_width):
    if now_height + 1 < size[0]:
        return "b"
    elif now_width + 1 < size[1]:
        return "l"
    return None

if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    size, target = get_input()
    oshituke(size, target)


Measured memory_bytes: 17244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC017
{
    class ModerateDifferences
    {
        public static void Main()
        {
            var nabcd = ReadLine().Trim().Split(' ').Select(_ => long.Parse(_)).ToArray();
            var n = nabcd[0]; var a = nabcd[1]; var b = nabcd[2]; var c = nabcd[3]; var d = nabcd[4];
            var yes = "YES"; var no = "NO";
            var option = BinSearch(_ =>
           {
               return new Range(a + c * _ - d * (n - _ - 1), a + d * _ - c * (n - _  - 1)).CompareTo(b);
           }, 0, n);
            if (option.HasValue) {
                WriteLine(yes);
            }
            else {
                WriteLine(no);
            }
            /*
            for (var i = 0; i <= n; ++i) {
                if (a + c * i - d * (n - i - 1) <= b && b <= a + d * i - c * (n - i - 1)) {
                    WriteLine(yes);
                    return;
                }
            }
            WriteLine(no);
            */
        }
        static Option<long> BinSearch(Func<long, Compare> func, long left, long right)

        {
            if (left >= right) return func(left) == Compare.Contain ? Option<long>.Just(left) : Option<long>.None();
            else {
                var mid = (left + right) / 2;
                if (func(mid) != Compare.Larger) {
                    return BinSearch(func, left, mid);
                }
                else {
                    return BinSearch(func, mid + 1, right);
                }
            }
        }
        class Option<T>
        {
            public T Value { get; private set; }
            public bool HasValue { get; private set; }
            public static Option<T> Just(T val)
            {
                return new Option<T> { Value = val, HasValue = true };
            }
            public static Option<T> None()
            {
                return new Option<T> { HasValue = false };
            }
        }
        enum Compare
        {
            Larger, Smaller, Contain
        }
        struct Range
        {
            public Range(long from, long to)
            {
                From = from; To = to;
            }
            public long From { get; private set; }
            public long To { get; private set; }
            public Compare CompareTo(long other)
            {
                if (other < From) return Compare.Smaller;
                else if (other > To) return Compare.Larger;
                else return Compare.Contain;
            }
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


vi to[10];
int ans =0;
int n,m;

bool used[10];
void dfs(int v, int len=1) {
  if (len == n) {
    // TODO:
    ans++;
    return;
  }
  for (int u: to[v]) {
    if (used[u]) continue;
    used[u] = true;
    dfs(u, len+1);
    used[u] = false;
  }
}
int main() {
  cin >> n >> m;
  
  rep(i,m) {
  int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  used[0]=true;
  dfs(0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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; }
// template end


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    in >> n;
    out << "ABC" << n << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }

    int h = 0;
    LL head = A[h];
    int t = N-1;
    LL tail = A[t];

    while (h+1 < t) {
        if (head < tail) {
            ++h;
            head += A[h];
        } else {
            --t;
            tail += A[t];
        }
    }

    cout << abs(head - tail) << endl;

    return 0;
}


Measured memory_bytes: 1024
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  double a[105]={},cnt=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    cnt+=1/a[i];
  }
  cout << fixed << setprecision(10) << 1/cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
template <class T>
using ll = long long;
using ull = unsigned long long;

vector<int> v;

int main() {
    FAST;

    int n, m;
    cin >> n >> m;
    float volt = 1.0 / (4.0 * m);
    float sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        sum += a;
        v.push_back(a);
    }

    float b = sum * volt;

    sort(all(v), [](int l, int r){
        return l > r;
    });


    rep(i, m){
        if(v[i] < b){
            println("No");
            stop;
        }
    }

    println("Yes");
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
using namespace std;
#define ll long long
const int maxn = 100005;
int gcd(int x,int y){
	if(y==0)
		return x;
	else return gcd(y,x%y);
}

char s1[maxn],s2[maxn];
int p1[maxn],p2[maxn];
map<ll,char> mp;
int main(){
	ll n,m;
	cin >> n >> m;
	ll t = gcd(n, m);
	ll ans = n*m/t;
	scanf("%s %s",s1,s2);
	if(s1[0]!=s2[0]){
		printf("-1\n");
		return 0;
	}
	long long f = ans/n;
	for(int i=1; i<n; i++){
		mp[f] = s1[i];
		f+=(ans/n);
	}
	f = ans/m;
	bool flag = true;
	for(int i=1; i<m; i++){
		if(mp.find(f)!=mp.end()&&s2[i]!=mp[f]){
			flag=false;
			break;
		}
		else {
			mp[f] = s2[i];
			f += (ans/m);
		}
	}
	if(flag)
		printf("%lld\n",ans);
	else printf("-1\n"); 
} 


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a,b,r;
  cin >> a;
  for(int i=1;i<n;i++){
    cin >> b;
    if(a < b)swap(a,b);
    r = a % b;
    while(r > 0){
      a = b;
      b = r;
      r = a % b;
    }
    a = b;
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

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

	if (x == 1 || x == 2 * n -1) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	deque<int> ans;
	ans.push_back(x);
	for (int i = 1; i < min(x,n); i++) {
		ans.push_front(i);
		
	}

	for (int i = 2 *n-1; i > max(x, n); i--) {
		ans.push_back(i);

	}

	if (x < n) {
		for (int i = x + 1; i <= n; i++) {
			ans.push_front(i);
		}
	}

	if (x > n) {
		for (int i = n; i <= x -1; i++) {
			ans.push_back(i);
		}
	}

	while (!ans.empty()) {
		cout << ans.front()<< " " << endl;
		ans.pop_front();
	}

}

Measured memory_bytes: 4340
import sys, math
from functools import lru_cache
import datetime
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    p = list(mi())
    cnt = 0
    for i in range(N):
        if p[i] == i+1:
            if i == N-1:
                p[i-1], p[i] = p[i], p[i-1]
            else:
                p[i], p[i+1] = p[i+1], p[i]
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20992
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string a;
            a = Console.ReadLine(); //標準入力
            int anser = 0;
            foreach (char c in a)
            {
                if (c == '+') anser++;
                if (c == '-') anser--;
            }

            Console.WriteLine(anser);

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using lint=long long;
lint mod=998244353;
void add_eq(lint&x,lint y){x+=y;if(mod<=x)x-=mod;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,X;std::cin>>n>>X;
    std::vector<std::vector<lint>>binom(n+X+1,std::vector<lint>(n+X+1));
    binom.at(0).at(0)=1;
    for(lint i=0;i<n+X;i++){
        for(lint j=0;j<=i;j++){
            add_eq(binom.at(i+1).at(j),binom.at(i).at(j));
            add_eq(binom.at(i+1).at(j+1),binom.at(i).at(j));
        }
    }
    lint max=1;while(max<=X)max<<=1;
    std::vector<std::vector<lint>>dp(n+1,std::vector<lint>(max));
    dp.at(0).at(0)=1;
    for(lint i=0;i<=X;i++){
        for(lint j=n-1;j>=0;j--){
            for(lint k=0;k<max;k++){
                add_eq(dp.at(j+1).at(k^i),dp.at(j).at(k));
            }
        }
    }
    lint ans=0;
    for(lint i=0;2*i<=n;i++){
        add_eq(ans,dp.at(n-2*i).at(X)*binom.at(i+X).at(i)%mod);
    }
    std::cout<<ans<<'\n';
}



Measured memory_bytes: 12760
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A < B:
  if A + V * T < B + W * T:
    print('NO')
  else:
    print('YES')
else:
  if A - V * T > B - W * T:
    print('NO')
  else:
    print('YES')


Measured memory_bytes: 9176
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  a = map(parseInt, readline() |> collect)

  for b in 0:7
    x = a[1]
    for i in 1:3
      x += (b & 1<<(i - 1) != 0 ? 1 : -1) * a[i + 1]
    end
    if x == 7
      for i in 1:3
        print(a[i])
        print(b & 1<<(i - 1) != 0 ? "+" : "-")
      end
      print(a[4])
      println("=7")
      return
    end
  end
end

main()


Measured memory_bytes: 164520
import sys
import math

def get_degit(n):
    return int(math.log10(n) + 1)

def solve(n):
    ans = 100

    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            a = n / i
            b = n / a
            k = max(get_degit(a), get_degit(b))
            if k < ans:
                ans = k

    return ans

def main():
    n = int(sys.stdin.readline())
    ans = solve(n)

    print(ans)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3064
N, M = map(int, input().split())
PS = [input().split() for _ in range(M)]
Pena = [0] * (N+1)
pena = 0
ac = 0
for p, s in PS:
    p = int(p)
    if s == "AC":
        if Pena[p] >= 0:
            ac += 1
            pena += Pena[p]
            Pena[p] = -999999999
    else:
        Pena[p] += 1
print(ac, pena)


Measured memory_bytes: 38932
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn solve(s: &Vec<char>) -> bool {
    if s[0] != 'A' {
        return false;
    }

    let mut cnt = 0;
    for i in 2..s.len() - 1 {
        if s[i] == 'C' {
            cnt += 1;
        }
    }
    if cnt != 1 {
        return false;
    }

    let mut cap = 0;
    for c in s {
        if c.is_uppercase() {
            cap += 1;
        }
    }
    cap == 2
}

fn main() {
    input! {
        s: String,
    }

    if solve(&s.chars().collect()) {
        println!("AC");
    } else {
        println!("WA");
    }
}


Measured memory_bytes: 2144
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int main(){
	int W,H,n;
	cin>>W>>H>>n;
	int area[H][W],ans=0;
	int x[n],y[n],a[n];
	for(int i=0;i<n;i++){
		x[i]=0;
		y[i]=0;
		a[i]=0;
	}
	for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>a[i];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			area[i][j] = 0;
		}
	}

	for(int i=0;i<n;i++){
		if(a[i] == 1){
			for(int j=0;j<H;j++){
				for(int k=0;k<x[i];k++){
					area[j][k] = 1;
				}
			}
		}
		if(a[i] == 2){
			for(int j=0;j<H;j++){
				for(int k=x[i];k<W;k++){
					area[j][k] = 1;
				}
			}
		}
		if(a[i] == 3){
			for(int j=0;j<y[i];j++){
				for(int k=0;k<W;k++){
					area[j][k] = 1;
				}
			}
		}
		if(a[i] == 4){
			for(int j=y[i];j<H;j++){
				for(int k=0;k<W;k++){
					area[j][k] = 1;
				}
			}
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(area[i][j] == 0)ans++;
		}
	}

	cout<< ans <<endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

# C - Lower
n = int(input())
h = list(map(int, input().split()))
count = 0
ans = 0

for i in range(n - 1):
	if h[i] >= h[i + 1]:
		count += 1
	else:
		count = 0

	ans = max(ans, count)

print(ans)

Measured memory_bytes: 14168
#include <stdio.h>

#define N 8
#define SAT 1
#define FREE -1

 
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int X[N][N];
 

 
void show(){
  int i, j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
        if(row[i] != j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j){
        printf("Q");
      }else{ 
        printf(".");
      }
    }
    printf("\n");
  }
}
 
void recursive(int i){
  int j;
  if(i == N){
    show();
    return;
  }
  for(j=0;j<N;j++){
    if(SAT == col[j] || SAT == dpos[i+j] || SAT == dneg[i-j+N-1] ) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = SAT;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}
 
int main(){
  int i,j,k,r,c;
  
  for( i = 0 ; i < N ; i++ ){
    row[i] = FREE;
    col[i] = FREE;
  }
  for( i = 0 ; i < 2*N-1 ; i++ ){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++) X[i][j] = false;
  }
 
  scanf("%d",&k);
   
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }
 
  recursive(0);
 
  return 0;
}





Measured memory_bytes: 2688
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 10**9 + 7

n = ri()
ls = ril()
counter = collections.defaultdict(int)
for a in ls:
    i = 0
    while a > 0:
        if a % 2 == 1:
            counter[i] += 1
        a //= 2
        i += 1
res = 0
for k, v in counter.items():
    res += (n - v) * v * 2**k % MOD
    res %= MOD
print(res)

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,x;
    cin >> a >> b >> x;

    if( x <= a + b && x >= a ){ cout << "YES" << endl;}

    else{ cout << "NO" << endl;}



    return 0;
}


Measured memory_bytes: 256
words = lambda t : list(map(t, input().split()))
l,r = words(int)

ml = l % 2019
mr = r % 2019

if ml >= mr or r - l >= 2019:
    print(0)
else:
    mi = (ml * (ml+1)) % 2019
    for i in range(ml,mr):
        for j in range(i+1, mr+1):
            #print(i,j,i*j,(i*j)%2019)
            mi = min(mi, (i*j) % 2019)
    print(mi)


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


class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n
        self.count = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
            self.count[i] += self.count[j]
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)
            self.count[j] += self.count[i]


uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    uf.merge(a-1, b-1)
print(uf.parent.count(-1)-1)


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

vector<int> nums;

void productExceptSelf(vector<int>& nums) {
        
        int n = nums.size();
        vector<int> output;
        
        int product = 0;
        for(int i=0;i<n;++i)
        {
            product ^= nums[i];
            output.push_back(product);            
        }
        
        //Traverse from right and update output array
        product = 0;
        for(int i=n-1;i>0;i--)
        {
            output[i] = output[i-1]^product;
            product ^= nums[i];
        }
        output[0] = product;
        
        for(vector<int>::iterator it=output.begin();it!=output.end();it++){
        	cout<<*(it)<<" ";
		}
		cout<<"\n";
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int tt; cin>>tt;
	    nums.push_back(tt);	
	}
	productExceptSelf(nums);
	return 0;
}

Measured memory_bytes: 5520
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int a,b,c,d; cin>>a>>b>>c>>d;
    if (abs(a-c) <= d)
    {
        cout << "Yes\n";
        return 0;
    } else if (abs(a-b) <= d && abs(b-c) <= d)
    {
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
    return 0;
}

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

using namespace std;

using ll = long long;


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	string s;

	cin >> s;

	cout << (count (s.begin (), s.end (), 'x') < 8 ? "YES" : "NO") << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4) << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	cout << setprecision(20);

	solve();
#endif

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long  N, K,ans,num;
	cin >> N >> K;
	if (K == 2) {
		long even = N / 2;
		long odd = N - even;
		long evengroup = even*even*even;
		long oddgroup = odd*odd*odd;
		ans = evengroup + oddgroup;
	}
	else if(K % 2 != 0){
		num = N / K;
		ans = num*num*num;
	}
	else if (K % 2 == 0) {
		long K2 = K / 2;
		num = N / K;
		long num2 = N / K2 - num; //○.5*K の形
		ans = num*num*num + num2*num2*num2;
	}
 
 
	cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define lol long long
#define in(n,s) insert(n,s)//ノート参照
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int gcd(int x,int y){//最大公約数
  if(y>x) swap(x,y);
  int r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  return y;
}
int Lcm(int x,int y){//最小公倍数
  int t=x*y;
  return t/gcd(x,y);
}
priority_queue<int> i[300000];
bool ii[111][111];
lol a,b,c,d,g,h;
bool can(int n,int m){
  if(n<0) return false;
  if(m<0) return false;
  if(n>=a) return false;
  if(m>=b) return false;
  return true;
}
int dfs(int n,int m){
  if(n==g&&m==h) return true;
  //if(i[n][m]!=i[c][d]||!can(n,m)||ii[n][m]) return false;
  ii[n][m]=true;
  return dfs(n+1,m)+dfs(n,m+1)+dfs(n-1,m)+dfs(n,m-1);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long e=0,f=0,j=1,u;
  string w,p;
  cin >>a;
  for(int n=1;n<=sqrt(a);n++){
    if(a%n==0) j=n;
  }
  cout <<j+a/j-2<<'\n';
  return (0);
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> coord;
coord L[1000000];
int main(){
    ll n,m;
    cin >> n >> m;
    for(ll i=0; i<m; i++){
        ll tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        L[i] = make_pair(tmp1,tmp2);
    }

    ll left=L[0].first, right=L[0].second;

    for(ll i=1; i<m; i++){
        if( left < L[i].first) left = L[i].first;
        if( right > L[i].second) right = L[i].second;
    }

    if( left > right ) cout << 0 << endl;
    else cout << right-left+1 <<endl;

    return 0;
}


Measured memory_bytes: 1792
//To debug :  g++ -g file.cpp -o code
//cout<<setprecision(p)<<fixed<<var
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807;
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000;
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
 

 

ll dp[101][100001];
ll ps[101][100001];
ll a[101];

int main()
{

	memset(ps,0,sizeof(ps));
	memset(dp,0,sizeof(dp));

	int i,j,n,k;
	ll sum = 0;

	cin>>n>>k;

	rep(i,1,n+1)
		cin>>a[i];

	//Let start from Last person

	for(i=0;i<=k;++i)
	{
		if(i<=a[n])
			dp[n][i]=1;

		if(i==0)
			ps[n][i]=1;
		else
			ps[n][i] = (dp[n][i] + ps[n][i-1])%mod;

		//cout<<dp[n][i]<<" "<<n<<" "<<i<<" "<<ps[n][i]<<"\n";

	}

	//Now from second last person

	for(i=(n-1);i>=1;--i)
	{

		//This person can take fro 0 to a[i] candies. If k greater than a[i] then zero candies

		for(j=0;j<=k;++j)
		{

			if((j-a[i]-1)<0)
				dp[i][j] = ps[i+1][j];
			else
				dp[i][j]  =  (ps[i+1][j] - ps[i+1][j-a[i]-1])%mod ; //But wait (j-1-i can be negative)


			if(dp[i][j] < 0)
				dp[i][j]+=mod;

			if(j==0)
				ps[i][j] = dp[i][j];
			else
				ps[i][j] = (dp[i][j] + ps[i][j-1])%mod ;

			//cout<<dp[i][j]<<" "<<i<<" "<<j<<"\n";

		}

	}


	cout<<dp[1][k]<<"\n";




	return 0;
}

Measured memory_bytes: 158080
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    string S, T; cin >> S >> T;
    int S_len = S.size();
    int T_len = T.size();

    int ans = INF;
    rep(i,S_len-T_len+1) {
        int tmp = 0;
        rep(j,T_len) {
            if (S[i+j] != T[j]) ++tmp;
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;


    return 0;
}





Measured memory_bytes: 3532
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include <cstdlib>
#include <stdlib.h>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define MOD 1000000007
using namespace std;
using ll=long long;
int cnt,element;
int main()
{
    int n,k,snu,sna,i,j,rafi;
    cin>>n>>k;
    set<int>s;
    for(int i=0;i<k;i++)
    {
        cin>>snu;
        for(int j=0;j<snu;j++)
        {
            cin>>sna;
            s.insert(sna);
        }
    }
    int len=s.size();
    cout<<n-len<<endl;
    return 0;
}


Measured memory_bytes: 3636
import itertools
n,m,q = map(int,input().split())
abcd = [tuple(map(int,input().split())) for _ in range(q)]

l = set(range(1,m+1))
h = itertools.combinations_with_replacement(l, n)

ans = 0
for i in h:
    tmp = 0
    for (a,b,c,d) in abcd:
        if(i[b-1]-i[a-1] == c):
            tmp += d
    ans = max(ans,tmp)

print(ans)

Measured memory_bytes: 9208