akhauriyash/Code-Regression huggingface dataset:
N, C = map(int, input().split())
xv = [list(map(int, input().split())) for _ in range(N)]

R1 = [0]*N
R2 = [0]*N
L1 = [0]*N
L2 = [0]*N

cal = 0
ans1 = 0
ans2 = 0
for i, (x, v) in enumerate(xv):
    cal += v
    ans1 = max(ans1, cal-x)
    ans2 = max(ans2, cal-2*x)
    R1[i] = ans1
    R2[i] = ans2


cal = 0
ans1 = 0
ans2 = 0
for i, (x, v) in enumerate(xv[::-1]):
    x = C-x
    cal += v
    ans1 = max(ans1, cal-x)
    ans2 = max(ans2, cal-2*x)
    L1[-1-i] = ans1
    L2[-1-i] = ans2

ans = 0

for i in range(N-1):
    ans = max(ans, R2[i]+L1[i+1], R1[i]+L2[i+1])

ans = max(ans, R1[-1], L1[0])
print(ans)


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

bool is_circular(string S){
  string rev = S;
  reverse(rev.begin(), rev.end());
  if(S == rev)
    return true;
  else
    return false;
}
int main(){
  string S;
  cin >> S;
  int N = S.size();
  if(is_circular(S) && is_circular(S.substr(0, (N / 2))) && is_circular(S.substr((N + 1) / 2)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++){
        cin >> a[i];
    }

    for (int i = 0; i < h+2; i++){
        if (i == 0 || i == h+1){
            for (int j = 0; j < w+2; j++){
                cout << '#';
            }
            cout << endl;
        }else{
            cout << '#';
            cout << a[i-1];
            cout << '#' << endl;
        }
    }
}

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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
    int n;
    cin >> n;
    int b[n-1];
    long long int sum=0;
    for(int i=0;i<n-1;i++){
        cin >> b[i];
    }

    for(int i=0;i<n;i++){ 
        if(i==0){
            sum+=b[i];
        }
        else if(i==n-1){
            sum+=b[n-2];
        }
        else{
            sum+=min(b[i-1],b[i]);
        }
        
    }

    cout << sum;

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a,b,c,d,r,g,temp;
  while(scanf("%d %d",&a,&b)!=EOF){
  if(a<b){
    temp=a;
    a=b;
    b=temp;
  }
  c=a;
  d=b;
  while( b != 0 ) {
    temp = a%b;
    a = b;
    b = temp;
  }
  r=c*(d/a);
  printf("%d %d\n",a,r);
  }
  return 0;
}

Measured memory_bytes: 0
N=int(input())
#単純グラフ：ループも多重辺もない
#連結：成分が1

ans=[]
if N%2==0:
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if j!= (N-i+1):
                ans.append([i,j])

else:
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if j!=(N-i):
                ans.append([i,j])

print(len(ans))
for i, j in ans:
    print(i,j)

Measured memory_bytes: 4124
def main():
    n = int(input())

    min = int(input())
    ans = -2 * int(1e9+1)

    for _ in range(n-1):
        x = int(input())
        if x - min > ans:
            ans = x - min

        if x < min:
            min = x

    print(ans)

main()


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
int main() {
    int N, p[100];
    cin >> N;
    rep(i, N){
        cin >> p[i];
    }
    int cnt = 0;
    rep(i, N){
        if(p[i] != i+1){
            cnt++;
        }
    }
    if(cnt <= 2)cout << "YES";
    else cout << "NO";
}

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

int main(){
  long long int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  vector<int> b(0);
  vector<int> kanri(n,-1);
  int y=0;//現在地-1
  
  while(kanri.at(y)==-1){
    kanri.at(y)=b.size();
    if (b.size() == k) { cout << y+1 << endl; return 0; }
    b.push_back(y+1);
    y=a.at(y)-1;
  }
  y=kanri.at(y);//yは例外の数
  
  cout << b.at((k-y)%(b.size()-y)+y) << endl;
  
}


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

int main(){

int c,ans=0,calc=0;
while (scanf("%1d[^\n]", &c)!=EOF)
{
  calc += c;
  if ((calc%9)!=0)
  {
    ans = 1;
  } else{
    ans = 0;
  }
  
}

ans > 0 ? puts("No") : puts("Yes");

return 0;

}

Measured memory_bytes: 1616
"""
E.
"""
from functools import reduce
from collections import deque


def prod(x, y):
    return x * y % MOD

    
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
# abs_a_list = sorted(a_list, key=abs, reverse=True)
MOD = 10**9 + 7

if K%2 == 1:
    flg = True
    for a in a_list:
        if a >= 0:
            flg = False
            break
    if flg:
        print(reduce(prod, a_list[:K]))
        exit()

S = []
a_list = deque(a_list)
i = 0
while i < K:
    if len(a_list)>=2:
        if a_list[0]*a_list[1] >= a_list[-1]*a_list[-2]:
            S.append(a_list.popleft())
            i += 1
        elif a_list[0]*a_list[1] < a_list[-1]*a_list[-2] and i <= K-2:
            S.append(a_list.pop())
            S.append(a_list.pop())
            i += 2
        else:
            S.append(a_list.popleft())
            i += 1
    else:
        S.append(a_list.popleft())
        i += 1
        
ans = reduce(prod, S)
print(ans)

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int count = 0;
		int n = sc.nextInt();
		int[] S = new int[n];
		for(int i = 0; i < n; i++) {
			S[i] = sc.nextInt(); 
		}
		int q = sc.nextInt();
		int[] T = new int[q];
		for(int i = 0; i < q; i++) {
			T[i] = sc.nextInt();
		}
		
		for(int j = 0; j < q; j++) {
			for(int i = 0; i < n; i++) {
				if(S[i] == T[j]) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 40208
SA = input()
SB = input()
SC = input()
A = 0
B = 0
C = 0
flag = 'a'
while True:
    if flag == 'a':
        if A == len(SA):
            print('A')
            break
        flag = SA[A]
        A += 1
    elif flag == 'b':
        if B == len(SB):
            print('B')
            break
        flag = SB[B]
        B += 1
    else:
        if C == len(SC):
            print('C')
            break
        flag = SC[C]
        C += 1

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

class unionfind {
    std::vector<int> parents;
    std::vector<int> sizes;
    public:
        unionfind(int n) : parents(n), sizes(n, 1) {
            iota(begin(parents), end(parents), 0);
        }
        int root(int x) {
            if (parents[x] == x)
                return x;
            else
                return parents[x] = root(parents[x]);
        }
        bool is_same(int x, int y) {
            return root(x) == root(y);
        }
        void unite(int x, int y) {
            int rx = root(x);
            int ry = root(y);
            if (rx == ry)
                return;
            parents[rx] = ry;
            sizes[ry] += sizes[rx];
            sizes[rx] = 0;
        }
        // root size
        int size(int x) {
            return sizes[x];
        }
};

int main() {
    fastio;
    ll ans=0;
    ll N,M;
    cin >> N >> M;
    unionfind uf(N);
    rep(i,M) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        uf.unite(a,b);
    }
    set<int> g;
    rep(i,N) {
        g.insert(uf.root(i));
    }
    ans = g.size() - 1;
    cout << ans << endl;
}


Measured memory_bytes: 7896
#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define ll long long
#define f first
#define se second
#define pb push_back
using namespace std;
typedef vector<long long int> vec;
// ll md=1e9+7;
// ll MAX=1e18;
//strtobin(char *s,int *a){ int w; FORE(w,0,strlen(s)){a[w]=s[w]-'0'};}
// ll power(ll x,ll y,ll p)
// {   if (y == 0)
//         return 1;
//     else if (y % 2 == 0)
//         return ((power(x,y / 2,p)%p) * (power(x, y / 2,p)%p))%p;
//     else
//         return (x * ((power(x,y / 2,p)%p) * (power(x,y / 2,p))%p))%p;
// }
// ll ce(ll x,ll y)
// { if(x%y==0)
// 	{
//        return (x/y);
// 	}else{
// 		return (x/y)+1;
// 	}
 
// }
int main()
{

	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
ll n,m,i;
cin>>n>>m;
if(n==1&&m==0)
{
  cout<<"0"<<endl;return 0;
}
vector<ll>v(n+1);
for(i=1;i<=n;i++)
{ v[i]=-1;

}ll x,y;
while(m--)
{ cin>>x>>y;

  
   if(v[x]==-1){v[x]=y;}else{
     if(v[x]==y)
     {
      continue;
     }else{
      cout<<"-1"<<endl;return 0;
     }
   }
}
for(i=1;i<=n;i++)
{
  if(i==1)
  {
    if(v[i]==-1)
    {
      v[i]=1;
    }else if(v[i]==0)
    {
      if(n!=1){cout<<"-1"<<endl;return 0;}else if(n==1){cout<<"0"<<endl;return 0;}
    }
  }else{
    if(v[i]==-1)
    {
      v[i]=0;
    }
  }
}
for(i=1;i<=n;i++)
{
  cout<<v[i];
}
cout<<endl;




return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++){
    int num1, num2;
    num1 = i % 10;
    if(i/10000 != num1){
      continue;
    }
    num2 = i - num1 * 10000;
    num2 /= 10;
    num1 = num2 % 10;
    if(num2/100 != num1){
      continue;
    }
    ans++;
  }
  cout << ans << endl;
}

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

const int N = 5010;
typedef long long ll;

int n, m;
int a[N], v[N], f[N][N];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i) {
		int lim = 0;
		scanf("%d%d", &a[i], &lim);
		for(int x, j = 1; j <= lim; ++j) {
			scanf("%d", &x);
			--x; v[i] |= 1 << x;
		}
	}
	memset(f, 0x3f, sizeof(f));
	f[0][0] = 0;
	for(int i = 1; i <= m; ++i) {
		for(int j = 0; j < (1 << n); ++j) {
			f[i][j] = min(f[i][j], f[i - 1][j]);
			f[i][j | v[i]] = min(f[i][j | v[i]], f[i][j] + a[i]);
		}
	}
	if(f[m][(1 << n) - 1] == 0x3f3f3f3f) puts("-1");
	else printf("%d\n", f[m][(1 << n) - 1]);
}

Measured memory_bytes: 98432
def f():
  a = list(map(float,input().split()))

  for i in range(0, 1251):
    if i >= a[0]/0.08 and i < (a[0]+1)/0.08 and i >= a[1]/0.1 and i < (a[1]+1)/0.1:
      print(i)
      return

  print(-1)

f()

Measured memory_bytes: 2940
N, M, K =map(int,input().split())
bases = list(map(int,input().split()))
ans=0

for i in range(N):
  a= list(map(int,input().split()))
  tmp=0
  for j in range(M):
    tmp+= bases[j]*a[j]
  
  if tmp+K>0:
    ans+=1
    
print(ans)


Measured memory_bytes: 3060
program select_half
  implicit none
  integer(8), parameter :: infty = lshift(1_8, 61)
  integer :: n, i, j
  integer(8) :: a(200000) = 0, dp(0:200000, 2) = -infty
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    do j = (i + 1) / 2, n / 2 - (n - i + 1) / 2, -1
      dp(j, 1) = maxval(dp(j, :))
      if (j > 0) then
        dp(j, 2) = merge(a(i), dp(j - 1, 1) + a(i), dp(j - 1, 1) == -infty)
      end if
    end do
  end do
  write(*,'(i0)') maxval(dp(n / 2, :))
end program select_half

Measured memory_bytes: 6308
#include<bits/stdc++.h>
using namespace std;
int main() {
    string o, e;
    cin >> o >> e;
    int i;
    int len1 = o.length();
    int len2 = e.length();
    int len = len1 + len2;
    int j, k;
    i = 0, j = 0;
    for(k=0; k<len; k++){
        if(i>=len1){
            cout << e[j];
            j++;
        }
        else if(j>=len2){
            cout << o[i];
            i++;
        }
        else if(k%2==0){
            cout << o[i];
            i++;
        }
        else{
            cout << e[j];
            j++;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
#define ppb pop_back
#define len(v) int(v.size())
#define all(v) (v).begin(),(v).end()
#define ri(x) scanf("%d",&(x))
#define rii(x,y) scanf("%d %d",&(x),&(y))
#define riii(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rl(x) scanf("%lld",&(x))
#define rll(x,y) scanf("%lld %lld",&(x),&(y))
#define rlll(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
using namespace std; 
typedef unsigned int uint; typedef long long ll;
typedef unsigned long long ull; typedef pair<int, int> pii;
typedef pair<ll,ll> pll; typedef long double ld;
void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0);}
template<typename T> T __lcm(T a, T b){return (a*b)/__gcd(a,b);}
template<typename T> T fpow(T a, T b, T p) {
	a %= p; T res = 1; while (b > 0) { 
	if (b & 1) res = res * a % p;
	a = a * a % p; b >>= 1;} return res;}
template<typename T> T binpow(T a, T b) {
		T res = 1; while (b > 0) {if (b & 1) res = res * a;
		a = a * a; b >>= 1;} return res;}
const long double PI = acos(-1);
const long long MOD = 1000000000 +7;
const int maxn = 1e5;

int n;
int a[maxn], dp[maxn];

int main() {
	ri(n);
	forn(i, n) ri(a[i]);
	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	forr(i, 2, n){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	printf("%d\n", dp[n-1]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,x,a[100000]={};
 long long ans=0;
 cin>>n>>x;
 for(int i=0;i<n;i++)cin>>a[i];

 for(int i=1;i<n;i++)
  if(a[i-1]+a[i]>x){
   ans+=a[i-1]+a[i]-x;
   if(a[i-1]>x){
    a[i]=0;
    a[i-1]=x;
    }
   else a[i]=x-a[i-1];
  }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 640
N=int(input())
j=0
J=0
for i in range(N):
  D1,D2=map(int,input().split())
  if D1==D2:
    j+=1
    if j>=3:
      J=3
  else:
    j=0
if J>=3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9184
S = input()
T = input()
L = []
slide_num = len(S) - len(T)
if slide_num < 0:
    print('UNRESTORABLE')
    exit()
for slide in range(slide_num+1):
    for j in range(len(T)):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        L.append((S[:slide] + T + S[slide+len(T):]).replace('?', 'a'))

if L:
    print(L.pop())
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int pre[MAXN],suf[MAXN];	
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
		scanf("%d",pre+i),pre[i]+=pre[i-1];
	for(int i=1;i<=n;i++)
		scanf("%d",suf+i);
	int ans=0;	
	for(int i=n;i>=1;i--){
		suf[i]+=suf[i+1];
		umax(ans,suf[i]+pre[i]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,a,b,c,i,s,e;
	while(cin>>n,n){
		for(i=0;i<n;i++){
			cin>>a>>b>>c;s=(a+b+c)/3,e=(a+b)/2;
			cout<<(s>=80||e>=90||a==100||b==100||c==100?'A':(s>=70||(s>=50&&(a>=80||b>=80))?'B':'C'))<<endl;
		}
	}
}

Measured memory_bytes: 1152
/* ex 4_3
   cy_an  */

#include <stdio.h>
#include <math.h>

int main(void){

    // 変数宣言
    int len_a, len_b, deff, depth, i;
    // 入力
    scanf("%d %d", &len_a, &len_b);

    // deffの計算
    deff = len_b - len_a;
    // depthの計算
    depth = -len_a;
    for(i = 1; i < deff; i++){
        depth += i;
    }
    // depthの出力
    printf("%d\n", depth);

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int x[100],y[100],h[100];
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i] >> h[i];
	}
	int x1,y1,h1,x2,y2,h2,m,j;
	for(j=0;j<10201||m==n;j++){
		x1=j/101;
		y1=j%101;
		m=0;
		for(int l=0;l<n;l++){
			if(!(h[l]==0)){
				h1=h[l]+abs(x1-x[l])+abs(y1-y[l]);
			}
		}
		for(int k=0;k<n;k++){
			if(h[k]==max(h1-abs(x1-x[k])-abs(y1-y[k]),0)&&h1>=h[k]&&h1>0){
				m++;
			}
		}
		if(m==n){
			x2=x1;
			y2=y1;
			h2=h1;
		}
	}
	cout << x2 << " " << y2 << " " << h2 << endl;
	return 0;
}


Measured memory_bytes: 256
N,x=map(int,input().split())
A=list(map(int,input().split()))
r=0
for i in range(N-1):
    if A[i]>x:
        r+=A[i]+A[i+1]-x
        A[i]=x
        A[i+1]=0
    elif A[i]+A[i+1]>x:
        r+=A[i]+A[i+1]-x
        A[i+1]=x-A[i]
print(r)

Measured memory_bytes: 14052
count = int(input())
wlist = input().split()
z = 0
for i in range(count):
  wlist[i] = int(wlist[i])
  z += wlist[i]
c = z/2
d = 0
e = 0

while d < c:
    d = d + wlist[e]
    e += 1
    if d >= z-d:
      e = e-1
      d = d - wlist[e]
      break

f = abs(z-2*d)
print(min(f,abs(z - 2*(d+wlist[e]))))


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

using namespace std;

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

	int x, y, cnt = 0;
	double sum;
	for (int i = 0; i < n; i++) {
		sum = 0.0;
		cin >> x >> y;
		sum = sqrt(double(x) * double(x) + double(y) * double (y));
		if (sum <= (double)d) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3680
//Let's join Kaede Takagaki Fun Club !!
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
ll mod;
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

ll dp[6005][9005];
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[10005],R[10005];
ll rev2[10005];
ll rev3[10005];
void make(){
	F[0] = 1;
	for(int i=1;i<10005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<10005;i++) R[i] = modpow(F[i],mod-2);
	for(int i=0;i<10005;i++) {
		rev2[i] = modpow(modpow(2LL,i),mod-2);
		rev3[i] = modpow(modpow(3LL,i),mod-2);
	}
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int main(){
	int n, m; g(n); g(m);
	mod = m;
	make();
	ll ans = 0;
	for(int one=0;one<=3*n;one++){
		for(int two=0;two<=one;two++){
			int zan = 3*n-one-two-two;
			if(zan >= 0 && zan%3 == 0){
				int thr = zan / 3;
				add(ans, C(3*n, one) * C(3*n-one, two*2) % mod * F[two*2] % mod * R[two] % mod * rev2[two] % mod * F[thr*3] % mod * R[thr] % mod * rev3[thr] % mod);
			}
			//o(one,1); o(two,1); o(ans);
		}
	}
	o(ans);
}

Measured memory_bytes: 512
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"]else stack.push(int(s)) for s in arr]
print(stack.pop())



Measured memory_bytes: 5612
#include<iostream>
using namespace std;
void ad(int a,int b,int c){cout<<"+ "<<a<<" "<<b<<" "<<c<<endl;}
void lt(int a,int b,int c){cout<<"< "<<a<<" "<<b<<" "<<c<<endl;}
main()
{
	cout<<3870<<endl;
	ad(0,1,3);
	lt(2,3,3);
	for(int x=0;x<2;x++)
	{
		ad(3,x,x);
		int v=x+4;
		for(int i=0;i<30;i++)
		{
			if(i>0)ad(v,v,v);
			ad(v,3,6);
			for(int j=i;j<29;j++)ad(6,6,6);
			int u=i+7+x*30;
			lt(6,x,u);
			ad(v,u,v);
		}
	}
	for(int t=0;t<59;t++)
	{
		if(t>0)ad(2,2,2);
		for(int i=t>29?t-29:0;i<30&&i<=t;i++)
		{
			int j=t-i;
			ad(i+7,j+37,4);
			lt(3,4,4);
			ad(2,4,2);
		}
	}
}

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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    string s;
    cin >> s;
    int c[4];
    for(int i = 0 ; i < 4; ++i){
        c[i] = s[i] - '0';
    }

    if(c[0] + c[1] + c[2] + c[3] == 7){
        cout << c[0] << '+' << c[1] << '+' << c[2] << '+' << c[3] << '=' << 7 << endl;
    }else if(c[0] + c[1] + c[2] - c[3] == 7){
        cout << c[0] << '+' << c[1] << '+' << c[2] << '-' << c[3] << '=' << 7 << endl;
    }else if(c[0] + c[1] - c[2] + c[3] == 7){
        cout << c[0] << '+' << c[1] << '-' << c[2] << '+' << c[3] << '=' << 7 << endl;
    }else if(c[0] - c[1] + c[2] + c[3] == 7){
        cout << c[0] << '-' << c[1] << '+' << c[2] << '+' << c[3] << '=' << 7 << endl;
    }else if(c[0] + c[1] - c[2] - c[3] == 7){
        cout << c[0] << '+' << c[1] << '-' << c[2] << '-' << c[3] << '=' << 7 << endl;
    }else if(c[0] - c[1] + c[2] - c[3] == 7){
        cout << c[0] << '-' << c[1] << '+' << c[2] << '-' << c[3] << '=' << 7 << endl;
    }else if(c[0] - c[1] - c[2] + c[3] == 7){
        cout << c[0] << '-' << c[1] << '-' << c[2] << '+' << c[3] << '=' << 7 << endl;
    }else if(c[0] - c[1] - c[2] - c[3] == 7){
        cout << c[0] << '-' << c[1] << '-' << c[2] << '-' << c[3] << '=' << 7 << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a*b%2==0) cout<<"Even"<<endl;
    else cout<<"Odd"<<endl;
}

Measured memory_bytes: 764
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (char s) { return string(1, s); }
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) {
	string res = "["; for (int i = 0; i < (int)v.size() - 1; i++) res += to_string(v[i]) + ", ";
	if (!v.empty()) res += to_string(v.back());	res += "]"; return res; }

int main () { 
#ifdef XVENOM
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif

	int x, ans = 0;
	scanf("%d", &x);
	while (ans * (ans + 1) / 2 < x) ans++;
	printf("%d\n", ans);
}

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

int main()
{
	int a;
	cin>>a;
	int x=10-a/100;
	int y=10-a/10%10;
	int z=10-a%10;
	cout<<x*100+y*10+z*1<<endl;
	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c;cin>>a>>b>>c;
  if(a+b<c){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-10;
int sign(double x)
{
    if(fabs(x)<=eps)return 0;
    if(x>0)return 1;
    return -1;
}
struct Point{
    double x,y;
    Point(double _x=0,double _y=0):x(_x),y(_y){}
    Point operator + (Point p){return Point(x+p.x,y+p.y);}
    Point operator - (Point p){return Point(x-p.x,y-p.y);}
    Point operator * (double k){return Point(x*k,y*k);}
    Point operator / (double k){return Point(x/k,y/k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator < (const Point &p)const{return x!=p.x?x<p.x:y<p.y;}
};
typedef Point Vector;
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
int ccw(Point p0,Point p1,Point p2)
{
    Vector a=p1-p0,b=p2-p0;
    if(sign(cross(a,b))==1)return 1;
    return 0;
}
int n;
Point p;
Polygon g,s,ans;
double Area(Point a,Point b,Point c)
{
    Vector x1=b-a,y1=c-a;
    return cross(x1,y1);
}
Polygon andrew()
{
    s=g;
    int n=s.size();
    sort(s.begin(),s.end());
    Polygon u;
    for(int i=0;i<n;i++){
        for(int j=u.size();j>=2&&sign(Area(u[j-2],u[j-1],s[i]))>=0;j--){
            u.pop_back();
        }
        u.push_back(s[i]);
    }
    int tmp=u.size()+1;
    for(int i=n-2;i>=0;i--){
        for(int j=u.size();j>=tmp&&sign(Area(u[j-2],u[j-1],s[i]))>=0;j--){
            u.pop_back();
        }
        u.push_back(s[i]);
    }
    if(n>1)u.pop_back();
    reverse(u.begin(),u.end());
    return u;
}
double rc()
{
    double res=0;
    int n=ans.size();
    int k=1;
    for(int i=0;i<n;i++){
        while(sign(Area(ans[i],ans[(i+1)%n],ans[(k+1)%n])-Area(ans[i],ans[(i+1)%n],ans[k%n]))==1)k=(k+1)%n;
        res=max(res,(ans[i]-ans[k]).abs());
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf%lf",&p.x,&p.y);
        g.push_back(p);
    }
    ans=andrew();
    printf("%.10f\n",rc());
    return 0;
}



Measured memory_bytes: 5440
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define rep(i, a, N) for(int i = a; i < N; i++)
#define rrep(i, a, N) for(int i = a; i >= N; i--)

int N;
int board[2][100];
int dp[2][100] = {0};

int dfs(int x, int y, int cnt) {
    cnt += board[x][y];
    if (x == 1 && y == N - 1) return cnt;

    int ret = 0;
    if (x + 1 < 2) ret = max(ret, dfs(x + 1, y, cnt));
    if (y + 1 < N) ret = max(ret, dfs(x, y + 1, cnt));

    return ret;
}

int main() {
    cin >> N;
    rep(i, 0, 2) {
        rep(j, 0, N) {
            cin >> board[i][j];
        }
    }

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

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

using namespace std;

int main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> v(n, vector<int>(d));
    for(auto&& i : v){
        for(auto&& j : i){
            cin >> j;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int num = 0;
            for(int k = 0; k < d; k++){
                num += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
            }
            int checknum;
            for(checknum = 1; checknum * checknum < num; checknum++);
            ans += checknum * checknum == num;
        }
    }
    cout << ans << "\n";
}

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

typedef long long ll; 

ll f(ll b, ll n){
        if(n==0) return 0; 
        return n%b+f(b,n/b); 
}
int main(){
        ll n,s; cin>>n>>s; 
        if(s>n) { cout<<-1; return 0; }
        if(s==n) { cout<<n+1; return 0; }
        for(int i=2;i<=sqrt(n);i++){
                ll sum=f(i,n); 
                if(sum==s) { cout<<i; return 0; }
        }
        ll p=1; 
        ll a=n-s;
        for(p=sqrt(n);p>=1;p--){
                ll b=a/p+1;
                if(a%p==0 && b>p && s-p>=0 && s-p <b) {  cout<<b; return 0; }
        }
        cout<<-1; 

	return 0; 
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int n,s=0;
	
	cin>>n;
	int a[n];
	
	for(int i=0;i<n;i++)   cin>>a[i];
	
	do{
		for(int i=0;i<n;i++)
			if(a[i]%2==1)
			{
				cout<<s;
				return 0;
			} 
			else
			{
				a[i]=a[i]/2;
			}
		s++;
	}while(1);
}
		
	
	


Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args){
		List<String> list = new ArrayList<String>();

		String[] mark = {"S", "H", "C", "D"};

		for(int i = 0; i < 4; i++){
			for(int j = 1; j <= 13; j++){
				list.add(mark[i] + " " + j );
			}
		}

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.nextLine());

		for(int i = 0; i < n; i++){
			// ここのlistはint n(変数) ではだめ。理由はlist配列は参照型だから基本データ型のint n(変数)ではremoveできない
			list.remove(sc.nextLine());
		}

		for(String str : list){
			System.out.println(str);
		}
		
	}
}


Measured memory_bytes: 26280
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

const int MOD = 1e9 + 7, N = 1e6 + 7;

int f[N] = { 1 }, rf[N] = { 1 };

int binpow(int x) {
    int ans = 1, d = MOD - 2;
    while (d) {
        if (d & 1)
            ans = ans * x % MOD;
        x = x * x % MOD;
        d >>= 1;
    }
    return ans;
}

int binom(int n, int k) {
    return f[n] * rf[k] % MOD * rf[n - k] % MOD;
}

void solve() {
    loop1(i, N - 1) {
        f[i] = f[i - 1] * i % MOD;
        rf[i] = binpow(f[i]);
    }
    int x, y;
    cin >> x >> y;
    int one = x, two = 0, ans = 0;
    for (; one >= 0; ----one, ++two) {
        if (one * 2 + two == y)
            ans = (ans + binom(one + two, one)) % MOD;
    }
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 19248
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string s;
    int n[3] = {0};

    cin >> s;
    REP(i, s.size())
    {
        n[s[i] - 'a']++;
    }

    bool res = false;
    res |= n[0] == n[1] && n[1] == n[2];
    res |= n[0] + 1 == n[1] && n[1] == n[2];
    res |= n[0] + 1 == n[1] + 1 && n[1] + 1 == n[2];
    res |= n[0] + 1 == n[1] && n[1] == n[2] + 1;
    res |= n[0] + 1 == n[1] + 1 && n[1] + 1 == n[2] + 1;
    res |= n[0] + 1 == n[1] + 2 && n[1] + 2 == n[2] + 1;
    res |= n[0] == n[1] + 1 && n[1] + 1 == n[2] + 1;
    res |= n[0] == n[1] && n[1] == n[2] + 1;

    if (res)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int e[101][101];
	int R, C, r, c;
	int s, total;

	scanf("%d%d", &R, &C);
	for (r = 1; r <= R; r++) {
		for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
	}
	
	for (r = 1; r <= R; r++) {
		s = 0;
		for (c = 1; c <= C; c++) s += e[r][c];
		e[r][0] = s;
	}
	total = 0;
	for (c = 1; c <= C; c++) {
		s = 0;
		for (r = 1; r <= R; r++) s += e[r][c];
		e[0][c] = s;
		total += s;
	}
	for (r = 1; r <= R; r++) {
		for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
		printf("%d\n", e[r][0]);
	}
	for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
	printf("%d\n", total);
	return 0;
}



Measured memory_bytes: 2144
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int num = stdIn.nextInt();
        num = swap(num);
        System.out.println(num);
    }
    static int swap(int num){
        int j,k,l;
        j = num/100;
        k = (num%100)/10;
        l = num%10;
        if(j >= k && j >= l){
            return (j*100+j*10+j);
        }
        if(j < k || j < l){
            return ((j+1)*100+(j+1)*10+(j+1));
        }
        return (j*100+j*10+j);
    }
}

Measured memory_bytes: 23124
using System;
using System.Collections.Generic;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ').Select(c=>int.Parse(c)).ToArray();
            var absX = inputs[2] - inputs[0];
            var absY = inputs[3] - inputs[1];
            var result = new List<char>();
            result.AddRange(Enumerable.Range(0, absY).Select(_ => 'U'));
            result.AddRange(Enumerable.Range(0, absX).Select(_ => 'R'));
            result.AddRange(Enumerable.Range(0, absY).Select(_ => 'D'));
            result.AddRange(Enumerable.Range(0, absX).Select(_ => 'L'));
            result.Add('L');
            result.Add('U');
            result.AddRange(Enumerable.Range(0, absY).Select(_ => 'U'));
            result.AddRange(Enumerable.Range(0, absX).Select(_ => 'R'));
            result.Add('R');
            result.Add('D');
            result.Add('R');
            result.Add('D');
            result.AddRange(Enumerable.Range(0, absY).Select(_ => 'D'));
            result.AddRange(Enumerable.Range(0, absX).Select(_ => 'L'));
            result.Add('L');
            result.Add('U');
            Console.WriteLine(string.Join("", result));
        }
    }

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,i,mi=1e6+1,ma=-1e6-1,mii=-1,mai=-1;
  cin>>n;
  for(i=1;i<=n;i++){
    cin>>a;
    if(a<mi){
      mi=a;
      mii=i;
    }
    if(a>ma){
      ma=a;
      mai=i;
    }
  }
  cout<<2*n<<endl;
  if(abs(mi)<=abs(ma)){
    cout<<mai<<' '<<1<<endl<<mai<<' '<<1<<endl;
    for(i=1;i<n;i++) cout<<i<<' '<<i+1<<endl<<i<<' '<<i+1<<endl;
  }
  else if(abs(mi)>abs(ma)){
    cout<<mii<<' '<<n<<endl<<mii<<' '<<n<<endl;
    for(i=n;i>1;i--) cout<<i<<' '<<i-1<<endl<<i<<' '<<i-1<<endl;
  }
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	char a[100];
	char s; 
	int i,n,count=0;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
		a[i]=getchar();
	}
	for(i=0;i<n;i++){
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')count++;
	}
    printf("%d",count);
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll m[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for(int i = 1; i <= n; i++) m[i % k]++;
    ans = m[0] * m[0] * m[0];
    if(k % 2 == 0) ans += m[k >> 1 ] * m[k >> 1] * m[k >> 1];
    cout << ans;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++)
    cin >> d.at(i);
  
  sort(d.begin(),d.end());
  
  cout << d.at(n/2)-d.at(n/2-1) << endl;
}

Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, Q = map(int, input().split())
INF = 2**31-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)

def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1

def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


ans = []
for q in range(Q):
    t, *cmd = map(int, readline().split())
    if t:
        s, t = cmd
        ans.append(str(query(s, t+1)))
    else:
        s, t, x = cmd
        update(s, t+1, x)

write("\n".join(ans))
write("\n")


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x; cin>>x;
    if (x>=30){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int i = 1;    
    while(true){
      if(s==1 || s==2 || s==4){
        break;
      } else if(s % 2 == 0){
        i++;
        s /= 2;
      } else {
        i++;
        s = s*3 + 1;
      }
    }
    System.out.println(i+3);
  }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,x,y,i,j,k,p=0,q=0,h,w,r,t;
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
	s[i]=((int)s[i]+n);
		if((int)s[i]>90)
		{s[i]=(int)s[i]%90+64;//cout<<(int)s[i]<<endl;
		}
	}
cout<<s;
}

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

int main() {
    const int po[10] = {8,27,32,125,128,
                    216,243,363,512,1000};
    int x = 0;
    cin >> x;
    int ans = (int)pow((int)sqrt(x), 2);
    for(int i = 0; po[i]<=x; i++)
        ans = max(ans, po[i]);
    cout << ans << "\n";
    return 0;
}

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

int main() {
    int N;
    double count=0;
    cin >>N;
    map<double,string>mp;
    for(int i=0; i<N;i++){
        double x;
        string u;
        cin >>x>>u;
        mp[x]=u;
        if(mp[x]=="JPY")count+=x;
        else count += 380000*x;
    }
    cout << count <<endl;
}


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

#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()

const int NAX = 3000 + 5, MOD = 1000000007;

struct Solution
{
    Solution() {}
    void solveCase();
};

int grid[NAX][NAX];
ll dp[NAX][NAX][4];
int r, c;

ll solve(int ridx, int cidx, int rem)
{
    if (ridx == (r - 1) && cidx == (c - 1))
        return rem > 0 ? (grid[ridx][cidx] > 0 ? grid[ridx][cidx] : 0) : 0;
    if (ridx == r)
        return -1e18;
    if (cidx == c)
        return -1e18;
    ll &ret = dp[ridx][cidx][rem];
    if (ret >= 0)
        return ret;
    ret = -1e18;
    if (rem == 0)
        ret = max(solve(ridx + 1, cidx, 3), solve(ridx, cidx + 1, 0));
    else
    {
        ll temp = max(solve(ridx + 1, cidx, 3), solve(ridx, cidx + 1, rem));
        ret = max(ret, temp);
        temp = max(grid[ridx][cidx] + solve(ridx + 1, cidx, 3), grid[ridx][cidx] + solve(ridx, cidx + 1, rem - 1));
        ret = max(ret, temp);
    }
    return ret;
}

void Solution::solveCase()
{
    memset(dp, -1, sizeof dp);
    cin >> r >> c;
    int k;
    cin >> k;
    for (size_t i = 0; i < k; i++)
    {
        int x, y, v;
        cin >> x >> y >> v;
        grid[x - 1][y - 1] = v;
    }
    cout << solve(0, 0, 3) << '\n';
}

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef LOCAL
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 321516
n=int(input())
s=input()

r=s.count("R")
g=s.count("G")
b=s.count("B")
all_res=r*g*b

del_res=0
for i in range(1,n-1):
    for q in range(1,min(i,n-i-1)+1):
        #print(i,q)
        if s[i]!=s[i-q] and s[i]!=s[i+q] and s[i-q]!=s[i+q]:
            del_res+=1

print(all_res-del_res)

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 2e5 + 5;

int cnt[ N ];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n;
  cin >> n;
  for (int i = 1; i <= n - 1; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1; i <= n; i++) cout << cnt[i] << endl;
  return 0;
}



Measured memory_bytes: 4308
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,len(p)-1):
  if (p[i]<p[i-1] and p[i]>p[i+1]) or (p[i]>p[i-1] and p[i]<p[i+1]):
    ans+=1
  else:
    ans+=0
    

print(ans)    



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    ll min1=min(a,b);
    min1=min(min1,c);
    min1=min(min1,d);
    min1=min(min1,e);
    if(n%min1!=0)cout<<(n/min1)+5<<endl;
    else cout<<(n/min1)+4<<endl;
}

Measured memory_bytes: 256