akhauriyash/Code-Regression huggingface dataset:
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<vector<ll>> Matrix;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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);}

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

  ll r;
  cin >> r;
  cout << 3 * pow(r, 2) << endl;
  return 0;
}


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

int main()
{
    string st;
    cin>>st;
    int l=st.size();

    if(st[l-1] == 's' ){
        st+="es";
        cout<<st<<"\n";
    }else{
        st+='s';
        cout<<st<<"\n";
    }
}


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

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


Measured memory_bytes: 640
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

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

	int i, j;
	VInt b(N);
	FOR(i, 0, N) scanf("%d", &b[i]);
	VInt res(N);
	RFOR(i, N, 0)
	{
		RFOR(j, i + 1, 0) if (b[j] == j + 1) break;
		if (j == -1) break;
		b.erase(b.begin() + j);
		res[i] = j + 1;
	}

	if (i == -1)
		FOR(i, 0, N) printf("%d\n", res[i]);
	else
		printf("-1\n");
	return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll a; string _b; cin >> a >> _b;
    string b = "";
    rep(i, _b.size()) {
        if (_b[i] != '.') b.push_back(_b[i]);
    }
    ll c = stoi(b);
    cout << a * c / 100 << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
  int a,b,c,d,e;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  if(a==0){
   printf("1"); 
  }
  if(b==0){
   printf("2"); 
  }
  if(c==0){
   printf("3"); 
  }
  if(d==0){
   printf("4"); 
  }
  if(e==0){
   printf("5"); 
  }
  
 return 0; 
}

Measured memory_bytes: 1656
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    yes(M==N);
    return 0;
}

Measured memory_bytes: 3032
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool st[100100],visited[100100];
int a[100100],b[100100],ufp[100100],ufr[100100],d[100100],e[100100];

vector<P> g[100100],s;

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufp[i] = i;
		ufr[i] = 1;
	}
}

int ufind(int x){
	if(x != ufp[x]){
		ufp[x] = ufind(ufp[x]);
	}
	return ufp[x];
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return;
	}
	if(ufr[x]<ufr[y]){
		swap(x,y);
	}
	ufr[x] += ufr[y];
	ufp[y] = x;
}

void dfs(int v, int p=-1){
	int u,i;
	for(i=(g[v].l_ength()-1); i>=0; --i){
		u = g[v][i].first;
		if(u==p){
			continue;
		}
		d[u] = d[v]+1;
		e[u] = g[v][i].second;
		s.push_back(P(d[u],u));
		dfs(u,v);
	}
}

int main(void){
	int n,m,i,t;
	cin >> n >> m;
	ufinit(n);
	for(i=0; i<m; ++i){
		cin >> a[i] >> b[i];
		--a[i]; --b[i];
		st[a[i]] = (!st[a[i]]);
		if(ufind(a[i])==ufind(b[i])){
			continue;
		}
		unionf(a[i],b[i]);
		g[a[i]].push_back(P(b[i],i));
		g[b[i]].push_back(P(a[i],i));
	}
	if(m%2){
		cout << "-1" << endl;
		return 0;
	}
	dfs(0);
	sort(s.begin(),s.end(),greater<P>());
	for(i=0; i<n; ++i){
		if(st[s[i].second]){
			t = e[s[i].second];
			swap(a[t],b[t]);
			st[a[t]] = (!st[a[t]]);
			st[b[t]] = (!st[b[t]]);
		}
	}
	for(i=0; i<m; ++i){
		++a[i]; ++b[i];
		cout << a[i] << " " << b[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 18164
#include<stdio.h>

int main() {
    int a, b, c, d;

    scanf("%d %d %d %d", &a, &b, &c, &d);

    if(a * b > c * d) {
        printf("%d", a * b);
    } else {
        printf("%d", c * d);
    }
  
    return 0;
}


Measured memory_bytes: 128
def dfs(graph, start, visited):
    if visited[start] != -99999:
        return True

    stack = [start]
    visited[start] = 0#初期値を0に設定
    while stack:
        label = stack.pop()
        for nextnode, distance in graph[label]:
            if visited[nextnode] == -99999:#初めて訪れる場所なら座標を設定
                stack.append(nextnode)
                visited[nextnode] = visited[label] + distance
            elif visited[nextnode] != visited[label] + distance:#二回目以降なら一回目と同じかを確認，stackはとらない
                return False
    return True


N, M = (int(i) for i in input().split())

graph = [[] for i in range(N + 1)]#インデックス番号と実際の番号をあわせるためにN+1にする

for i in range(M):
    L, R, D = (int(i) for i in input().split())
    graph[L].append((R, D))
    graph[R].append((L, -1 * D))

visited = [-99999 for i in range(N + 1)]

flag = True
for i in range(1, N + 1):
    ans = dfs(graph, i, visited)
    if not ans:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 65972
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include <queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

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

int main(){
    ll a, b;
    cin >> a >> b;
    cout << a * b / gcd(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Union_Find_Tree{
	public:
	vi Par,Rank;
	Union_Find_Tree(int n){
		Par=Rank=vi(n);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		if(Rank[x]<Rank[y]) Par[x]=y;
		else{
			Par[y]=x;
			if(Rank[x]==Rank[y]) Rank[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){
		return Find_Par(x)==Find_Par(y);
	}
};

int n;
vp x,y;

int main(){
	cin>>n;
	x=y=vp(n);
	for(int i=0;i<n;i++){
		cin>>x[i].first>>y[i].first;
		x[i].second=i;
		y[i].second=i;
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	vip a;
	for(int i=1;i<n;i++) a.push_back({abs(x[i].first-x[i-1].first),{x[i].second,x[i-1].second}});
	for(int i=1;i<n;i++) a.push_back({abs(y[i].first-y[i-1].first),{y[i].second,y[i-1].second}});
	sort(a.begin(),a.end());
	Union_Find_Tree uft(n);
	ll res=0;
	for(int i=0;i<2*n-2;i++){
		ll c=a[i].first;
		P p=a[i].second;
		int v=p.first,u=p.second;
		if(!uft.Same(v,u)){
			uft.Unite(v,u);
			res+=c;
		}
	}
	cout<<res<<endl;
}

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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int n,k;
	string s;
	cin >> n >> k >> s;
	int c = 0;
	int sum = 0;
	for(int i = 0; i < n - 1; i++){
		if(s[i] != s[i + 1])c++;
	}
	cout << n - 1 - max(0,c - 2 * k) << endl;
	return 0;
}
 

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <climits>
#define mk make_pair
#define pb push_back
#define scanf scanf_s
//#define printf printf_s
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pos;
const ll N = 2010, MOD = 1000000007;

ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}

int bb(int v1) {
	if (v1 % 2 == 0)return v1 / 2 - 1;
	else return v1 / 2;
}

ll pw(ll a, ll b) {
	ll v = 1;
	for (; b > 0; b = (b >> 1), a = (a * a) % MOD) {
		if ((b & 1) > 0)v = (v * a) % MOD;
	}
	return v;
}


struct Comb {
public:ll frc[N + 1], rv[N + 1];
	  ll pw(ll v1, ll v2) {
		  ll v3 = 1;
		  for (; v2 > 0; v2 = (v2 >> 1)) {
			  if (v2 & 1)v3 = (v3 * v2) % MOD;
			  v1 = (v1 * v1) % MOD;
		  }
		  return v3;
	  }

	  void set() {
		  frc[0] = 1;
		  rv[0] = 1;
		  for (int i = 1; i < N; i++) {
			  frc[i] = (frc[i - 1] * i) % MOD;
			  rv[i] = pw(frc[i], MOD - 2);
		  }
	  }
	  ll comb(ll a, ll b) {
		  ll v1 = frc[a];
		  v1 = (v1 * rv[b]) % MOD;
		  v1 = (v1 * rv[a - b]) % MOD;
		  return v1;
	  }
};

double r;

int main() {
	cin >> r;
	printf("%.15f\n", r * 2 * 3.14159265358979323846);
	return 0;
}


Measured memory_bytes: 3776
import sys
from operator import sub

sys.setrecursionlimit(100000)


def dfs(s, visited):
    visited.add(s)
    for v in links[s]:
        if v not in visited:
            dfs(v, visited)


def solve():
    checked = set()
    for i in range(ls // 2 + 1):
        if i in checked:
            continue
        visited = set()
        dfs(i, visited)
        inner_total = sum(sd[k] for k in visited) % 26
        if inner_total != 0:
            return False
        checked.update(visited)
    return True


s = input()
sl = list(map(ord, s))
sd = list(map(sub, sl + [97], [97] + sl))
ls = len(s)
lsd = len(sd)

n = int(input())
links = [set() for _ in range(lsd)]

for i in range((ls + 1) // 2):
    links[i].add(ls - i)
    links[ls - i].add(i)
for a, b in (map(int, input().split()) for _ in range(n)):
    links[a - 1].add(b)
    links[b].add(a - 1)

print('YES' if solve() else 'NO')


Measured memory_bytes: 88604
n = int(input())
k = len(list(str(n)))


c = [[0] * 10 for _ in range(10)]


for k in range(1, n + 1):
    arr = list(map(int,list(str(k))))
    c[arr[0]][arr[-1]] += 1

    
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mx (1<<18)
int tr[mx*5];
int ar[mx+3];
void seg(int no,int s,int e,int ind){
    if(s==e){
        tr[no] = s;
        return;
    }
    int mid=(s+e)/2;
    if(mid>=ind)
    seg(no*2,s,mid,ind);
    else 
    seg(no*2+1,mid+1,e,ind);
    if(ar[tr[no*2]]>ar[tr[no*2+1]])tr[no] = tr[no*2];
    else tr[no] = tr[no*2+1];
}
int val;
int qu(int no,int s,int e,int st,int en, bool fl){
   // cout<<val<<endl;
    if(s>=st&&e<=en){
        return tr[no];
    }
    int mid = (s+e)/2;
    if(mid>=en)return qu(no*2,s,mid,st,en,fl);
    else if(mid<st)return qu(no*2+1, mid+1,e,st,en,fl);
    else
    {
        int pos= qu(no*2, s, mid,st,mid,fl);
        int pos1=qu(no*2+1,mid+1,e,mid+1,en,fl);
                //cout<<st<<" "<<mid<<" "<<en<<" "<<pos<<" "<<pos1<<endl;
        if(ar[pos]>ar[pos1])return pos;
        else return pos1;
    }
    
}
#define ll long long 
int main(){
   //cout<<(1<<18)<<endl;
    int n;
    //cin>>n;
    scanf("%d", &n);
    int m= (1<<n);
    set<pair<int,int> > st;
    for(int i=1;i<=m;i++){
        scanf("%d", &ar[i]);
        st.insert(make_pair(ar[i],i));
    }
    sort(ar+1,ar+m+1);
    int a[m+2];
    for(int i=1;i<=m;i++){a[i]=ar[i];  
        seg(1,1,m,i);
     } 
   // reverse(ar+1,ar+m+1);
    int ans[m+2];
    int l =1;
    ans[1]= ar[m];
    ar[m] = -1;
    seg(1,1,m,m);
    int cnt = 0;
    for(int i = 1;i<m;i*=2){
        for(int j=1;j<=i;j++){
            cnt++;
            int x = lower_bound(a+1,a+m+1,ans[j])-a;
            if(x>1){
                int ind = qu(1,1,m,1,x-1,1);
                if(ar[ind]!=-1){
                    ans[++l] = ar[ind];
                    ar[ind] = -1;
                    seg(1,1,m,ind);

                }
                else {
                    cout<<"No"<<endl;
                    return 0;
                }

            }
            else 
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
   // cout<<cnt<<endl;
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 18688
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (A, B, X) = Slice3<long>();
            if (A <= X && X <= A + B)
                WriteLine("YES");
            else
                WriteLine("NO");
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27536
#include<unordered_map>
#include<utility>
template<typename T>
class UnionFind {
 public:
  void unite(const T& a, const T& b) {
    auto x = find(a), y = find(b);
    if(rank_[x] < rank_[y]) std::swap(x, y);
    parent_[y] = x;
    if(rank_[x] == rank_[y]) rank_[x] += 1;
  }
  T find(const T& x) {
    if(!parent_.count(x)) {
      rank_[x] = 1;
      return parent_[x] = x;
    }
    return (parent_[x] == x) ? x : (parent_[x] = find(parent_[x]));
  }
 private:
  std::unordered_map<T, T> parent_;
  std::unordered_map<T, int> rank_;
};

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

using Vertex = int;
using Weight = long long;
struct Edge {Vertex u, v; Weight w, s;};

const Weight INF = 1e18;
const Weight MOD = 1e9 + 7;

void Kruskal(auto& E, auto& s) {
  vector<Edge*> mst = {&s};
  auto sum = s.w;
  UnionFind<Vertex> uf;
  uf.unite(s.u, s.v);

  for(auto& e: E) {
    if(uf.find(e.u) == uf.find(e.v)) continue;
    uf.unite(e.u, e.v);
    sum += e.w;
    mst.emplace_back(&e);
  }

  for(auto e: mst) e->s = min(e->s, sum);
}

Weight f(auto E, auto X) {
  auto C = count_if(begin(E), end(E), [X](auto e) {return e.s <= X;});
  auto res = 1ll;
  for(auto i=0; i<min(E.size(), E.size() - C + 1); ++i) res = (res << 1) % MOD;
  return res;
}

int main() {
  int N, M;
  cin >> N >> M;
  Weight X;
  cin >> X;
  vector<Edge> E;
  for(auto i=0; i<M; ++i) {
    Vertex U, V; Weight W;
    cin >> U >> V >> W;
    E.push_back({--U, --V, W, INF});
  }

  sort(begin(E), end(E), [](auto l, auto r) {return l.w < r.w;});
  for(auto& e: E) Kruskal(E, e);

  cout << (f(E, X-1) - f(E, X) + MOD) % MOD << endl;
}


Measured memory_bytes: 512
def solve(n, T):

    def gcd(a, b):
        if a > b:
            a, b = b, a
        while a % b != 0:
            a, b = b, a % b
        return b

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

    l = T.pop()
    for t in T:
        l = lcm(l, t)
    return l

_n = int(input())
_T = [int(input()) for _ in range(_n)]
print(solve(_n, _T))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll f(ll x){
  if(x==0){
    return 1;
  }
  else
    return x*f(x-1)%MOD;
}

int main() {
  ll n,m;
  cin >> n >> m;
  ll k=abs(n-m);
  if(k>=2){
    cout << 0 << endl;
  }
  else if(k==1){
    cout << f(n)*f(m)%MOD << endl;
  }
  else
    cout << 2*f(n)*f(m)%MOD << endl;
}

Measured memory_bytes: 1792
/**
 *   created: 16 November 2019  10:01:14
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define int long long
#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

vector< vi > adj;

int32_t main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n,m,l;
		cin>>n>>m>>l;
		vector< vector<int> > dist(n+1, vector<int>(n+1, INFLL));
		rep(i,1,n+1)
			dist[i][i] = 0;
		rep(i,0,m){
			int a,b,c;
			cin>>a>>b>>c;
			dist[a][b] = c;
			dist[b][a] = c;
		}	
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++)
					dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
			}
		}
		vector< vector<int> > dist2(n+1, vector<int>(n+1,INFLL));
		
		rep(i,1,n+1){
			rep(j,1,n+1){
				if(dist[i][j]<=l){
					dist2[i][j] = 1;
					// trace2(i,j);
				}
			}
		}
		rep(i,1,n+1)
			dist2[i][i] = 0;
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++){
					if(dist2[i][k]<INFLL && dist2[k][j]<INFLL)
						dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j]);
				}
		}
		int q;
		cin>>q;
		while(q--){
			int a,b;
			cin>>a>>b;
			if(dist2[a][b]==INFLL)
				cout<<-1<<endl;
			else
				cout<<dist2[a][b]-1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2048
#include<iostream>

using namespace std;

bool solve(int i, int n, int m, int A[]){
    if(i>n) return false;
    if(m==0) return true;
    return solve(i+1, n, m, A) || solve(i+1, n, m-A[i], A);


}
int main(){
    int n, m, q;
    cin >> n;
    int A[n];

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

    int B[q];
    for(int i=0; i<q; i++){
        cin >> B[i];
        if(solve(0, n, B[i], A)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

Measured memory_bytes: 3100
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int N;
    cin>>N;
    
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3604
#include<stdio.h>
main(){
  int i,p,q,n,x,taihi;
  int A[100001];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x = A[n-1];
  p=-1;
  for(i=0;i<n;i++){
    if(A[i]<= x){
      p++;
      taihi=A[p];
      A[p]=A[i];
      A[i]=taihi;
    }
  }
 
  for(i=0;i<n;i++){
    if(i==p)printf("[");
     printf("%d",A[i]);
    if(i==p)printf("]");
     if(i<n-1)printf(" ");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 5100000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7
vector<ll> fac(MAX), finv(MAX), inv(MAX);

int main(){
    ll n,K; cin >> n >> K;
    vl h(n);
    K = n-K;
    if(K==0){
        puts("0");
        return 0;
    }
    rep(i,n) cin >> h[i];
    vvl dp(n,vl(K,linf));
    rep(i,n) dp[i][0] = h[i];
    rep(i,n){
        rep(j,K-1){
            rep(k,i){
                chmin(dp[i][j+1], dp[k][j] + max(0LL, h[i]-h[k]));
            }
        }
    }
    ll ans = linf;
    rep(i,n) chmin(ans, dp[i][K-1]);
    cout << ans << endl;
}


Measured memory_bytes: 120448
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		Scanner scan = new Scanner(System.in);
		String word = "";		//???????????????string
		int[] shuffleBegin = new int[100]; //?????£?????????????§????
		String temp = "";
		String kansei = "";
		while(true){
			temp = scan.next();
			if(temp.equals("-")){
				break;
			}
			char[] targetChar = temp.toCharArray();
			int targetLength = temp.length();
			
			int shuffleTimes = scan.nextInt();
			for(int i=0; i<shuffleTimes; i++){
				shuffleBegin[i] = scan.nextInt();
			}
			
			for(int i =0;i<shuffleTimes; i++){
			word = "";
				for(int j=0; j<(targetLength - shuffleBegin[i]) ; j++){
					word = word + targetChar[j + shuffleBegin[i]];
				}
				
				for(int j=0; j<shuffleBegin[i]; j++){
					word = word + targetChar[j];
				}
				
			targetChar = word.toCharArray();
			kansei = word;

			}
			System.out.println(word);		
			
		}
	}
}

Measured memory_bytes: 45764
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int solve(string a, string b) {
	vector<int> cnt(26);
	for (auto ac : a) {
		for (auto bc : b) {
			if (ac != bc) {
				continue;
			}

			cnt[ac - 'a']++;
		}
	}

	int res = 0;
	for (auto v : cnt) {
		res += (v > 0);
	}

	return res;
}

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

	int n;
	string s;
	cin >> n >> s;

	int ans = 0;
	for (int i = 1; i < n; i++) {
		string a = s.substr(0, i);
		string b = s.substr(i);
		ans = max(ans, solve(a, b));
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    map<ll,ll> mp;
    ll n=s.size();
    rep(i,n){
        mp[s[i]-'a']++;
    }
    ll ans=n*(n-1)/2+1;
    for(auto i:mp){
        if(i.second>1){
            ans-=(i.second*(i.second-1)/2);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int k;cin >> k;
  string st = "1";
  for(int i=2;i<=k;i++){
    int ps = -1;
    for(int j=0;j<st.size();j++){
      if((j==st.size()-1||st[j]<=st[j+1]) && st[j]!='9'){
        ps = j;
        break;
      }
    }
    if(ps==-1){
      st += "0";
      ps = st.size()-1;
    }
    st[ps] = st[ps] + 1;
    ps--;
    while(ps>=0){
      st[ps] = max(st[ps+1]-1-'0',0) + '0';
      ps--;
    }
  } 
  reverse(ALL(st));
  cout << st << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 256
#a,b=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
flag=True
if a.count(0)>0:
  print(0)
  flag=False
ans=1
if flag:
  for i in range(n):
    ans*=a[i]
    if 10**18<ans:
      print(-1)
      flag=False
      break
if flag:
  print(ans)

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


int n,D;

int ans;

int main(){
	scanf("%d%d",&n,&D);
	while(n--){
		int x,y;scanf("%d%d",&x,&y);
		if(1LL*x*x+1LL*y*y<=1LL*D*D)++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int A = s.nextInt();
    int B = s.nextInt();
      if ( A+B >= A-B){
        if (A*B >= A+B){
          System.out.println(A*B);
        }
        if (A*B < A+B){
          System.out.println(A+B);
        }
      }
      if ( A+B < A-B){
        if (A*B >= A-B){
          System.out.println(A*B);
        }
        if (A*B < A-B){
          System.out.println(A-B);
        }
      }
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define SQ(x) ((x)* (x))

using namespace std;

// 円と線分の当たり判定 //
bool jES(int sx1, int sy1, int sx2, int sy2, int x, int y, int r) {
    int d2;
    int a,b, c;
	
	a = sy2 - sy1;
	b = sx1 - sx2;
	c = -1 * (a * sx1 + b * sy1);  
	// d = abs(a*x+b*y+c)/sqrt(a*a+b*b)
	d2 = SQ(a*x+b*y+c);
	if(d2 > r*r * (a*a + b*b)) return false;
	
	if(((sx2-sx1)*(x-sx1)+(sy2-sy1)*(y-sy1)>0) &&
	   ((sx1-sx2)*(x-sx2)+(sy1-sy2)*(y-sy2)>0))  return true;
	
	return false;
}


int main(void){
 
int n, m;
int w[110][3];
int tx,ty,sx,sy;
	
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		rep(i,n) cin >> w[i][0] >> w[i][1]>> w[i][2];
		
		cin >> m;
		rep(i,m){
			cin >> tx >> ty >> sx >> sy;
			bool ok = true;
			rep(j,n){
				if((SQ(tx-w[j][0]) + SQ(ty-w[j][1]) < SQ(w[j][2])) &&
				(SQ(sx-w[j][0]) + SQ(sy-w[j][1]) < SQ(w[j][2]))) ok=false;
				else if ((SQ(tx-w[j][0]) + SQ(ty-w[j][1]) > SQ(w[j][2])) &&
				(SQ(sx-w[j][0]) + SQ(sy-w[j][1]) < SQ(w[j][2]))) ok=true;
				else if ((SQ(tx-w[j][0]) + SQ(ty-w[j][1]) < SQ(w[j][2])) &&
				(SQ(sx-w[j][0]) + SQ(sy-w[j][1]) > SQ(w[j][2]))) ok=true;
				else  ok = jES(tx,ty,sx,sy,w[j][0],w[j][1],w[j][2]);
		//		cout << "test:::" <<(ok?  "Safe": "Danger") << endl;
				if(ok) break;
			}
			cout << (ok? "Safe": "Danger") << endl;
		}
	}
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int c,n,m;
int pass[200][200];

double d[200][20];
bool used[200][20];

int dijk(int s,int g){
    rep(i,200)rep(j,20){
        d[i][j]=INF;
        used[i][j]=false;
    }
    
    d[s][c]=0;
    
    while(1){
        int v=-1;
        int w=-1;
        rep(u,n){
            rep(i,c+1){
                if( !used[u][i] && (v==-1||d[u][i]<d[v][w]) )v=u,w=i;
            }
        }
        if(v==-1)break;
        
        used[v][w]=true;
        
        rep(u,n){
            d[u][w] = min(d[u][w] , d[v][w] + pass[v][u] );
//            cout<<"d["<<u<<"]["<<w<<"]="<<d[u][w]<<endl;
            if(w-1>=0 && pass[v][u]!=INF){
                d[u][w-1] = min(d[u][w-1] , d[v][w] + (pass[v][u]/2.0) );
//                cout<<"d["<<u<<"]["<<w-1<<"]="<<d[u][w-1]<<endl;
            }
        }
    }
    double ret=INF;
    rep(i,c+1){
        ret = min(ret,d[g][i]);
    }
    return ret;
}


int main(){
    int s,g;
    while(cin>>c>>n>>m>>s>>g){
        if(c==0&&n==0&&m==0&&s==0&&g==0)break;
        
        s--,g--;
        rep(i,200)rep(j,200)pass[i][j]=INF;
        rep(i,200)pass[i][i]=0;
        
        rep(i,m){
            int a,b,f;
            cin>>a>>b>>f;
            a--,b--;
            pass[a][b]=pass[b][a]=f;
        }
        
    cout<<dijk(s,g)<<endl;
    }
}

Measured memory_bytes: 1352
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(void)
{
    int n;
    string s;
    int w = 0;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'W')
            w++;
    }
    int cnt = 0;
    for (int i = n - w; i < n; i++)
    {
        if (s[i] == 'W')
            cnt++;
    }
    cout << w - cnt;
    return 0;
}

Measured memory_bytes: 3752
#include <stdio.h>

int main() {
  
  int a,b,c,d,e,f;
  float x,y;

  while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF) {
    x=(double)(c*e-b*f)/(double)(a*e-b*d);
    y=(double)(a*f-c*d)/(double)(a*e-b*d);
    if(x==-0) x=0;
    if(y==-0) y=0;
    printf("%.3f %.3f\n",x,y);
  }
  
  return 0;
}

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

int main()
{
    long K, N, tmp;
    cin >> K >> N;
    vector<long> a(N);
    for (long i = 0; i < N;i++){
        cin >> a.at(i);
    }
    // for (long i = 0; i < N ; i++)
    // {
    //     cout << a.at(i) << endl;
    // }
    tmp = a.at(N-1) - a.at(0);
    for (long i = 0; i < N - 1;i++){
        if((K-a.at(i+1)+a.at(i))<tmp){
            tmp = (K - a.at(i + 1) + a.at(i));
        }
    }

        cout << tmp << endl;
}

Measured memory_bytes: 1792
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))

for i in range(3):
    if a1[i] in b and a2[i] in b and a3[i] in b:
        print("Yes")
        exit()

if a1[0] in b and a1[1] in b and a1[2] in b:
    print("Yes")
    exit()
if a2[0] in b and a2[1] in b and a2[2] in b:
    print("Yes")
    exit()
if a3[0] in b and a3[1] in b and a3[2] in b:
    print("Yes")
    exit()

if a1[0] in b and a2[1] in b and a3[2] in b:
    print("Yes")
    exit()
if a1[2] in b and a2[1] in b and a3[0] in b:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include<ctime>
#include<math.h>
#include<string>
using namespace std;

int main(){
    int i,x;
    i = 1;
    cin >> x;
    while(x !=0){
    
    cout << "Case" << " "<< i << ": " << x << endl; 
    i++;
    cin >> x;

   
    }
     return 0;
}


Measured memory_bytes: 3084
X,Y = map(int,input().split())
price = 0
if X==1 and Y ==1:
  price+=1000000
else:
  if X ==1:
    price += 300000
  elif X ==2:
    price += 200000
  elif X ==3:
    price += 100000
  if Y ==1:
    price += 300000
  elif Y ==2:
    price += 200000
  elif Y ==3:
    price += 100000
print(price)


Measured memory_bytes: 3060
n = input()
li = list(map(int,input().split()))

ans = 0

for i in range(1,len(li) - 1):
    if li[i - 1] < li[i] < li[i + 1]:
        ans += 1
    if li[i + 1] < li[i] < li[i - 1]:
        ans += 1

print(ans)


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

int main()
{
ll n , k ;
cin >> n >> k ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}

rep(j,min(50LL,k)){
  vector<ll> v(n+1,0);
  rep(i,n){
    v[max(0LL,i-a[i])]++;
    v[min(n,i+a[i]+1)]--;
  }
  a[0]=v[0];
  rep(i,n-1)a[i+1]=a[i]+v[i+1];
}
for(auto an:a)cout << an << " ";
cout << endl;
return 0;
}

Measured memory_bytes: 6436
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


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


int main(){
  ll n; string s; cin >> n >> s; ll rcount = 0;
  ll bcount = 0; ll gcount = 0;
  
  for(ll i=0; i < n; i++){
    if(s[i] == 'R') rcount++;
    else if(s[i] == 'G') gcount++;
    else bcount++;
  }
  
  ll ans = rcount*bcount*gcount; 
  
   
  for(ll j=1; j <= (n-1)/2; j++){
    
  
    for(ll i=0; i <= n - 2*j - 1; i++){

        
    
      if((s[i]!=s[i+j])&&(s[i+j]!=s[i+2*j])&&(s[i+2*j]!=s[i])) ans--;
      
    }
    
  }
  cout << ans << endl;
  
}
  



Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    int s[10000],t[500];
    int i,j,n,q,c=0;

    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++) {
      for (j = 0; j < n; j++) {
        if (s[j] == t[i]) {
          c++;
          break;
        }
      }
    }

    printf ("%d\n",c);

    return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
	char c = getchar(); int w = 1; int x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	x *= w;
	return x;
}
inline ll readll() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	x *= w;
	return x;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};

int main(){
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0;i<s.size();i++)ans=(ans+(s[i]-'0'))%9;
    cout<<(ans%9==0?"Yes":"No")<<endl;
return 0;
}
/* stuff to remember
	* int overflow, array bounds
	* special cases (n=1? n=0?)
	* do something instead of nothing and stay organized
	* USE STATIC ARRAYS
	* DEFINING ARRAYS BEFORE main()
	* DO NOT DEFINE ARRAYS IN main()
	* USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;

int check(ll x){
  int res=1;
  while(1){
    if(x<=1)return res;
    x--;
    x=x-x/k;
    res++;
  }
}

ll bynary_search(){
  ll l=0,r=(ll)(1e18)+1;
  while(l<r){
    ll m=(l+r)/2;
    if(check(m)<n)l=m+1;
    else r=m;
  }
  return max(0LL,l-1);
}

int main(){
  cin>>n>>k;
  cout<<bynary_search()<<endl;
  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
  ll x;
  mint() : x(0) {
  }
  mint(ll x) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() {
    return mint() - *this;
  }
  bool operator<(const mint& a) {
    return x < a.x;
  }
  bool operator>(const mint& a) {
    return x > a.x;
  }
  bool operator<=(const mint& a) {
    return x <= a.x;
  }
  bool operator>=(const mint& a) {
    return x >= a.x;
  }
  bool operator==(const mint& a) {
    return x == a.x;
  }
  bool operator!=(const mint& a) {
    return x != a.x;
  }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}

void solve(istream& cin, ostream& cout) {
  ll n, k;
  cin >> n >> k;
  map<int, int> mp;
  REP(i, n) {
    ll a;
    cin >> a;
    a--;
    mp[i] = a;
  }
  vector<int> visited;
  map<ll, ll> vm;
  ll now = 0;
  ll cnt = 0;
  ll ini, rep;
  while (true) {
    if (!vm.count(now)) {
      vm[now] = cnt;
      cnt++;
    } else {
      ini = vm[now];
      rep = cnt - ini;
      break;
    }
    visited.push_back(now);
    ll next = mp[now];
    now = next;
  }
  if (k - ini < 0) {
    cout << visited[k] + 1 << endl;
  } else {
    ll pos = (k - ini) % rep;
    cout << visited[ini + pos] + 1 << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 25620
#pragma region Macros
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define REV(x) reverse(ALL(x))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define lwb(x,n) distance(x.begin(),lower_bound(ALL(x),(n)))
#define upb(x,n) distance(x.begin(),upper_bound(ALL(x),(n)))
#define fora(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#ifdef _MY_DEBUG
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define de(...) CHOOSE((__VA_ARGS__,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define de(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
template<class T = ll> using v = vector<T>;
template<class T = ll> using vv = vector<vector<T>>;
template<class T = ll> using vvv = vector<vector<vector<T>>>;
template<class T> bool maxi(T &a, const T &b){ if(a<b){a=b;return 1;}return 0;}
template<class T> bool mini(T &a, const T &b){ if(b<a){a=b;return 1;}return 0;}
template<class T> ll sumer(const T& a){ return accumulate(ALL(a),0LL); }
template<class T> void UNIQUE(vector<T> &a){ SORT(a);a.erase(unique(ALL(a)),a.end());}
template<class T, class U> ostream &operator<<(ostream &os, const pair<T,U> &pe) { os << pe.first << " " << pe.second; return os;}
template<class T> ostream &operator<<(ostream &os, const v<T> &ve) { rep(i,ve.size()) os<< (i?" ":"")<<ve[i]; return os;}
ll topbit(ll a) { return a==0?-1:63-__builtin_clzll(a);}
ll botbit(ll a) { return a==0?64:__builtin_ctzll(a);}
ll popcount(ll a) { return __builtin_popcountll(a);}
#define dame {cout<< retword <<"\n"; return;}
#pragma endregion
//--MODIFS---------------------------------
#pragma region Modifs
#define retword "-1"
#define MOD  1000000007
using P  = pair<ll,ll>;
using TP  = tuple<ll,ll,ll>;
#pragma endregion
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N;
    cin>>N;
    v<> A(N);
    rep(i,N) cin>>A[i];
    map<ll,ll> mp;
    ll ans=0;
    rep(i,N){
        ll now=i-A[i];
        ll kosu=mp[now];
        ans+=kosu;
        ++mp[A[i]+i];
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    // ifstream in("input.txt"); cin.rdbuf(in.rdbuf());
    // ofstream out("output.txt"); cout.rdbuf(out.rdbuf());
    cout << fixed << setprecision(15);
    // ll Qkai; cin>>Qkai; rep(QQ,Qkai) Main();
    Main();
}
//-----------------------------------------

Measured memory_bytes: 27364
#include<stdio.h>

int main()
{
    int a;
    scanf("%d",&a);
    int L=a/100;
    int R=a%100;
    if(1<=L&&L<=12){
    if(1<=R&&R<=12)printf("AMBIGUOUS\n");
    else printf("MMYY\n");
    }
    else{
        if(1<=R&&R<=12)printf("YYMM\n");
         else printf("NA\n");
         }
         return 0;
}


Measured memory_bytes: 128