akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]



def main():
    a=LI()
    n=a[0]
    x=a[1]-1
    y=a[2]-1
    dist={}
    ans={}
    for i in range(n):
        dist[i]={}
        ans[i]=0
    for i in range(n):
        for j in range(i+1, n):
            dist[i][j]=min(j-i, 1+abs(j-y)+abs(i-x))
            ans[dist[i][j]]+=1
    for i in range(1,n):
        print(ans[i])
main()


Measured memory_bytes: 219092
n,m=map(int,input().split())
s=input()
s=s[::-1]
r,l,cnt,k,=0,0,0,0
ans=[]
while 1:
  while cnt<m:
    r+=1
    if r==n:
      ans.append(r-k)
      print(*ans[::-1])
      exit()
    if s[r]=='0':
      l=r
    cnt+=1
  if r-l==m:
    print(-1)
    exit()
  ans.append(l-k)
  k=l
  cnt=r-l

Measured memory_bytes: 6408
# coding: utf-8
# user: herp_sy

import math
import statistics

# fact(int)
def fact(n):
  if(n == 1):
    return 1
  else:
    return (n * fact(n - 1))

# gcd(int,int)
def gcd(a,b):
  if a == 0:
    return b
  elif b == 0:
    return a
  else:
    return gcd(b,a % b)

# lcm(int,int)
def lcm(a,b):
  return (a * b / gcd(a,b))

# qsort(array[])
def qsort(seq):
  if len(seq) < 1:
      return seq
  pivot = seq[0]
  left = []
  right = []
  for x in range(1, len(seq)):
    if seq[x] <= pivot:
        left.append(seq[x])
    else:
        right.append(seq[x])
  left = qsort(left)
  right = qsort(right)
  foo = [pivot]
  return (left + foo + right)

# , = map(int, input.split())
#  = int(input())
x = []
r,d,xs = map(int, input().split())
x.append(xs)
for i in range(0,10):
  x.append(r * x[i] - d)  
  print(x[i + 1])


Measured memory_bytes: 5144
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }
    int n;
    cin >> n;
    double ans = n * 2 * 3.14159265358979f;
    cout << ans << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3864
A,B,C,X,Y = map(int,input().split())
if X-Y>=0:
    print(min(A*X+B*Y,A*(X-Y)+C*2*Y,C*2*X))
else:
    print(min(A*X+B*Y,B*(Y-X)+C*2*X,C*2*Y))

Measured memory_bytes: 61848
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

// 二分累乗法
template <typename T>
T modpow(T a, T n, T mod) {
    T ret = 1;

    if (mod == 1) {
        while (n > 0) {
            if (n & 1) {
                ret = ret * a;
            }
            a = a * a;
            n >>= 1;
        }
    } else {
        while (n > 0) {
            if (n & 1) {
                ret = ret * a % mod;
            }
            a = a * a % mod;
            n >>= 1;
        }
    }

    return ret;
}

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

    string s;
    cin >> s;

    if (s.back() == 's') {
        s += "es";
    } else {
        s += 's';
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
#define N 100001
#define Q 50001

int S[N],T[Q],n,q,i,c=0,l,r,m,k;

int main() {	
  scanf("%d",&n);

  for(i=0; i<n; i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);

  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }

  for(i=0; i<q; i++){
    k = T[i];
    l = 0;
    r = n;

    while(l < r){
      m = (l + r) / 2;

      if(S[m]==k){
				c++;
				break;
			}
      else if(S[m]<k){
				l = m + 1;
				continue;
			}
      else if(S[m]>k){
				r = m;
				continue;
			}
    }
  }

  printf("%d\n",c);	
	
  return 0;
}



Measured memory_bytes: 2312
#include<bits/stdc++.h>
using namespace std;
int main(){
  long k,n,i,max=0;
  long a[n],b[n],c[n];
  scanf("%ld%ld",&k,&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }for(i=1;i<n;i++){
    b[i]=a[i]-a[i-1];
  }
  b[n]=a[0]+k-a[n-1];
  for(i=1;i<=n;i++){
    if(b[i]>max){
      max=b[i];
    }
  }
  cout<<(k-max)<<endl;
}

Measured memory_bytes: 7936
#include<iostream>
#include<map>
using namespace std;
int main()
{
	int n,i,t,cnt=0;
	cin>>n;
	map<int,int> mp;
	for(i=0;i<n;i++){
		cin>>t;
		if(mp[t]==0)	
			mp[t]=1;
		else mp[t]=0;
	}
	for(auto it:mp)
		if(it.second==1)
			cnt++;
	cout<<cnt<<endl;
	return 0;		
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mod 1000000007
#define setpres(x) fixed<<setprecision(x)
using namespace std;
int32_t main()
{
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<max({b*d,b*c,a*d,a*c});
    }
}


Measured memory_bytes: 3584
import sys
from heapq import heappush, heappop
sys.setrecursionlimit(10**6)

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

n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
k = 0

pqs = []
edge = [[] for _ in range(n)]
for i in range(m):
    x, y = [int(item) for item in input().split()]
    edge[x].append(y)
    edge[y].append(x)

def dfs(n):
    kind[n] = k
    heappush(pqs[k], a[n])
    for item in edge[n]:
        if kind[item] == -1:
            dfs(item)

kind = [-1] * n
for i, item in enumerate(kind):
    if item == -1:
        pqs.append([])
        dfs(i)
        k += 1

if k == 1:
    print(0)
    exit()
    
ans = 0
for i in range(k):
    val = heappop(pqs[i])
    ans += val
pqs = [flatten for inner in pqs for flatten in inner] 
pqs.sort()
for i in range(k-2):
    if i > len(pqs) - 1:
        print("Impossible")
        exit()
    ans += pqs[i]
print(ans)

Measured memory_bytes: 118336
#include<bits/stdc++.h>
using namespace std;
int main()
{
 
    long long int a,b,c,i;
    cin>>a>>b;
     c=__gcd(a,b);
     long long int ans=(a*b)/c;
 
    cout<<ans<<endl;
 
 
 
 
 
 
    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::cmp::min;

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<i32> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, k) = input_tuple();
    let v_vec = input_vec();

    let mut max = 0;
    for i in 0..min(n+1, k+1) { // 左から取る数
        for j in 0..min(n-i+1, k-i+1) { // 右から取る数
            let mut jewelries: Vec<i32> = Vec::new();
            let mut left = v_vec[..i].to_vec();
            let mut right = v_vec[n-j..].to_vec();
            jewelries.append(&mut left);
            jewelries.append(&mut right);
            jewelries.sort();
            let mut sum = 0;
            // println!("{}, {} -> {:?}", i, j, jewelries);
            for l in 0..(i+j) {
                if jewelries[l] < 0 && i + j + l + 1 < k + 1 {
                    continue;
                }
                sum += jewelries[l];
            }
            if sum > max {
                max = sum;
            }
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
    int a,b,c,tmp,res;
    cin >> a >> b >> c;
    
    //Rearrange a b c in ascending order:
    if (a > b) swap(a,b);
    if (b > c) swap(b,c);
    
    //Solution:
    tmp = 2*c-a-b;
    res = (tmp&1 ? tmp/2+2 : tmp/2);
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

void solve() {
    ll n; cin >> n;
    string s; cin >> s;
    Vl w(n, 0), e(n, 0);
    rep(i, 1, n) {
        w[i] = w[i-1];
        if(s[i-1] == 'W') w[i]++;
    }
    for(int i = n-2; i >= 0; i--){
        e[i] = e[i+1];
        if(s[i+1] == 'E') e[i]++;
    }
    // rep(i, 0, n) cout << w[i];
    // cout << endl;
    // rep(i, 0, n) cout << e[i];
    // cout << endl;
    Vl v(n, 0);
    rep(i, 0, n) v[i] = w[i] + e[i];
    ll ans = 1001001001;
    rep(i, 0, n) ans = min(ans, v[i]);
    cout << ans << endl;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 7700
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 2005;


int32_t main() {

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

    int N, M, C;
    cin >> N >> M >> C;

    vector<int> b(M);
    rep(i,M) cin >> b[i];

    int te, cnt = 0;
    rep(i,N) {
        int sum = 0;
        rep(j,M) {
            cin >> te;
            sum += te*b[j];
        }
        sum += C;
        if(sum > 0) cnt++;
    }
    cout << cnt << '\n'; 
}

Measured memory_bytes: 256
#include<stdio.h>
void swap(int *,int*);
int main(){
  int i,j,n,retu[100],sum=0;
  scanf("%d",&n);
  if(n>100)return 0;
  for(i=0;i<n;i++) scanf("%d",&retu[i]);
  
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(retu[j] < retu[j-1]) {
	swap(&retu[j],&retu[j-1]);
	sum++;
      }
    }
  }
  for(i=0;i<n-1;i++)printf("%d ",retu[i]);
  printf("%d",retu[n-1]);
  printf("\n%d\n",sum);
  return 0;
}

void swap(int *a,int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

Measured memory_bytes: 600
ac a b c w = case w of 'a' -> if null a then "A" else ac (tail a) b c (head a)
                       'b' -> if null b then "B" else ac a (tail b) c (head b)
                       'c' -> if null c then "C" else ac a b (tail c) (head c)
main=do
 [a,b,c]<-sequence[getLine,getLine,getLine]
 putStrLn$ac a b c 'a' 

Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) << endl ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }
vll fac(2,1),inv(2,1),finv(2,1) ;

void nCr_set(int n){
	for(int i=2;i<=n;i++){
		fac.push_back(fac.at(i-1)*i%mod) ;
		inv.push_back(mod-inv.at(mod%i)*(mod/i)%mod) ;
		finv.push_back(finv.at(i-1)*inv.at(i)%mod) ;
	}
}

ll nCr(ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}

ll nHr(ll n,ll r){
	return nCr(n+r-1,n-1) ;
}

int main(){
	ll r1,c1,r2,c2 ;
	cin >> r1 >> c1 >> r2 >> c2 ;
	ll ans = 0 ;
	nCr_set(r2+c2+10) ;
	auto f = [&](ll r,ll c){
		ll res = 0 ;
		for(int i=1;i<=c+1;i++) res = (res+nCr(r+i,i))%mod ;
		return res ;
	} ;
	ans = f(r2,c2)+(mod-f(r2,c1-1))+(mod-f(r1-1,c2))+f(r1-1,c1-1) ;
	cout << ans%mod << endl ;
}

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

int main(void)
{
	int n;
	int a,b;
	int asum,bsum;
	while(1)
	{
		cin >> n;
		if(n == 0)
			return 0;
		asum=0;bsum=0;
		for(int i=0;i<n;i++)
		{
			cin >> a >> b;
			if(a>b)
			{
				asum=asum+a+b;
			}
			if(b>a)
				bsum=bsum+a+b;
			if(a==b)
			{
				asum+=a;
				bsum+=b;
			}
		}
		cout << asum << ' ' << bsum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

#define PUT 0
#define REMOVE 1
#define CHECK_PLANE 2

int cnt;
int m[10][10];
int ans[10][10];

bool is_origin[10][10];
bool make_rect(int now,int x,int y,int width,int height,int flag,
	       int r,int c){
  rep(i,height){
    rep(j,width){
      if ( flag == PUT )m[y+i][j+x]=now;
      else if ( flag == REMOVE && is_origin[y+i][x+j] == false){
	m[y+i][j+x]=0;
      }else if (flag == CHECK_PLANE){
	if ( m[y+i][j+x]!=0 && m[y+i][j+x]!=now)return false;
      }
    }
  }
  return true;
}

void solve(int num,int now,int *number,int *x,int *y,int *size,int r,int c){
  if ( now == num){
    cnt++;
    rep(i,r)rep(j,c)ans[i][j]=m[i][j];
    return;
  }

  if ( cnt > 1)return;
  
  int cur=number[now];
  REP(k,1,size[now]+1){
    if ( size[now]%k != 0)continue;
    int h=k,w=size[now]/k;
    int hstart=max(0,y[now]-h+1),wstart=max(0,x[now]-w+1);
    REP(i,hstart,y[now]+1 && i+h <=r){
      REP(j,wstart,x[now]+1 && j+w <=c){
	if ( make_rect(cur,j,i,w,h,CHECK_PLANE,r,c) ){
	  make_rect(cur,j,i,w,h,PUT,r,c);
	  solve(num,now+1,number,x,y,size,r,c);
	  make_rect(cur,j,i,w,h,REMOVE,r,c);
	}
      }
    }
  }
}


main(){
  int c,r,n;
  while(cin>>c>>r>>n && c){
    pair<int,int> in[n];
    int x[n],y[n],size[n],tmp[100+1],num[100+1];
    rep(i,n)cin>>in[i].second>>in[i].first;
    sort(in,in+n,greater<pair<int,int> >());
    rep(i,n)tmp[in[i].second]=i,size[i]=in[i].first,num[i]=in[i].second;
    rep(i,r){
      rep(j,c){
	cin>>m[i][j];
	if ( m[i][j] != 0){
	  x[tmp[m[i][j]]]=j;
	  y[tmp[m[i][j]]]=i;
	  is_origin[i][j]=true;
	}
	is_origin[i][j]=false;
      }
    }
    cnt = 0;

    solve(n,0,num,x,y,size,r,c);
    if ( cnt == 1){
      rep(i,r){
	rep(j,c){
	  if ( j)cout << ' ';
	  cout <<ans[i][j];
	}
	cout << endl;
      }
    }else cout << "NA"<<endl;
  }
}

Measured memory_bytes: 868
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
K = line[1] * 1 
A = lines.shift().split(' ')

_Heap = {
  heap: [],
  compare: (a, b) => a < b,
  create(arr, desc) {
    this.heap = [0]
    if (desc) {
        this.compare = (a, b) => a > b
    }
    for(var i=0; i < arr.length; i++) {
      this.push(arr[i] * 1)
    }
  },
  push(v) {
    var idx = this.heap.length
    while(idx > 1) {
        var parent = ~~(idx / 2)
        if (this.compare(v, this.heap[parent])) {
            this.heap[idx] = this.heap[parent]
            idx = parent
        } else {
            break;
        }
    }
    this.heap[idx] = v
  },
  pop() {
    if (this.heap.length == 1) {
        return
    } else if (this.heap.length == 2) {
        return this.heap.pop()
    }
    
    var val = this.heap[1]
    var last = this.heap.pop()
    var idx = 1
    while(true) {
        var left = idx * 2
        var right = idx * 2 + 1
        var next = idx
        if (left < this.heap.length && this.compare(this.heap[left], last)) {
          next = left
        }
        if (right < this.heap.length
			&& this.compare(this.heap[right], last)
			&& this.compare(this.heap[right], this.heap[left])) {
          next = right
        }
        if (next != idx) {
          this.heap[idx] = this.heap[next]
          idx = next
        } else {
            break;
        }
    }
    this.heap[idx] = last
    return val
  }
}

_Heap.create(A, true)

for(i=0; i<K; i++) {
    a = _Heap.pop()
    _Heap.push(~~(a / 2))
}

sum = 0
for(i=1; i<_Heap.heap.length; i++) {
    sum += _Heap.heap[i]
}

console.log(sum)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;

const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;

/*
  filippos
  Contest : AtCoder DP contest
  Task : G - Longest Path
*/

int main(){
  cin.tie(0), cin.sync_with_stdio(0), cout.tie(0), cout.sync_with_stdio(0);

  int n, m; cin >> n >> m;
  vvi g(n);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
  }

  function<int(int)> dp = [&](int i){
    static vi memo(n, -1);
    if(memo[i] != -1) return memo[i];
    if(g[i].size() == 0) return 0;
    transform(g[i].begin(), g[i].end(), g[i].begin(), dp);
    return memo[i] = 1 + *max_element(g[i].begin(), g[i].end());
  };

  vi indexes(n); iota(indexes.begin(), indexes.end(), 0);
  transform(indexes.begin(), indexes.end(), indexes.begin(), dp);

  // for_each(indexes.begin(), indexes.end(), [](int i){cout << i << ' ';});
  // cout << '\n';

  cout << *max_element(indexes.begin(), indexes.end());

  return cout << endl, 0;
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>> dp(114514,vector<int>(3,0));
  cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
  for(int i=1;i<n;++i){
    int a,b,c;
	  cin>>a>>b>>c;
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
	  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
	  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
  }
  cout<<max({
    dp[n-1][0],
	  dp[n-1][1],
	  dp[n-1][2]
  });
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;

typedef struct{
    int time;
    bool ishuman;
    int point;
} info_0s; 

//区間に入る⇒人⇒区間に抜けるの順番でソートされるようにしたい
auto compare = [](const info_0s& a, const info_0s& b){ 
    if (a.time == b.time){
        return a.point < b.point;
    } else {
        return a.time > b.time;
    }
};
priority_queue<info_0s, vector<info_0s>, decltype(compare)> info(compare);

int main()
{
    int n, q;
    cin >> n >> q;
    rep(i, n){ 
        int tmp_s, tmp_t, tmp_x; 
        cin >> tmp_s >> tmp_t >> tmp_x; 
        info.push({tmp_s - tmp_x, false, tmp_x});
        info.push({tmp_t - tmp_x-1, false, -tmp_x});
    }
    rep(i, q){
        int tmp_d;
        cin >> tmp_d;
        info.push({tmp_d, true, 0});
    }

    set<int> bigger;
    while(!info.empty()){
        info_0s info_p = info.top();
        info.pop();
        //cout << info_p.time << ":"<< info_p.ishuman << ":"<< info_p.point <<bigger.size() <<endl;
        if (info_p.ishuman){
            if (bigger.size() != 0){
                cout << *bigger.begin() << endl;
            } else {
                cout << "-1" << endl;
            }
        } else {
            if (info_p.point > 0){
                bigger.insert(info_p.point);
            } else {
                bigger.erase(-info_p.point);
            }
        }


    }
}

Measured memory_bytes: 18024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll n, x;

ll solve() {
    ll res = x;
    ll p = n, q = n-x;
    if (p % q == 0) {
        res += (2*(p/q)-2) * q;
    } else {
        res += (2*(p/q)-1) * q;
    }
    ll r = p % q;
    p = q;
    q = r;
    while (q > 0) {
        if (p % q == 0) {
            res += (2*(p/q)-1) * q;
        } else {
            res += (2*(p/q)) * q;
        }
        r = p % q;
        p = q;
        q = r;
    }
    return res;
}

void input() {
    cin >> n >> x;
}

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

    input();
    cout << solve() << endl;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

bool X[200005];
bool Y[200005];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (a == 0)
            X[b] = true;
        if (b == N - 1)
            Y[a] = true;
    }

    string ans = "IMPOSSIBLE";
    REP(i, N)
    {
        if (X[i] && Y[i])
        {
            ans = "POSSIBLE";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
h = {
 'AG':1,
 'CG':1,
 'AGG':0,
 'aGG':1,
 'ATG':0,
 'aTG':1,
 'GA':1,
 'gA':3,
 'AC':1,
 'aC':3,
 'AT':1,
 'AGT':0,
 'aGT':1,
 'agT':2
}
for i in range(2,n):
    g = {}
    g['AG'] = h['GA']+h['gA']
    g['CG'] = h['aC']
    g['AGG'] = h['AG']
    g['aGG'] = h['CG']+h['AGG']+h['aTG']+h['aGG']+h['ATG']
    g['ATG'] = h['AT']
    g['aTG'] = h['AGT']+h['aGT']+h['agT']
    g['GA'] = h['AG']+h['CG']+h['AGG']+h['aTG']+h['aGG']+h['ATG']
    g['gA'] = h['GA']+h['gA']+h['AC']+h['aC']+h['AT']+h['AGT']+ \
             h['aGT']+h['agT']
    g['AC'] = h['gA']
    g['aC'] = h['AC']+h['aC']+h['AT']+ \
             h['aGT']+h['agT'] + \
             h['CG']+h['aTG']+h['aGG']
    g['AT'] = h['GA']+h['gA']
    g['AGT'] = h['AG']
    g['aGT'] = h['CG']+h['AGG']+h['aTG']+h['aGG']+h['ATG']
    g['agT'] = h['AC']+h['aC']+h['AT']+h['AGT']+ \
             h['aGT']+h['agT']
    h = g
sm = 0
for k in h:
    sm = (sm+h[k])%R
print(sm)


Measured memory_bytes: 38332
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > toys(M,vector<int>(N+1,0));
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		for (int j = 0; j < M; j++) {
			if (j == tmp-1) {
				toys[j][i + 1] += toys[j][i] + 1;
			}
			else {
				toys[j][i + 1] += toys[j][i];
			}
		}
	}
	
	vector<int> dp(1 << M, INF / 2); //集合Sを敷き詰めたときの動かすぬいぐるみ
	vector<int> top(1 << M, 0); //集合Sを敷き詰めたとき、次に動かす最初のぬいぐるみの位置
	dp[0] = 0;
	for (int i = 0; i < (1 << M); i++) {
		for (int j = 0; j < M; j++) { //次におくぬいぐるみ
			if (i & (1 << j)) continue; //既に置いてたらcontinue
			if (dp[i] + toys[j][N] - (toys[j][top[i] + toys[j][N]] - toys[j][top[i]]) < dp[i + (1 << j)]) {
				dp[i + (1 << j)] = dp[i] + toys[j][N] - (toys[j][top[i] + toys[j][N]] - toys[j][top[i]]);
				top[i + (1 << j)] = top[i] + toys[j][N];
			}
		}
	}
	cout << dp[(1 << M) - 1] << endl;
	return 0;
}


Measured memory_bytes: 18840
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n);
    double elem;
    F0R(i,n)
    {
        F0R(j,d)
        {
            cin >> elem;
            x[i].pb(elem);
        }
    }
    int count = 0;
    int val=0;
    // cout << "REACHED HERE" << endl;
    F0R(i,n)
    {
        FOR(j,i+1,n)
        {
            val=0;
            F0R(l,d)
            {
                val+=pow(x[i][l]-x[j][l],2);
            }
            if(val==pow((int)pow(val,.5),2))
            {
                count++;
                // cout << i << " " << j << endl;
            }
        }
    }
    cout << count;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main()
{
	int n,cnt=0;;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;;i++)
	{
		bool pd=true;
		for(int j=1;j<=n;j++) 
		{
			if(a[j]%2!=0)
			{
				pd=false;
				break;
			} 
		}
		if(pd==false)break;
		if(pd)
		{
			cnt++;
			for(int j=1;j<=n;j++)
				a[j]/=2;
		} 
	} 
	cout<<cnt; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace::std;
#define int long long int
#define MOD 1000000007
int n,k;
vector<vector<int>> v[64];

void multiply(int p,int o,int u){
	vector<vector<int>> tmp;
	for(int k=0;k<n;k++){
		vector<int> tp;
		for(int j=0;j<n;j++){
			int t=0;
			for(int i=0;i<n;i++)
				t=(t+((v[p][k][i]*v[o][i][j])%MOD))%MOD;
			// cout<<k<<' '<<j<<' '<<t<<'\n';
			tp.push_back(t);
		}
		tmp.push_back(tp);
	}
	v[u]=tmp;
}

main(){
	// ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		vector<int> t;
		for(int j=0,g;j<n;j++)
			cin>>g,t.push_back(g);
		v[0].push_back(t);
	}
	for(int i=1;i<64;i++)
		multiply(i-1,i-1,i);
	// return 0;
	int last=log2(k&(-k)),ans=0;
	for(k-=k&(-k);k;k-=k&(-k))
		multiply(last,log2(k&(-k)),log2(k&(-k))),last=log2(k&(-k));
	for(auto a:v[last])
		for(auto b:a)
			ans=(ans+b)%MOD;
	cout<<ans<<'\n';
}

Measured memory_bytes: 1664
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        int givenNumber = scan.nextInt();
        
        if (givenNumber >= 1 && givenNumber <= 100) {
            System.out.println((int)Math.pow(givenNumber, 3));
        }
    }
}


Measured memory_bytes: 26204
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

using namespace std;
using ll = long long;

void Main() {
	int n; cin >> n;
	string s; cin >> s;
	char prev = s[0];
	int res = 1;
	FOR(i, 1, n) {
		if (prev != s[i]) {
			++res;
			prev = s[i];
		}
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 10**9 + 7

H,W,K = map(int,readline().split())

"""
・長方形ピースに対して右上のセルがどれであるかに注目
・各xに対してx回目の操作がそのセルについて加点対象になる確率を求めればよい
"""

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

p1 = K
p2 = (K*(K+1)//2)
p3 = ((K-1)*K*(K+1)//3) * H*W * pow((H+W)*(H+W-1),MOD-2,MOD)
p = (p1 + p2 + p3) % MOD

x = np.arange(H+W,H+W-K,-1,dtype=np.int64)
answer = p * cumprod(x,MOD)[-1] % MOD
print(answer)

Measured memory_bytes: 481112
#include <bits/stdc++.h>
using namespace std;
#define lli long long

int main() 
{
    string s;
    cin >> s;
    
    int ans = (s[0]=='R')?1:0;
    
    if(s[1]=='R') ans++;
    
    if(s[2]=='R' && s[2]==s[1]) ++ans;
    else if(s[2]=='R' && s[2]!=s[1]) ans=1;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  int a,b,c,d,e,ra,rb,rc,rd,re,mr,i;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&d);
  scanf("%d",&e);
  ra=a%10;
  rb=b%10;
  rc=c%10;
  rd=d%10;
  re=e%10;
  mr=11;
  if(mr>ra&&ra!=0){mr=ra;i=1;}
  if(mr>rb&&rb!=0){mr=rb;i=2;}
  if(mr>rc&&rc!=0){mr=rc;i=3;}
  if(mr>rd&&rd!=0){mr=rd;i=4;}
  if(mr>re&&re!=0){mr=re;i=5;}
  if(mr==11)mr=0;
  if(i!=1){a=((a+9)/10)*10;}
  else{a=(a/10)*10;}
  if(i!=2){b=((b+9)/10)*10;}
  else{b=(b/10)*10;}
  if(i!=3){c=((c+9)/10)*10;}
  else{c=(c/10)*10;}
  if(i!=4){d=((d+9)/10)*10;}
  else{d=(d/10)*10;}
  if(i!=5){e=((e+9)/10)*10;}
  else{e=(e/10)*10;}
  printf("%d\n",a+b+c+d+e+mr);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int x,y;
    cin>>x>>y;
    cout<<(x<=3?(4-x)*100000:0)+(y<=3?(4-y)*100000:0)+(x==1&&y==1?400000:0)<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

int main()
{
    ll n, k;

    ll a, b, c;
    ll ans = 0;

    scanf("%lld %lld", &n, &k);

    for (a = 1; a <= n; a++) {
        ll mod_k = a % k;

        b = k - mod_k;
        c = k - b;

        if ((a + b) % k == 0 && (b + c) % k == 0 && (a + c) % k == 0 &&
            a <= n && b <= n && c <= n) {

            ans += ((n - b) / k + 1) * ((n - c) / k + 1);

            if (b == 0) ans -= (n - c) / k + 1;
            if (c == 0) ans -= (n - b) / k + 1;
            //ans++;
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
ans = 0
s = []
for e in c:
    if c[e] >= 2:
        s.append(e)
    if c[e] >= 4:
        ans = max(ans,e*e)
s = sorted(s)
if len(s) < 2:
    print(0)
else:
    print(max(ans,s[-1]*s[-2]))


Measured memory_bytes: 68760
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}


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

int main(void){
    int N;
    cin >> N;
    float x;

    float ans = 0;
    for(int i = 0; i < N; i++){
        cin >> x;
        ans += 1 / x;
    }

    cout << 1 / ans << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    vector<ll> A(N), B(N);
    multimap<ll,ll> mp;
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
        mp.insert(make_pair(A[i],B[i]));
    }
    auto itr=mp.begin();
    ll num=0,ans=0;
    while(num<M){
        if(M-num>itr->second){
            ans+=itr->second*itr->first;
            num+=itr->second;
        }else{
            ans+=itr->first*(M-num);
            num+=M-num;
        }
        itr++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    int res = INF;
    
    for (int i = 0; i+k-1 < n; i++) {
        int l = x[i], r = x[i+k-1];
        res = min(res, abs(l) + abs(r - l));
        res = min(res, abs(r) + abs(r - l));
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
s = input()
n = len(s)
flag = 1
for i in range(n):
    if (i % 2 == 0) and (s[i] not in {'R', 'U', 'D'}):
        flag = 0
    if (i % 2 == 1) and (s[i] not in {'L', 'U', 'D'}):
        flag = 0
print('Yes' if flag else 'No')

Measured memory_bytes: 3060
a, b = gets.chomp.split.map(&:to_i)

status = 'Impossible'

if a % 3 == 0
  status = 'Possible'
elsif b % 3 == 0
  status = 'Possible'
elsif (a + b) % 3 == 0
  status = 'Possible'
end

puts status


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N>>M>>K;
    cout<<min(N*M,K)<<endl;
}

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

using lli = long long;

int main() {
	lli n, k;
	cin >> n >> k;

	vector<lli> A(n), F(n);
	for (int i = 0; i < n; ++i) cin >> A[i];
	for (int i = 0; i < n; ++i) cin >> F[i];

	sort(A.begin(), A.end());
	sort(F.rbegin(), F.rend());

	lli lo = 0, hi = (lli)2E12, mi;
	while (lo < hi) {
		mi = (lo + hi) >> 1;
		
		lli needTrain = 0;
		for (int i = 0; i < n; ++i) {
			if (A[i] * F[i] <= mi) continue;
			needTrain += A[i] - mi / F[i];
		}

		// cout << needTrain << endl;

		if (needTrain <= k) {
			hi = mi;
		}
		else {
			lo = mi + 1;
		}
	}

	cout << lo << "\n";
}

Measured memory_bytes: 3328
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int>h(n);
	rep(i,n)cin>>h[i];
	int sum=0;
	rep(i,n){
		if(h[i]>=k){
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ull binpowmod(ull x,ull y,ull p)/* (x^y)%p in O(log y) */{ull res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<int,int> x,pair<int,int> y)
{
    return x.second>y.second;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}

void solve()
{   
    int n;
    string s;
    cin>>n;
    cin>>s;
    ll cnt=0;
    for(int dist=1;dist<=n/2;dist++){
        if(2*dist>=n) break;
        else
        {
            for(int start=0;start+2*dist<n;start++){
                if(s[start]!=s[start+dist] && s[start]!=s[start+2*dist] && s[start+dist]!=s[start+2*dist])
                    cnt++;
            }
        }
    }
    map<char,ll> m;
    for(char c: s)
        m[c]++;
    ll ans;
    ans=m['R']*m['G']*m['B'];
    cout<<ans-cnt;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++)
    cin>>s.at(i);
  cin>>m;
  vector<string> t(m);
  for(int i=0;i<m;i++)
    cin>>t.at(i);
  
  int ans=0;
  vector<int> sum(n);
  
  for(int i=0;i<n;i++){
    string str=s.at(i);
    
    for(int k=0;k<n;k++){
      if(str==s.at(k))
        sum.at(i)++;
    }
    for(int l=0;l<m;l++){
      if(str==t.at(l))
        sum.at(i)--;
    }
  }
  for(int i=0;i<n;i++){
    if(sum.at(i)>ans)
      ans=sum.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  int n;
  cin>>n;
  int a[n],b[n],s=0,A=0,B=0;
  r(i,n)cin>>a[i]>>b[i];
  vector<P>v;
  r(i,n){
    v.push_back(P(a[i]+b[i],i));
  }
  sort(v.begin(),v.end(),greater<P>());
  r(i,n){
    if(i%2==0)A+=a[v[i].second];
    if(i%2==1)B+=b[v[i].second];
  }
  cout<<A-B<<endl;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
int mod;
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
int f[6010][3010],F[6010][2010];
const int maxn=6010;
int fact[6010],ifact[6010];
int C(int n,int m){return n<m?0:1ll*fact[n]*ifact[n-m]%mod*ifact[m]%mod;}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi()*3;mod=gi();
	f[0][0]=1;
	for(int i=0;i<n;++i)
		for(int j=0;j<=i&&j*3<=n;++j)
			if(f[i][j]){
				inc(f[i+1][j],f[i][j]);
				inc(f[i+1][j+1],1ll*f[i][j]*(i-2*j)%mod);
			}
	fact[0]=1;for(int i=1;i<=n;++i)fact[i]=1ll*fact[i-1]*i%mod;
	ifact[n]=pow(fact[n],mod-2);for(int i=n;i;--i)ifact[i-1]=1ll*ifact[i]*i%mod;
	F[0][0]=1;
	for(int i=0;i<n;++i)
		for(int j=0;j*3<=i;++j)
			if(F[i][j]){
				inc(F[i+1][j],F[i][j]);
				inc(F[i+1][j+1],2ll*F[i][j]*C(i-j*3,2)%mod);
			}
	int ans=0;
	for(int i=0;i*3<=n;++i){
		for(int j=0;j*3<=n-3*i;++j)
			inc(ans,1ll*F[n][i]*f[n-3*i][j]%mod);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 117120
#include <iostream>

int main() {
 
  int N;
  std::cin >> N;

  if(N%1000 == 0){
    std::cout << 0 << std::endl;
  }else {
    std::cout << 1000 - N%1000 << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 3636
char S[12];
char out[2<<20];
int outsz,Slen;
main()
{
	int N,K;
	scanf("%d%d ",&N,&K);
	gets(S);
	Slen=strlen(S);
	for(int i=0;i<N;i++)
	{
		if(i<K)
		{
			strcpy(out+outsz,S);
			outsz+=Slen;
		}
		else
		{
			out[outsz++]='7';
		}
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}


Measured memory_bytes: 2304
/*
ID: varunra2
LANG: C++
TASK: matchings
*/

#include<bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

int n;
VVI grid;
VI dp;

void init() {
  dp.resize(1 << n);
  grid.resize(n);
  for(int i = 0; i < n; i++) grid[i].resize(n);
  rep(i, 0, sz(dp)) dp[i] = 0;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("matchings.in", "r", stdin);
  freopen("matchings.out", "w", stdout);
#endif
  cin.sync_with_stdio(0); cin.tie(0);

  cin >> n;

  init();

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      cin >> grid[i][j];
    }
  }

  dp[0] = 1;
  for(int i = 1; i < (1 << n); i++) {
    int cur = __builtin_popcount(i) - 1;
    for(int j = 0; j < n; j++) {
      if(grid[cur][j] == 0) continue;
      if(i & (1 << j)) {
        dp[i] += dp[i - (1 << j)];
        if(dp[i] >= MOD) dp[i] -= MOD;
      }
    }
  }

  cout << dp[(1 << n) - 1] << '\n';

  return 0;
}


Measured memory_bytes: 11376
K = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
print(a[K-1])


Measured memory_bytes: 38256
<?php
fscanf(STDIN, '%d %d', $n, $k);
fscanf(STDIN, '%d %d %d', $r, $s, $p);
fscanf(STDIN, '%s', $t);

$cnt = [
    'r' => substr_count($t, 'r'),
    's' => substr_count($t, 's'),
    'p' => substr_count($t, 'p'),
];
$flg = array_fill(0, $n, 0);

for ($i = $n - 1; $i >= $k; $i--) {
    if ($flg[$i]) continue;
    if ($t[$i] == $t[$i-$k]) {
        $flg[$i-$k] = 1;
        $cnt[$t[$i]]--;
    }
}

$ans = $cnt['r'] * $p + $cnt['s'] * $r + $cnt['p'] * $s;
echo $ans.PHP_EOL;

Measured memory_bytes: 8696
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    P = LI()
    cor = sorted(P)
    for i in range(N):
        for j in range(N):
            ok = True
            for k,c in enumerate(cor):
                a = P[k]
                if k == i:
                    a = P[j]
                elif k == j:
                    a = P[i]
                if a!=c:
                    ok=False
                    break
            if ok:
                print("YES")
                exit()
    print("NO")
if __name__ == '__main__':
    main()

Measured memory_bytes: 39280
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 1000000000
#define MOD 1000000007
#define LOG 29
#define EPS 0.000000001
#define M 305
using namespace std;

int n;
int cur[3],ans[N],now[3],mark[N];
vector<int> v[N],w[3];

int nxt(int m) {

	mark[now[m]]=1;
	now[m]+=3;
	return now[m]-3;

}

void dfs(int node,int dad,int c) {

	w[c].pb(node);
	for(int i:v[node]) {
		if(i!=dad) {
			dfs(i,node,!c);
		}
	}

}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);	

	cin>>n;
	for(int i=1,x,y;i<n;i++) {
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	now[0]=3;
	now[1]=1;
	now[2]=2;
	for(int i=0;i<3;i++) {
		cur[i]=n/3+(n%3>=i && i);
	}
	dfs(1,0,0);
	if(sz(w[0])>sz(w[1]))
		swap(w[0],w[1]);
	int c=0;
	if(sz(w[0])>cur[0]) {
		c=1;		
	}	
	while(sz(w[0])) {
		int node=w[0].back();
		w[0].ppb();
		if(!cur[c]) c--;
		ans[node]=nxt(c);
		cur[c]--;
	}
	int ptr=1;
	for(auto x:w[1]) {
		while(mark[ptr]) ptr++;
		ans[x]=ptr;
		ptr++;
	}
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<" ";

}

Measured memory_bytes: 22516