akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79936
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n;
        scanf("%d", &n);
        if ( n < 1000 ) printf("ABC\n");
        else printf("ABD\n");

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main(void){
    
    unsigned long H,W;
    cin >> H >> W;
    
    if(H%2 == 1 && W%2 == 1){
        if(H == 1 || W == 1){
            cout << 1 << endl;
        }
        else{
            cout<< H*W/2 + 1 <<endl;
        }
        
    }
    else{
        if(H == 1 || W == 1){
            cout << 1 << endl;
        }
        else{
            cout<< H*W/2 <<endl;
        }
        
    }
   
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define maxn 800010
#define P 924844033
#define G 5
using namespace std;
typedef long long ll;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
ll n;
ll rev[maxn],f[maxn],g[maxn],fac[maxn],ifac[maxn],siz[maxn],cnt[maxn];
struct edge
{
    int to,nxt;
}e[maxn];
int head[maxn],edge_cnt;
void add(int from,int to)
{
    e[++edge_cnt]={to,head[from]},head[from]=edge_cnt;
}
ll qp(ll x,ll y)
{
    ll v=1;
    while(y)
    {
        if(y&1) v=v*x%P;
        x=x*x%P,y>>=1;
    }
    return v;
}
int calc(int n)
{
    int lim=1;
    while(lim<=n) lim<<=1;
    for(int i=0;i<lim;++i)
        rev[i]=(rev[i>>1]>>1)|((i&1)?lim>>1:0);
    return lim;
}
void NTT(ll *a,int lim,int type)
{
    for(int i=0;i<lim;++i)
        if(i<rev[i])
            swap(a[i],a[rev[i]]);
    for(int len=1;len<lim;len<<=1)
    {
        ll wn=qp(G,(P-1)/(len<<1));
        for(int i=0;i<lim;i+=len<<1)
        {
            ll w=1;
            for(int j=i;j<i+len;++j,w=w*wn%P)
            {
                ll x=a[j],y=w*a[j+len]%P;
                a[j]=(x+y)%P,a[j+len]=(x-y+P)%P;
            }
        }
    }
    if(type==1) return;
    ll inv=qp(lim,P-2);
    for(int i=0;i<lim;++i) a[i]=a[i]*inv%P;
    reverse(a+1,a+lim);
}
void mul(ll *f,ll *g)
{
    int lim=calc(n<<1);
    NTT(f,lim,1),NTT(g,lim,1);
    for(int i=0;i<lim;++i) f[i]=f[i]*g[i]%P;
    NTT(f,lim,-1);
}
void dfs(int x,int fa)
{
    siz[x]=1;
    for(int i=head[x];i;i=e[i].nxt)
    {
        int y=e[i].to;
        if(y==fa) continue;
        dfs(y,x),siz[x]+=siz[y];
    }
    cnt[siz[x]]++,cnt[n-siz[x]]++;
}
ll C(ll n,ll m)
{
    return fac[n]*ifac[m]%P*ifac[n-m]%P;
}
void init()
{
    fac[0]=ifac[0]=1;
    for(int i=1;i<=n;++i) fac[i]=fac[i-1]*i%P;
    ifac[n]=qp(fac[n],P-2);
    for(int i=n-1;i;--i) ifac[i]=ifac[i+1]*(i+1)%P;
}
int main()
{
    read(n),init();
    for(int i=1;i<n;++i)
    {
        int x,y;
        read(x),read(y);
        add(x,y),add(y,x);
    }
    dfs(1,0),g[0]=1;
    for(int i=1;i<=n;++i) f[i]=cnt[n-i]*fac[n-i]%P,g[i]=ifac[i];
    mul(f,g),reverse(f,f+n+1);
    for(int i=1;i<=n;++i) printf("%lld\n",(n*C(n,i)%P-ifac[i]*f[i]%P+P)%P);
    return 0;
}

Measured memory_bytes: 39444
#include <bits/stdc++.h>
using namespace std;
static int64_t fib(int32_t n) {
  if (n < 0 || 44ll < n) {
    return -1;
  }
  if (n == 0 || n == 1ll) {
    return 1ll;
  }
  int64_t a = 1ll, b = 1ll;
  for (int32_t i = 2; i <= n; ++i) {
    int64_t t = a + b;
    a = b, b = t;
  }
  return b;
}
int main() {
  int32_t n;
  cin >> n;
  cout << fib(n) << endl;
}



Measured memory_bytes: 3104
#include<stdio.h>
int main(void)
{
    int x, y;
    while(1)
    {
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0)
        {
            break;
        }
        else if(x < y)
        {
            printf("%d %d\n", x, y);
        }
        else
        {
            printf("%d %d\n", y, x);
        }
    }
    return 0;
}


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

const int MAXN = 200005;

int n, m, ai, bi;
vector <int> g[MAXN];

bool vis[MAXN];
int c;

void dfs(int u){
	vis[u] = true;
	c++;
	
	for(int v : g[u]){
		if(!vis[v])dfs(v);
	}
}

int main(){
	scanf("%d %d", &n, &m);
	while(m--){
		scanf("%d %d", &ai, &bi);
		ai--, bi--;
		
		g[ai].push_back(bi);
		g[bi].push_back(ai);
	}
		
	int res = 0;
	for(int i = 0; i < n; i++)if(!vis[i]){
		c = 0;
		dfs(i);
		res = max(res, c);
	}
	printf("%d\n", res);
	
	return 0;
}


Measured memory_bytes: 21056
n,*a=map(int,open(0).read().split())
ans=0
for k,v in enumerate(a):
    if k==n-1 and k+1==v:
        a[k-1],a[k]=a[k],a[k-1]
        ans+=1
    elif k+1==v:
        a[k],a[k+1]=a[k+1],a[k]
        ans+=1
print(ans)
    

Measured memory_bytes: 13940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    int N=in();
    string S;
    cin>>S;
    vector<int> a, b, c;
    rep(i, N){
        if(S.at(i)=='R'){
            a.push_back(i);
        }
        else if(S.at(i)=='G'){
            b.push_back(i);
        }
        else{
            c.push_back(i);
        }
    }
    ll sum=0;
    int m1, m2;
    rep(i, a.size()){
        rep(j, b.size()){
            m1=min(a.at(i), b.at(j));
            m2=max(a.at(i),b.at(j));
            if(2*m1-m2>=0){
                if(S.at(2*m1-m2)=='B'){
                    sum++;
                }
            }
            if(2*m2-m1<N){
                if(S.at(2*m2-m1)=='B'){
                    sum++;
                }
            }
            if((m2-m1)%2==0){
                if(S.at((m1+m2)/2)=='B'){
                    sum++;
                }
            }
        }
    }
    ll p, q, r;
    p=a.size();
    q=b.size();
    r=c.size();
    ll ans=p*q*r-sum;
    cout<<ans<<endl;
}

Measured memory_bytes: 3668
N=int(input())
L=[]
for i in range(N):
	L.append(int(input()))
count=0
ans=0
i=0
while(1):
	count+=1
	if count==N+1:
		print(-1)
		exit()
	i=L[i]-1
	ans+=1
	if i==1:
		print(ans)
		exit()

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

int main(){
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
    
    int max_A = X / 500;
    int count = 0;
    
    for(int i=min({max_A, A}); i>=0; i--){
        int tmp_X = X - i*500;

        int max_B = tmp_X / 100;
        for(int j=min({max_B, B}); j>=0; j--){
            int tmp_X_2 = tmp_X - 100*j;

            int require_C = tmp_X_2 / 50;
            if(require_C <= C){
                count += 1;
            }
        
        }
    }

    cout << count << endl;
    return 0;
}

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

int main(){
  int N,M;cin>>N>>M;
  char A[N][N];
  char B[M][M];
  for(int i=0;i<N;i++) cin>>A[i];
  for(int i=0;i<M;i++) cin>>B[i];
  bool can=false;
  for(int i=0;i<=N-M;i++){
    for(int l=0;l<=N-M;l++){
      bool isyes=true;
      for(int j=0;j<M;j++){
        for(int k=0;k<M;k++){
          if(A[i+j][k+l]!=B[j][k]){
            isyes=false;
            break;
          }
        }
        if(!isyes) break;
      }
      if(isyes){
        can=true;
        break;
      }
    }
    if(can) break;
  }
  cout<<(can?"Yes":"No")<<endl;
}

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

#define PI 3.141592653589793238462643383279
typedef long long ll;
const long double EPS = 1e-9;
const ll MOD = 1e9+7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(20);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    #ifdef LOCAL_TEST
    freopen("input.txt","r",stdin);
    #endif
    int n; cin >> n;
    int ans, a; cin >> ans;
    for(int i=1;i<n;i++) {
        cin >> a;
        ans = __gcd(ans, a);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
N,A,B,C,D=list(map(int,input().split()))
S=input()
bS=S[B-1:D]
a=True
if C<D:
    if "##" in bS:
        a=False
    else:
        aS=S[A-1:C]
        if "##" in aS:
            a=False

else:
    if "##" in bS:
        a=False
    else:
        aS=S[A-1:C]
        if "##" in aS:
            a=False
        else:
            tmp=S[:B-1]+"#"+S[B:]
            aS=tmp[A-1:C]
            j1= ("##" in aS)
            tmp=S[:D-1]+"#"+S[D:]
            aS=tmp[A-1:C]
            j2= ("##" in aS)
            if  ((not "..." in bS) and (j1 and j2)):
                a=False
            
        
        
if a:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3892
var
	N,i:Longint;
	p,A,T:int64;
begin
	read(N,p);
	T:=1000;
	for i:=2 to N do begin
		read(A);
		if p<A then begin
			T:=T mod p+T div p*A;
		end;
		p:=A;
	end;
	writeln(T);
end.

Measured memory_bytes: 1320
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
int main(void)
{
	char s[1003];
	scanf("%s",s);
	if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') puts("3");
	else if(s[0]=='R'&&s[1]=='R') puts("2");
	else if(s[1]=='R'&&s[2]=='R') puts("2");
	else if(s[0]=='S'&&s[1]=='S'&&s[2]=='S') puts("0");
	else puts("1");
}

Measured memory_bytes: 3760
#include <stdio.h>
#define MAX 100
#define INFTY 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim(){
  int i,u,minv,v,sum;
  int d[MAX],p[MAX],color[MAX];

  for(i = 0;i < n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0;i < n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(v = 0;v < n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  sum = 0;
  for(i = 0;i < n;i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      scanf("%d",&e);
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }
  printf("%d\n",prim());

  return 0;
}

Measured memory_bytes: 632
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();
    static long mod = 1000000007;

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] s = new int[n];
        int[] t = new int[m];
        Arrays.setAll(s, i -> scanner.nextInt());
        Arrays.setAll(t, i -> scanner.nextInt());

        long[][] dp = new long[n + 1][m + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + mod - dp[i - 1][j - 1] + (s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : 0)) % mod;
            }
        }

        System.out.println(dp[n][m] + 1);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return tokenizer.nextToken();
        }

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

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

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

Measured memory_bytes: 84948
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 100

int N;
int h[MAX];
int num = 0;

int find_min_idx(int left, int right){
    // return the index of the minimum value in h
    int min_idx = left;
    for (int i = left; i <= right; i++){
        if (h[min_idx] > h[i]){
            min_idx = i;
        }
    }
    // cout << min_idx << " " << h[min_idx] << endl;
    return min_idx;
}

void binary_calc(int left, int right){
    // minを見つける
    int min_idx = find_min_idx(left, right);
    // cout << min_idx << " " << h[min_idx] << endl;
    num += h[min_idx];
    int each_num = h[min_idx];
    for (int i = left; i <= right; i++){
        h[i] -= each_num;
    }
    // for (int i = 0; i < N; i++){
    //     cout <<  h[i] << " ";
    // }
    // cout << endl;
    if (min_idx != right){
        binary_calc(min_idx+1, right);
    }
    if (min_idx != left){
        binary_calc(left, min_idx-1);
    }
}

int main(){
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    binary_calc(0, N-1);
    cout << num << endl;

    return 0;
}

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

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  rep(i, k) ans += p[i];
  cout << ans << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int sum = 0;
    int x=0, prex=101010;
    for (int i=0; i<n; i++) {
        if (i!=n-1) cin >> x;
        sum += min(x, prex);
        prex = x;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
def a(n,m):
	l1=n//3*2+1
	l2=n-l1
	l3=m//2
	l4=m-l3
	A=[l2*m,l1*l3,l1*l4]
	r=max(A)-min(A)
	if n>3:
		l5=l1//2
		l6=l1-l5
		B=[l2*m,l5*m,l6*m]
		r=min(r,max(B)-min(B))
	return r
h,w=map(int,input().split())
if h%3==0 or w%3==0:
	print(0)
else:
	print(min(a(h,w),a(w,h)))

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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    vector< vector<int> > s(M);
    for (int i=0;i<M;i++) {
        int k;
        cin >> k;

        s[i].resize(0);
        for (int j=0;j<k;j++) {
            int si;
            cin >> si;
            s[i].push_back(si);
        }
    }

    vector<int> p(M);
    for (int i=0;i<M;i++) {
        int pi;
        cin >> pi;
        p[i] = pi;
    }

    bool ok;
    int ans = 0;

    for (int i=0;i<pow(2,N);i++){
        ok = true;
        for (int m=0;m<s.size();m++) {
            int t=0;
            for (int k=0;k<s[m].size();k++) {
                t += (i >> (s[m][k] - 1)) & 1;
            }
            if (t % 2 != p[m]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n,k; cin >> n >> k;
    int ans = 0;
    REP(i,n) {
        int x; cin >> x;
        if (x >= k) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
t = gets.to_i
ret = []
t.times do
  n, k = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  ds = (xs.size - 1).times.map {|i| xs[i + 1] - xs[i] }.sort
  a = ds[0..-k]
  ret << (a.empty? ? "0" : a.reduce(:+))
end
puts ret

Measured memory_bytes: 21544
#include <cstdio>
#include <string>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef long long ll;
ll sum;
int k;

int main(){
	cin >> k;
	for(int i = 1; i <= k; i++){
		for(int j = 1; j <= k; j++){
			for(int m = 1; m <= k; m++){
				sum += __gcd(i,__gcd(j, m));
			}
		}
	}
	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 3804
"use strict"

const main = (input) => {
    input = input.split("\n");
    const N = Number(input[0]);
    let ds = input[1].split(" ").map(p => Number(p));
    ds = ds.sort((a, b) => a - b);
    const l = ds[(N / 2) - 1];
    const r = ds[(N / 2)];
    const ans = r - l;
    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 28380
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
#from __future__ import print_function, division    #while using python2
# from itertools import accumulate
# from collections import defaultdict, Counter

def modinv(n,p):
    return pow(n,p-2,p)

def main():
    #sys.stdin = open('input.txt', 'r')
    #sys.stdout = open('output.txt', 'w')

    n = int(input())
    coords = []
    for i in range(n):
        coords.append([int(x) for x in input().split()])
    
    r = int(1e9)
    x1, y1 = [0, 0]
    x2, y2 = [r, 0]
    x3, y3 = [0, r]
    x4, y4 = [r, r]

    d1 = []
    d2 = []
    d3 = []
    d4 = []
    
    for x, y in coords:
        d1.append(abs(x-x1) + abs(y - y1))
        d2.append(abs(x-x2) + abs(y - y2))
        d3.append(abs(x-x3) + abs(y - y3))
        d4.append(abs(x-x4) + abs(y - y4))

    d1.sort()
    d2.sort()
    d3.sort()
    d4.sort()

    # print(*d1)
    # print(*d2)
    # print(*d3)
    # print(*d4)

    print(max(d1[-1] - d1[0], d2[-1] - d2[0], d3[-1] - d3[0], d4[-1] - d4[0]))


#------------------ Python 2 and 3 footer by Pajenegod and c1729-----------------------------------------
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

if __name__ == '__main__':
   main()


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

int main(void) {
  char c;
  cin >> c;

  if (c == 'a'||c == 'e'||c == 'i'||c =='o'||c =='u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())

ans = 0
l, r = 0, 0
x, s = 0, 0
while r < N:
    s += A[r]
    x ^= A[r]
    if s == x:
        ans += (r-l+1)
        r += 1
    else:
        while s != x:
            s -= A[l]
            x ^= A[l]
            l += 1
        ans += (r-l+1)
        r += 1
print(ans)

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

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, x;

int main()
{
    cin >> n >> x;
    int cnt = 0;
    while(n){
        n /= x;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	wrln(min(A, B) + min(C, D));
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)


using namespace std;



int main(){
	bool prime[1000001];
	rep(i, 1000001){
		prime[i] = true;
	}
	prime[0] = prime[1] = false;

	loop(i, 2, 1001){
		if (prime[i]){
			for (int j = i * 2; j < 1000001; j += i){
				prime[j] = false;
			}
		}
	}



	int ord;
	while (cin >> ord){
		int small, big;
		loop(i, ord+1, 1000001){
			if (prime[i]){
				big = i;
				break;
			}
		}
		for (int i = ord-1; i > 0; i--){
			if (prime[i]){
				small = i;
				break;
			}
		}

		cout << small << " " << big << endl;
	}

}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

vector<int> sieve(int n) {
	vector<int> res;
	vector<bool> is_prime(n + 1, true);
	
	is_prime[0] = is_prime[1] = false;
	
	for (ll i = 2; i * i <= n; i++) if (is_prime[i]) {
		res.push_back(i);
		for (ll j = 1; i * j <= n; j++) is_prime[i * j] = false;
	}
	
	REP(i, n + 1) if (is_prime[i]) res.push_back(i);
	sort(res.begin(), res.end());
	return res;
}

int main() {
	
	auto prime = sieve(112345);
	vector<bool> is_prime(112345 + 1, false);
	for (int p : prime) is_prime[p] = true;
	
	
	vector<int> sum(112345);
	FOR(i, 1, 112345) {
		sum[i] = sum[i - 1];
		if (i % 2 == 0) continue;
		sum[i] += is_prime[i] && is_prime[(i + 1) / 2];
	}
	
	int Q;
	cin >> Q;
	while (Q--) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l - 1] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1152
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    s = list(input())
    a = len(s)
    if a%2==1:
        print('No')
        exit()
    for i, x in enumerate(s):
        if i%2==0:
            if x!='h':
                print('No')
                exit()
        else:
            if x!='i':
                print('No')
                exit()
    print('Yes')


if __name__ == '__main__':
    main()

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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n,m;
    cin >> n >> m;
    vector<string> a(n),b(m);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }
    for(int i = 0;i < m;i ++){
        cin >> b.at(i);
    }

    bool ans = false;

    for(int i = 0;i < n-m+1;i ++){
        for(int j = 0;j < n-m+1;j ++){
            for(int k = 0;k < m;k ++){
                if(a.at(i+k).substr(j,m) != b.at(k)){
                    break;
                }
                if(k == m-1){
                    ans = true;
                }
            }
        }
    }

    if(ans == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0; i<(n); i++)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;

const ll INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int l,r,d;
    cin>>l>>r>>d;
    int ans = 0;
    for(int i=l; i<=r; i++){
        if(i%d==0)ans++;
    }
    
    cout << ans <<endl;
    return 0;
}

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



int main(){
	int n; cin >> n;
	vector<bool> v(n);

	for(int i=0; i < n; i++){
		int x, y;
		cin >> x >> y;
		v[i] = (x == y);
	}
	
	bool flag = false;

	for(int i=0; i+2 < n; i++){
		flag |= v[i] && v[i+1] && v[i+2];
	}


	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3636
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine());
        int total = 0;
        int[] votes = new int[n];
        for (int i = 0; i < n; i++) {
            votes[i] = Integer.parseInt(st.nextToken());
            total += votes[i];
        }

        int necessaryVotes = (int)Math.ceil(1.0 * total / (4 * m));
        int canPrint = 0;
        for (int i = 0; i < n; i++) {
            if (votes[i] >= necessaryVotes) canPrint++;
        }

        System.out.println(canPrint >= m ? "Yes" : "No");
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X[] = new int[M];
		for (int i=0;i<M;i++) {
			X[i]= sc.nextInt();
		}
		if (N>=M){
			System.out.println(0);
			return;
		}
		Arrays.parallelSort(X);
		int space[] = new int[M-1];
		for (int i=1;i<M;i++) {
			space[i-1] = X[i]-X[i-1];
		}
		Arrays.parallelSort(space);
		int count =0;
		for (int i=0;i<M-N;i++) {
			count +=space[i];
		}
		System.out.println(count);
	}
}

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

int main() 
{
    int n;
    int pointT = 0, pointH = 0;
    string taro, hanako;


    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> taro >> hanako;

        int count = 0;                                      //文字が一致した回数を数える。

        if( taro.size() > hanako.size() )
            for( int j = 0; j < hanako.size(); j++ )
            {

                if( taro[j] > hanako[j] )
                {
                    pointT += 3;
                    break;
                }
                else if( taro[j] == hanako[j] )
                {
                    count++;
                    if( count == hanako.size() )
                        pointT += 3;
                }
                else
                {
                    pointH += 3;
                    break;
                }
            }
        else if( taro.size() < hanako.size() )
            for( int j = 0; j < taro.size(); j++ )
            {
                if( taro[j] > hanako[j] )
                {
                    pointT += 3;
                    break;
                }
                else if( taro[j] == hanako[j] )
                {
                    count++;
                    if( count == taro.size() )
                        pointH += 3;
                }
                else
                {
                    pointH += 3;
                    break;
                }
            }
        else
            for( int j = 0; j < hanako.size(); j++ )
            {
                if( taro[j] > hanako[j] )
                {
                    pointT += 3;
                    break;
                }
                else if( taro[j] == hanako[j] )
                {
                    count++;
                    if( count == hanako.size() )
                    {
                        pointT += 1;
                        pointH += 1;
                    }
                }
                else
                {
                    pointH += 3;
                    break;
                }
            }
    }
        cout << pointT << " " << pointH << endl; 
    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n,k;cin >> n >> k;
    vec<int> a(n);
    ll sum=0;
    rep(i,n)cin >> a[i];
    sort(all(a));
    if(k==0){cout << a[n-1] << endl;return 0;}
    function <int(int,int)>ans = [&](int l,int r){
        if(r-l==1)return r;
        int m=(l+r)/2;
        //答えをm以下にできるか判定
        //m以下にできるならもっと厳しい範囲に
        ll cnt=0;
        rep(i,n){
            cnt+=(a[i]+m-1)/m-1;
        }
        if(cnt<=k)return ans(l,m);
        else return ans(m,r);
        return 0;
    };
    cout << ans(0,a[n-1]) << endl;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))
        Yes
    else
        No
}
return 0;
}

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

const int N=200100;

priority_queue<int,vector<int>,greater<int> >pq1;
priority_queue<int>pq2;
vector<int>vecl[N],vecr[N],vec_del[N];
int n,m,q,a[N],b[N],c[N],sum[N],ans[N];
int tag1[N],tag2[N];
map<pair<int,int>,int>cnt;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;m=n+1;
	for(int i=1;i<=n;++i)cin>>a[i]>>b[i],b[i]=min(b[i],a[i]);
	for(int i=1;i<=m;++i)cin>>c[i],sum[i]=-1;
	sort(c+1,c+m+1);
	for(int i=1;i<=n;++i){
		a[i]=lower_bound(c+1,c+m+1,a[i])-c;
		b[i]=lower_bound(c+1,c+m+1,b[i])-c;
		++sum[a[i]];
		if(a[i]>b[i]){
			vecr[b[i]].push_back(a[i]-1);
			vecl[a[i]-1].push_back(b[i]);
		}
	}
	++sum[1];
	for(int i=1;i<=m;++i)sum[i]+=sum[i-1];
	int res=n;
	for(int i=m;i;--i){
		tag1[i]+=tag1[i+1];
		sum[i]+=tag1[i];
		for(int j:vecl[i])pq1.push(j),vec_del[j].push_back(i);
		while(sum[i]<0){
			if(!pq1.empty()&&pq1.top()<=i){
				int t=pq1.top();pq1.pop();
				int w=vec_del[t].back();vec_del[t].pop_back();
				--tag1[t-1];++tag1[i];++sum[i];
				--res;++cnt[make_pair(t,w)];
				++tag2[i+1];--tag2[w+1];
			}else{res=-2;break;}
		}
	}
	memset(tag1,0,sizeof tag1);
	ans[1]=res;
	for(int i=1;i<=m;++i){
		tag1[i]+=tag1[i-1];tag2[i]+=tag2[i-1];
		sum[i]+=tag1[i]+tag2[i];
		for(int j:vecr[i])
			if(cnt[make_pair(i,j)])--cnt[make_pair(i,j)];
			else pq2.push(j);
		if(!sum[i]){
			if(!pq2.empty()&&pq2.top()>=i){
				int t=pq2.top();pq2.pop();
				++tag1[i];--tag1[t+1];++sum[i];
				--res;
			}else res=-2;
		}
		ans[i+1]=res;
	}
	for(cin>>q;q --> 0;){
		int x,y;cin>>x>>y;
		x=lower_bound(c+1,c+m+1,x)-c;y=lower_bound(c+1,c+m+1,y)-c;
		res=max(ans[x]+1,ans[y]);res=max(res,-1);
		cout<<res<<'\n';
	}
	return 0;
}


Measured memory_bytes: 35960
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list  = new ArrayList<>();
        int sum = 0;

        for (int i = 0; i < n; i++){
            int a = sc.nextInt();
            list.add(a);
            sum += a;
        }

        int minDifference = sum;
        int calc = 0;

        for (int num : list){
            calc += num;

            if (Math.abs(sum - calc - calc) < minDifference){
                minDifference = Math.abs(sum - calc - calc);
            }
        }

        System.out.println(minDifference);
    }

}

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

	#define E "\n"
	#define int long long 
	#define f(i,l,n) for(int i=l;i<n;i++)

	int solve()
	{
		int n,m;
		cin >> n >> m;

		vector<int> v[n+1],h(n+1);
		f(i,1,n+1) cin >> h[i];

		f(i,0,m)
		{
			int x,y;
			cin >> x >> y;
			v[x].push_back(y);
			v[y].push_back(x);
		}

		int ans=0;

		for(int i=1;i<=n;i++)
		{
			if(v[i].size()==0) ans++;
			else
			{
				bool flg=true;
				for(auto it:v[i])
				{
					if(h[it]>=h[i]) flg=false;
				}
				if(flg) ans++;
			}
		}
		cout<<ans;


		return 0;
	}

	int32_t main()
	{

	 
	  int t=1;
	  //cin >>t;
	  while(t--) solve();

	}

Measured memory_bytes: 9856
n, x, y = gets.chomp.split(' ').map(&:to_i)
distances = Hash.new(0)
(1..n).each do |i|
  ((i + 1)..n).each do |j|
    route1 = j - i
    route2 = (x - i).abs + 1 + (y - j).abs
    distances[[route1, route2].min] += 1
  end
end
(1...n).each { |i| puts distances[i] }

Measured memory_bytes: 1916
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 998244353;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;

set<int> st;
int freq[N];

signed main(){
    fastio;
    int i,n,m,p,pen=0;
    cin>>n>>m;
    string s;
    for(i=0;i<m;++i){
        cin>>p>>s;
        if(s=="AC"){
            if(st.find(p)==st.end()) pen+=freq[p];
            st.insert(p);
        }
        else freq[p]++;
    }
    cout<<st.size()<<" "<<pen;
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    lli n, p;
    cin>>n>>p;
    string s;
    cin>>s;
    M = p;
    if(p != 2 && p != 5){
        vll mp(10005, 0);
        mp[0] = 1;
        lli curr = 0;
        loop(i, 0, n){
            lli temp = curr * 10 + (s[i]-'0');
            temp %= p;
            curr = temp;
            temp = power(10, n-i-1) * curr;
            temp %= p;
            mp[temp]++;
        }
        lli ans = 0;
        loop(i, 0, 10005)
            ans += (mp[i] * (mp[i]-1)) / 2;
        cout<<ans<<"\n";
    }
    else{
        lli count = 0;
        loop(i, 0, n){
            if((s[i] - '0') % p == 0)
                count += i+1;
        }
        // lli ans = (count * (count-1)) / 2;
        cout<<count<<"\n";
    }
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}

Measured memory_bytes: 720
#include <unistd.h>

int main()
{
    char buf[4] = {0};  // 入力バッファ（0で初期化）
    int N = 0;      // 入力された数値

    int len = 0;        // 入力された文字列の長さ
    int rank = 1;       // 位

    // 標準入力から4バイト読み込みバッファに格納
    read(0, buf, 4);

    // 入力された文字列の長さをはかる
    for (int i = 1; i < 4; i++) {
        if (buf[i] != 0) {
            len++;
        }
    }

    // Nに入力された数値を格納
    for (int i = len; i > 0; i--) {
        N += (int)((buf[i-1] - 0x30) * rank);   // 文字'0'はASCIIで0x30のため
        rank = rank * 10;
    }

    // 本題
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (N == (i * j)) {
                write(1, "Yes\n", 4);
                return 0;
            }
        }
    }

    write(1, "No\n", 3);

    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;

// ============union_find_tree===============
int MAX_N = 100000;
vector<int> par(MAX_N);//MAX_N == num of node
vector<int> tree_rank(MAX_N);

void init(int n)
{
  for (int i = 0; i < n; ++i)
  {
    par.at(i) = i;
    tree_rank.at(i) = 0;
  }
}

int find(int x)
{
  if (par.at(x) == x)
  {
    return x;
  }
  else
  {
    return par.at(x) = find(par.at(x));
  }
}

void unite(int x, int y)
{
  x = find(x);
  y = find(y);
  if (x == y)
  {
    return;
  }
  if (tree_rank.at(x) < tree_rank.at(y))
  {
    par.at(x) = y;
  }
  else
  {
    par.at(y) = x;
    if (tree_rank.at(x) == tree_rank.at(y))
    {
      tree_rank.at(x)++;
    }
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}

int main()
{
  int N, M, K;
  cin >> N >> M >> K;
  init(N);
  int A, B, C, D;
  vector<vector<int>> friend_or_block(N, vector<int>(0));
  for (int i = 0; i < M; ++i)
  {
    cin >> A >> B;
    friend_or_block.at(A - 1).push_back(B - 1);
    friend_or_block.at(B - 1).push_back(A - 1);
    unite(A - 1, B - 1);
  }
  for (int i = 0; i < K; ++i)
  {
    cin >> C >> D;
    if (same(C - 1, D - 1))
    {
      friend_or_block.at(C - 1).push_back(D - 1);
      friend_or_block.at(D - 1).push_back(C - 1);
    }
  }
  vector<int> connected_num(N, 0);
  for (int i = 0; i < N; ++i)
  {
    connected_num.at(find(i)) += 1;
  }

  for (int i = 0; i < N; ++i)
  {
    cout << connected_num.at(find(i)) - friend_or_block.at(i).size() - 1 << ' ';
  }
  cout << endl;
}


Measured memory_bytes: 8704