akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];

  vector<int> color(n, -1);

  auto ok = [&](auto& f, int p, int u, int cur)->int{
    if (color[u] != -1) return color[u] == cur;
    color[u] = cur;
    int res = 1;
    for (int v = 0; v < n; v++) {
      if (s[u][v] == '0') continue;
      if (v == p) continue;
      res &= f(f, u, v, cur ^ 1);
    }
    return res;
  };

  auto calc = [&](int first){
    queue<int> que;
    vector<int> d(n, INF);
    d[first] = 0;
    que.push(first);
    int res = 0;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      res = max(res, d[u]);
      for (int v = 0; v < n; v++) {
        if (s[u][v] == '0') continue;
        if (d[v] != INF) continue;
        d[v] = d[u] + 1;
        que.push(v);
      }
    }
    return res;
  };

  if (!ok(ok,-1,0,0)) cout << -1 << endl;
  else {
    int res = 0;
    for (int i = 0; i < n; i++) res = max(res, calc(i));
    cout << res + 1 << endl;
  }
  return 0;
} 

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a * c <= b)cout << c << endl;
	else cout << b / a << endl;
	return 0;
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Raheem
//#include<bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<iomanip>
#include<stdlib.h>
#include<queue>
#include<map>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<string.h>
#include<deque>
#include<set>
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef pair<int, int> pii;
#define FF first
#define SS second
#define MP make_pair
#define mxN (int)2e5 + 2
#define sz(n) (int)(n).size()
#define fasterIO ios::sync_with_stdio(0); cin.tie(0);
ll gcd(ll a, ll b)
{
    if(b == 0LL) return a;
    return gcd(b, a % b);
}
ll bigmod(ll a, ll b, ll mod)
{
    if(b == 0LL) return 1LL;
    ll sq = bigmod(a, b/2LL, mod);
    sq = (sq * sq) % mod;
    if(b&1LL) return (sq * (a%mod)) % mod;
    return sq;
}
vi primes;
vi sieve(const int n)
{
    vi primes(n+1, 0);
    primes[1] = 1;
	for (int p = 2; p*p <= n; p++)
    {
        if (!primes[p])
        {
            for(int i = p*p; i <= n; i += p)
                primes[i] = p;
        }
    }
  	for(int i = 2; i <= n; i++)
        if(!primes[i]) primes[i] = i;
    return primes;
}
map<int, int> getDivs(int x)
{
    map<int, int> divs;
    while(x > 1)
    {
        int div = primes[x];
        int cnt = 0;
        while(x%div == 0){
            x /= div;
            cnt++;
        }
        divs[div] = cnt;
    }
    return divs;
}

#define SIZE 15000005
#define INF 1000000000

void solve()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
}
int main()
{
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 3196
H,W=map(int,input().split())
l=[]
for i in range(H):
  l.append(list(map(int,input().split())))
  
x,y=0,0
p=1
J=[]
ans=0
if(H,W)==(1,1):
  print(0)
else:
  while y<H:
    if y%2==0:
      if x<W-1:
        nx=x+1
        ny=y
      else:
        nx=x
        ny=y+1
    else:
      if x>0:
        nx=x-1
        ny=y
      else:
        nx=x
        ny=y+1
    if l[y][x]%2==1:
      l[ny][nx]+=1
      ans+=1
      J.append((y+1,x+1,ny+1,nx+1))
    x,y=nx,ny
    if x==[0,W-1][H%2] and y==H-1:
      break

  print(ans)
  for a,b,c,d in J:
    print(a,b,c,d)

Measured memory_bytes: 26664
function main(input) {
  input=input.trim();
  var s = input.split("\n")[0]
  var t = input.split("\n")[1]
  const nagasa=s.length
  var ans=0;
  for(var i=0; i<nagasa; i++){
    s=s.charAt(nagasa-1)+s.slice(0,nagasa-1);
    //console.log(s);
      if(s==t){
        ans++
      }
    }
    
  if(ans>0||input.split("\n")[0]==t){
    console.log("Yes");
  }else{
    console.log("No");
  }
}

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



Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, a[101] = {};
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i], a[i] += a[i - 1];

    int ans = 2147483647;
    for (int i = 1; i <= n; i++)
        ans = min(ans, abs(a[n] - a[i] - a[i]));
    cout << ans << '\n';

    return 0;
}


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 2000010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int X1,X2,X3,X4,X5,X6;
int Y1,Y2,Y3,Y4,Y5,Y6;

int ans;

int fac[maxn],inv[maxn];

int C(int n,int m){
	return 1ll*fac[n+m]*inv[n]%mod*inv[m]%mod;
}

int calc(int x1,int y1,int x2,int y2){
	return (1ll*C(x2+1,y2+1)+C(x1,y1)-C(x1,y2+1)-C(x2+1,y1)+mod+mod)%mod;
}

void Work(){
	REP(i,X3,X4){
		int x=i,y=Y3;
		int t=1ll*calc(x-X2,y-Y2-1,x-X1,y-Y1-1)*calc(X5-x,Y5-y,X6-x,Y6-y)%mod;
		ans=(ans-1ll*(x+y)*t%mod+mod)%mod;
	}
	REP(i,Y3,Y4){
		int x=X3,y=i;
		int t=1ll*calc(x-X2-1,y-Y2,x-X1-1,y-Y1)*calc(X5-x,Y5-y,X6-x,Y6-y)%mod;
		ans=(ans-1ll*(x+y)*t%mod+mod)%mod;
	}
	REP(i,X3,X4){
		int x=i,y=Y4;
		int t=1ll*calc(x-X2,y-Y2,x-X1,y-Y1)*calc(X5-x,Y5-y-1,X6-x,Y6-y-1)%mod;
		ans=(1ll*(x+y+1)*t+ans)%mod;
	}
	REP(i,Y3,Y4){
		int x=X4,y=i;
		int t=1ll*calc(x-X2,y-Y2,x-X1,y-Y1)*calc(X5-x-1,Y5-y,X6-x-1,Y6-y)%mod;
		ans=(1ll*(x+y+1)*t+ans)%mod;
	}
	iout(ans);
}

void Init(){
	read(X1,X2);read(X3,X4);read(X5,X6);
	read(Y1,Y2);read(Y3,Y4);read(Y5,Y6);
	fac[0]=1;REP(i,1,2000000)fac[i]=1ll*fac[i-1]*i%mod;
	inv[2000000]=fexp(fac[2000000],mod-2);RREP(i,2000000,1)inv[i-1]=1ll*inv[i]*i%mod;
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 15872
a,b,c,d,e,f=map(int,input().split())
F=f//100
E=e/(e+100)
ans=[100*a,0]
W={i+j for i in range(0,F+1,a) for j in range(0,F+1,b)}
W=sorted(W)[1:]
for k in W:
    w=100*k
    for i in range(0,f+1,c):
        for j in range(0,f+1,d):
            s=i+j
            n=s/(w+s)
            if w+s>f or n>E: break
            if ans[1]/ans[0]<n:ans=[w+s,s]
print(ans[0],ans[1])

Measured memory_bytes: 3064
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll r, D, x2k;
    cin >> r >> D >> x2k;
    for (ll i = 1; i <= 10; i++)
    {
        x2k = r * x2k - D;
        cout << x2k << endl;
    }

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;

int main(int argc, char const *argv[]) {
    int N,M;
    cin>>N>>M;
    vector<int> /*x(M),y(M),*/c(N,1);
    set<int> s;
    s.insert(0);
    REP(i,M) {
        int x,y;
        cin>>x>>y;
        x--,y--;
        c[x]--;
        c[y]++;
        if(s.find(x)!=s.end()) { // xに赤球がある可能性がある
            if(c[x]==0) s.erase(x);
            s.insert(y);
        }
    }
    cout<<s.size()<<endl;
    return 0;
}

Measured memory_bytes: 5376
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut lucas: Vec<usize> = vec![2,1];
    if n > 1 {
        for i in 2..(n+1) {
            lucas.push(lucas[i-1] + lucas[i-2]);
        }
    }
    println!("{}", lucas[n])
}


Measured memory_bytes: 2204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FFOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int a[MAXN],b[MAXN];

signed main(){
	
	int n;cin >>n;
	rep(i,n) cin>>a[i]>>b[i];
	int cnt = 0;
	FFOR(i,n-1,0)
	{
		int nowa = a[i]+cnt;
		if(nowa == 0) continue;
		cnt+=((nowa-1)/b[i]+1)*b[i]-nowa;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int64_t firstcount=0;
  int64_t secondcount=0;
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(a.at(i)>a.at(j)){
        firstcount++;
      }
    }
  }
  sort(a.begin(),a.end());
  int memo=0;
  for(int i=1;i<n;i++){
    if(a.at(i)!=a.at(i-1)){
    secondcount+=i;
      memo=i;
    }
    if(a.at(i)==a.at(i-1)){
      secondcount+=memo;
    }
  }
  int64_t end=((firstcount*k%1000000007)+secondcount*((k*(k-1)/2)%1000000007))%1000000007;
  cout<<end;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var A = ReadArrayInt();
            Array.Sort(A);
            var BC = new List<int[]>();
            for (int i = 0; i < M; i++)
            {
                input = ReadArrayInt();
                var B = input[0];
                var C = input[1];
                BC.Add(new int[] { B, C });
            }
            BC = BC.OrderByDescending(a => a[1]).ToList();
            var idx = 0;
            var ans = new long[N];
            foreach(var bc in BC)
            {
                for (int i = 0; i < bc[0]; i++)
                {
                    ans[idx] = bc[1];
                    idx++;
                    if (idx >= N) break;
                }
                if (idx >= N) break;
            }
            for (int i = 0; i < N; i++)
            {
                if (ans[i] < A[i]) ans[i] = A[i];
            }

            Console.WriteLine(ans.Sum());
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 33964
#include <bits/stdc++.h>
#define INF 1000000

using namespace std;

int h=0,w=0;
char arr[21][21];
int d[401][401];
int di[4] = {1, -1, 0, 0};
int dj[4] = {0, 0, 1, -1};

int cd(int i, int j)
{
	return i*w+j;
}

bool check(int i, int j)
{
	return (i>=0 && i<h && j>=0 && j<w && arr[i][j]=='.');
}

int main()
{
	cin >> h >> w;		
	for (int i=0; i<h; i++)
	{
		for (int j=0; j<w; j++)
		{
			cin >> arr[i][j];
		}
	}
	for (int i=0; i<h*w; i++)
	{
		for (int j=0; j<h*w; j++)
			d[i][j] = INF;
		d[i][i] = 0;
	}
	for (int i=0; i<h; i++)
	{
		for (int j=0; j<w; j++)
		{
			if (arr[i][j]=='.')
				for (int k=0; k<4; k++)
				{
					if (check(i+di[k], j+dj[k])){
						d[cd(i,j)][cd(i+di[k], j+dj[k])] = 1;
					}
				}
		}
	}	
	for (int k=0; k<h*w; k++)
	{
		for (int i=0; i<h*w; i++)
		{
			for (int j=0; j<h*w; j++)
			{
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	int Max=0;	
	for (int i=0; i<h*w; i++)
		for (int j=0; j<h*w; j++)
			if (arr[i/w][i%w]=='.' && arr[j/w][j%w]=='.' && d[i][j]!=INF)
				Max = max(Max, d[i][j]);
	cout << Max;
	return 0;
}



Measured memory_bytes: 896
#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 && cnt <2){
    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 && cnt < 2){
      REP(j,wstart,x[now]+1 && j+w <=c && cnt < 2){
	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 if (cnt == 0)cout << "NA"<<endl;
  }
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A[] = new int[3];
        A[0] = sc.nextInt();
        A[1] = sc.nextInt();
        A[2] = sc.nextInt();
        Arrays.sort(A);
        System.out.println(A[2] - A[0]);

    }
}

Measured memory_bytes: 22996
/*
author : seryu
title : ABC138E_"Strings of Impurity"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s,t;
	cin >> s >> t;
	int n = sz(s);
	int m = sz(t);
	map<char, int> mp;
	rep(i, n)mp[s[i]]++;
	rep(i, m)
	{
		if(mp[t[i]] == 0)
		{
			cout << -1 << endl;
			return;
		}
	}
	vector<vector<int>> alp(26);
	rep(i, n) alp[s[i]-'a'].push_back(i);
	ll ans = 0;
	int j = 0;
	while(j < m)
	{
		int i = ans % n;
		if(lower_bound(all(alp[t[j]-'a']), i)-alp[t[j]-'a'].begin() == sz(alp[t[j]-'a']))
		{
			ans += n-i;
		}
		else
		{
			int x = *lower_bound(all(alp[t[j]-'a']), i);
			ans += x+1-i;
			j++;
		}
	}
	cout << ans << endl;
	return;
}

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


Measured memory_bytes: 1228
# https://atcoder.jp/contests/abc058/tasks/arc071_b
# 定式化してみると、独立に計算できる部分と、
# 前処理で累積和を求めておけばループ内でO(1)に減る部分と、
# 愚直に計算する部分に減る
# 式変形の端の部分が若干間違っていたので注意

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


class ModInt:
    def __init__(self, x, MOD=10 ** 9 + 7):
        '''
        pypyじゃないと地獄みたいな遅さなので注意
        '''
        self.mod = MOD
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x, self.mod)
        else:
            return ModInt(self.x + other, self.mod)

    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x, self.mod)
        else:
            return ModInt(self.x - other, self.mod)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x, self.mod)
        else:
            return ModInt(self.x * other, self.mod)

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(self.x * pow(other, self.mod - 2, self.mod), self.mod)

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, self.mod), self.mod)
        else:
            return ModInt(pow(self.x, other, self.mod), self.mod)

    __radd__ = __add__

    def __rsub__(self, other):  # 演算の順序が逆
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x, self.mod)
        else:
            return ModInt(other - self.x, self.mod)

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x * pow(self.x, self.mod - 2, self.mod), self.mod)
        else:
            return ModInt(other * pow(self.x, self.mod - 2, self.mod), self.mod)

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, self.mod), self.mod)
        else:
            return ModInt(pow(other, self.x, self.mod), self.mod)


def read_ints():
    return list(map(int, read().split()))


from itertools import accumulate

n, m = read_ints()
X = read_ints()
Y = read_ints()
MOD = 10 ** 9 + 7


def mul_term(X: list, n):
    S = list(accumulate(reversed(X)))
    S.reverse()
    ret = ModInt(0)
    for i in range(n - 1):
        ret += S[i + 1] - (n - i - 1) * X[i]
    return ret


# print(mul_term(X, n), mul_term(Y, m))
print(mul_term(X, n) * mul_term(Y, m))


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


int main() {
    vector<int> ip;
    int a,b,c;
    cin >> a >> b >> c;
    ip.push_back(a);
    ip.push_back(b);
    ip.push_back(c);
    sort(ip.begin(),ip.end());
    for(int i=0; i<ip.size(); ++i) {
        if (i+1 == ip.size()) {
            cout << ip[i] << endl;
        }else{
            cout << ip[i] << " ";
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N;
    int x = 0;
    int ans = 0;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0; i<N; i++){
        if(S[i]=='I'){
            x++;
        }else if(S[i]=='D'){
            x--;
        }
        if(ans < x){
            ans = x;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;

 public class Main {
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String s = "";

        try {
            s = in.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        long x = Long.parseLong(s.split(" ")[0]);
        long y = Long.parseLong(s.split(" ")[1]);
        long kaisu = 0;

        if ((x >= 0 && y >= 0 ) || ((x < 0) && (y < 0))){
       if(y > x){
       kaisu = y - x;
       } else {
       if (y == 0){
       kaisu = x - y + 1;
       } else {
       kaisu = x - y + 2;
       }
       }
        } else {
       x = x * -1;
       if(y > x){
       kaisu = y - x + 1;
       } else {
       if (y == 0){
       kaisu = x - y;
       } else {
       kaisu = x - y + 1;
       }
       }
        }
        System.out.println(kaisu);
    }
 }

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+10;
int num[maxn];
int vis[maxn];
int fa[maxn];
vector<int>vec;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin >> n;
    LL K;
    cin >> K;
    for(int i = 1;i<=n;++i)
        cin >> num[i];
    int id = num[1];
    vis[1] = 1;
    while(!vis[id])
    {
        fa[num[id]] = id;
        vis[id] = 1;
        id = num[id];
    }
    int count  = 0;
    for(int i = 1;i<=n;++i)
    {
        if(vis[i])
            ++count;
    }
    if(id==1)
    {
        K%=count;
        int cnt = 0;
        id  = 1;
        //cout << K << "\n";
        while(cnt<K)
        {
            id = num[id];
            ++cnt;
        }
        cout << id << "\n";
    }
    else
    {
        int tmp  =id;
        int cnt = 0;
        id = 1;
        while(tmp!=id)
        {
            ++cnt;
            vec.push_back(id);
            id = num[id];
        }
        if(K<cnt)
            cout << vec[K];
        else{
            K-=cnt;
            vec.clear();
            vec.push_back(id);
            id = num[id];
            while(tmp!=id)
            {
                vec.push_back(id);
                id = num[id];
            }
            K%=vec.size();
            cout << vec[K] << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 6576
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0 , f = 1; char ch = getchar();
	while(ch < '0' || ch > '9')	{if(ch == '-')	f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int n , k;
typedef vector<int> vi;
vi a[6];
vi A;
inline vi inv(const vi &p)
{
	vi q(n);
	for(int i = 0;i < n;i ++) q[p[i]] = i;
	return q;
}
inline vi mul(const vi &p,const vi &q)
{
	vi r(n);
	for(int i = 0;i < n;i ++) r[i] = p[q[i]];
	return r;
}
inline vi ksm(vi a,ll b)
{
	vi res(n);
	for(int i = 0;i < n;i ++) res[i] = i;
	while(b)
	{
		if(b & 1) res = mul(res,a);
		a = mul(a,a); b >>= 1;
	}
	return res;
}
int main()
{
	n = read(); k = read() - 1;
	a[0].resize(n); for(int i = 0;i < n;i ++) a[0][i] = read() - 1;
	a[1].resize(n); for(int i = 0;i < n;i ++) a[1][i] = read() - 1;
	for(int i = 2;i < 6;i ++) a[i] = mul(a[i - 1],inv(a[i - 2]));
	if(k < 6)
	{
		for(int i = 0;i < n;i ++) printf("%d ",a[k][i] + 1); 
		return puts("") , 0;
	}
	A = ksm(mul(mul(a[1],inv(a[0])),mul(inv(a[1]),a[0])),k / 6);
	A = mul(mul(A,a[k % 6]),inv(A));
	for(int i = 0;i < n;i ++) printf("%d ",A[i] + 1);
	return puts("") , 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define int long long
#define LONG LLONG_MAX/3;
#define INT INT_MAX/3;
#define mod 1000000007
typedef long long ll;
using namespace std;

queue<int> q;
int i;

void mutu(int a,int b){
	if(a==0&&b==0){
		q.push(1);
		return ;
	}
	if(a+1==b){
		for(int i=a*b/2+1;i<=b*(b+1)/2;i++){
			q.push(i);
		}
		mutu(i-1,b-1);
		return ;
	}
	else{
		q.push((a+1)*(a+2)/2-b);
		mutu(a-1,b);
	}
}

int mypow(int a,int b){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1)*a%mod;
	return mypow(a,b/2)*mypow(a,b/2)%mod;
}
int kaijo(int n){
	int ans=1;
	for(int i=1;i<=n;i++){
		ans*=i;
		ans%=mod;
	}
	return ans;
}
int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}

signed main(){
	int a;
	i=1;
	cin>>a;
	for(;(i+1)*i/2<=a;i++){
		if(i*(i+1)/2==a){
			cout<<"Yes"<<endl<<i+1;
			mutu(i-1,i);
			f(j,a*2){
				if(j%i==0){
					cout<<endl<<i;
				}
				cout<<" "<<q.front();
				q.pop();
			}
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 7680
n, m = map(int, input().split())
num = [1] * n
red = [0] * n
red[0] = 1

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x]:
        red[y] = 1
    num[x] -= 1
    num[y] += 1
    if num[x] == 0:
        red[x] = 0

ans = 0
for i in range(n):
    if red[i]:
        ans += 1
print(ans)


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int a[100010], n, f[100010];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i];
        f[a[i]]++;
    }
    if (n % 2) {
        if (f[0] != 1) {
            cout << 0;
            return 0;
        }
        FOR(i,1,n-1)
            if (i % 2) {
                if (f[i]) {
                    cout << 0;
                    return 0;
                }
            }
            else {
                if (f[i] != 2) {
                    cout << 0;
                    return 0;
                }
            }
    }
    else {
        FOR(i,0,n-1)
            if (i % 2) {
                if (f[i] != 2) {
                    cout << 0;
                    return 0;
                }
            }
            else {
                if (f[i]) {
                    cout << 0;
                    return 0;
                }
            }
    }
    ll res = 1;
    FOR(i,1,n/2) res = res * 2 % base;
    cout << res;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector <int> left(n, 0);
  vector <int> right(n, 0);
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    left.at(l-1) = 1;
    right.at(r-1) = 1;
  }
  int tmp_left, tmp_right;
  rep(i, n) {
    if (left.at(i) == 1) {
      tmp_left = i+1;
    }
    if (right.at(n-1-i) == 1) {
      tmp_right = n-i;
    }
  }
  int ans = 0;
  if (tmp_right - tmp_left + 1 > 0) {
    ans = tmp_right - tmp_left + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1ll << 63

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, E, s = 0, a, b;
	ll c;
	cin >> num >> E;
	vector<tuple<int, int, ll>> edge(E);
	vector<ll> ans(num, INF);
	rep(i, E) {
		cin >> a >> b >> c;
		edge[i] = make_tuple(a - 1, b - 1, c);
	}
	ans[s] = 0;
	rep(a, E) {
		rep(i, E) {
			if (ans[get<0>(edge[i])] != INF)
				chmax(ans[get<1>(edge[i])],  ans[get<0>(edge[i])] + get<2>(edge[i]));
		}
	}
	c = ans[num - 1];
	rep(i, E) {
		if (ans[get<0>(edge[i])] != INF)
			chmax(ans[get<1>(edge[i])], ans[get<0>(edge[i])] + get<2>(edge[i]));
	}
	c -= ans[num - 1];
	if (c)
		printf("inf\n");
	else
		cout << ans[num - 1] << "\n";
	return 0;
}

Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
$s = intval(fgets(STDIN));

function f($b, $n){
    if($n < $b)return $n;
    return f($b, intdiv($n, $b)) + $n % $b;
}
if($n == $s){
    echo $n+1,"\n";exit;
}
//$bがsqrt($n)より小さい場合
for($i = 2, $I = sqrt($n); $i <= $I; $i++){
    if(f($i, $n) == $s){
        echo $i,"\n";exit;
    }
}
//$bがsqrt($n)以上の場合　上位桁を決め打つと下位の桁は決まる
$minB = 10**18;
for($p = 1, $P = sqrt($n); $p <= $P; $p++){
    $q = $s - $p;
    if(($n-$q) % $p != 0)continue;
    $b = ($n-$q)/$p;
    if($p >= $b)continue;
    if($q >= $b)continue;
    if($q < 0)continue;
    $minB = min($minB, $b);
}
if($minB == 10**18){
    echo -1,"\n";
}else{
    printf("%d\n", $minB);
}

Measured memory_bytes: 4728
from math import floor
s = input()
k = int(input())
if len(set(s)) == 1:
    print(floor(len(s) * k / 2))
    exit(0)
x = s[0]
y = 1
ans = 0
for i in s[1:]:
    if i == x:
        y += 1
    else:
        ans += floor(y / 2)
        x = i
        y = 1
ans += floor(y / 2)
if s[0] != s[-1]:
    print(ans * k)
else:
    x = s[0]
    y = 1
    for i in s[1:]:
        if x == i:
            y += 1
        else:
            a = y
            break
    y = 0
    for i in s[::-1]:
        if x == i:
            y += 1
        else:
            b = y
            break
    print(ans * k - ((floor(a / 2) + floor(b / 2) - floor((a + b) / 2)) * (k - 1)))

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;

int main(){
    ll h;
    cin >> h;
    ll ans=0,cnt=1;
    while(h>0){
        h/=2;
        ans+=cnt;
        cnt*=2;
    }
    cout << ans << endl;
    return 0;
}

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

int grid[200][200];

int check(int x,int y,int t,int s){
  int curP=0;
  for(int i=0;i<t;i++){
    for(int j=0;j<s;j++){
      if(grid[y+i][x+j]==1)curP++;
    }
  }
  return curP;
}

int main(){
  int n;
  int w,h;
  while(cin>>n,n){
    for(int i=0;i<200;i++){
      for(int j=0;j<200;j++){
	grid[i][j]=0;
      }
    }
    cin>>w>>h;
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      grid[--y][--x]=1;
    }

    int s,t;
    cin>>s>>t;
    int curP=0;
    int maxP=curP;
    for(int i=0;i<=h-t;i++){

      curP=check(0,i,t,s);
      //cout << "curP:" <<  curP << endl;
      maxP=max(maxP,curP);

      for(int j=0;j<w-s;j++){
	for(int k=0;k<t;k++){
	  if(grid[i+k][j]==1)curP--;
	  if(grid[i+k][j+s]==1)curP++;
	}
      maxP=max(maxP,curP);
      //cout << "i:" << i << " j:" << j << " curP:" <<  curP << endl;
      }
    } 
    cout << maxP << endl;
  }
  return 0;
}

Measured memory_bytes: 1316
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int b[30];
vector<vector<int> > G;

int dfs(int x,int u,int n){
  if(x<0)return n;
  int m=dfs(x-1,u|1<<x,n+1);
  bool f=false;
  for(auto e:G[x]){
    f|=!(b[e]&u)&&1<<x==(b[e]&-b[e]);
  }
  if(!f){
    m=min(m,dfs(x-1,u,n));
  }
  return m;
}

int main(){
  for(int x,y;cin>>x>>y,x|y;){
    G=vector<vector<int> >(x);
    for(int i=0;i<x;i++){
      b[i]=1<<i;
      G[i].push_back(i);
    }
    while(y--){
      int u,v;
      cin>>u>>v;
      b[u]|=1<<v;
      b[v]|=1<<u;
      G[v].push_back(u);
      G[u].push_back(v);
    }
    cout<<dfs(x-1,0,0)<<endl;
  }
}

Measured memory_bytes: 1216
def resolve():
    N, M = map(int, input().split())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    C = []
    D = []
    for __ in range(M):
        c, d = map(int, input().split())
        C.append(c)
        D.append(d)
    for i in range(N):
        count = abs(A[i]-C[0]) + abs(B[i]-D[0])
        ans = 1
        for j in range(1, M):
            if count > abs(A[i]-C[j]) + abs(B[i]-D[j]):
                count = abs(A[i]-C[j]) + abs(B[i]-D[j])
                ans = j+1
        print(ans)
resolve()

Measured memory_bytes: 9124
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			int[] ps = new int[N];
			int[] cs = new int[N];
			
			ps[0] = - 1; 
			
			for(int i = 1; i < N; i++) {
				final int p = sc.nextInt() - 1;
				
				ps[i] = p;
				cs[p]++;
			}
			
			for(int i = 0; i < N; i++) {
				System.out.println(cs[i]);
			}
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


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

typedef long long ll;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  int n; cin >> n;
  vector<ll> a (n);
  for (ll& x : a)
    cin >> x;
  sort(a.rbegin(), a.rend());
  ll res = a[0];
  int k = n - 2;
  for (int i = 1; i < n; i++) {
    if (k == 0) break;
    int x = min(k, 2);
    res += a[i] * x;
    k -= x;
  }
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 4764
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	int max = 1;
      	for(int i=2; i*i<=n; i++){
          int num = i;
          while (num <= n) {
				num *= i;
			}
			num /= i;
			max = Math.max(max, num);
        }
      	System.out.println(max);
	}
}


Measured memory_bytes: 35652
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

template <class T>
struct Union_find {
    /*
  T: integer(int, long longなど)
  n個の整数に対してunion find森を生成
  par: 親の配列 ex)par[x]はxの親
  rank: ランクの配列で、root以外は意味はない
  size_of: サイズの配列で、root以外は意味がない
  root(x): xの根を返す
  same(x, y): boolでxとyが連結かを返す
  size(x): xが含まれる木の要素数を返す
  unite(x, y): xが含まれる木とyが含まれる木を連結させる
  */
    vector<int> par;
    vector<int> rank;
    vector<int> size_of;

    Union_find(T n) : par(n), rank(n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            size_of.push_back(1);
        }
    }

    int root(T x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool same(T x, T y) {
        return root(x) == root(y);
    }

    int size(T x) {
        return size_of[root(x)];
    }

    void unite(T x, T y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rank[x] < rank[y]) {
            size_of[y] += size_of[x];
            par[x] = y;
        }
        else {
            size_of[x] += size_of[y];
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        return;
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<set<int>> cannot_make_friends_with(n);
    int a, b;
    Union_find<int> uf(n);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
        cannot_make_friends_with[a].insert(b);
        cannot_make_friends_with[b].insert(a);
    }
    int c, d;
    rep(i, k) {
        cin >> c >> d;
        c--;
        d--;
        if (uf.same(c, d)) {
            cannot_make_friends_with[c].insert(d);
            cannot_make_friends_with[d].insert(c);
        }
    }
    rep(i, n) {
    
        cout << uf.size(i) - cannot_make_friends_with[i].size() - 1;
        if (i != n - 1)
            cout << " ";
        else
            cout << endl;
    }
    return 0;
}

Measured memory_bytes: 25464
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=300001 ;
int main()
{
   fast ;
   ll n ;
   cin>>n ;
   string s ;
   cin>>s ;
   map<char,ll>mp ;
   mp.insert({'R',0}) ;
   mp.insert({'G',1}) ;
   mp.insert({'B',2}) ;

   ll d[n][3] ;
   for(ll i=0;i<n;i++)
   {
       for(ll j=0;j<3;j++)
        d[i][j]=0 ;
   }
   d[n-1][mp[s[n-1]]]++ ;
   for(ll i=n-2;i>=0;i--)
   {
       d[i][0]=d[i+1][0] ;
       d[i][1]=d[i+1][1] ;
       d[i][2]=d[i+1][2] ;

       d[i][mp[s[i]]]++ ;
   }
   ll ans=0 ;

   for(ll i=0;i<n-2;i++)
   {
       for(ll j=i+1;j<n-1;j++)
       {
          if(s[i]!=s[j])
          {
              ll f[3] ;
              memset(f,0,sizeof(f)) ;
              f[mp[s[i]]]=1 ;
              f[mp[s[j]]]=1 ;
              for(ll l=0;l<3;l++)
              {
                  if(f[l]==0)
                  {
                      ans+=d[j+1][l] ;
                      ll op=2*j-i ;

                      if(op<n&&mp[s[op]]==l)
                      {
                          ans-- ;
                      }
                      break ;
                  }
              }
          }
       }
   }

   cout<<ans ;

}



Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<pair<int, int>> W(N);
  for (int i = 0; i < N; i++){
    int A, B;
    cin >> A >> B;
    W[i] = make_pair(B, A);
  }
  sort(W.begin(), W.end());
  long long t = 0;
  bool ans = true;
  for (int i = 0; i < N; i++){
    t += W[i].second;
    if (t > W[i].first){
      ans = false;
    }
  }
  if (ans){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1792
#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;

ll A[200005];
map<ll, ll> Map;

int main()
{
    ll N, K;
    cin >> N >> K;
    REP(i, N)
    {
        cin >> A[i];
        A[i] = (A[i] - 1) % K;
    }

    vector<ll> v;
    v.push_back(0);
    {
        ll s = 0;
        REP(i, N)
        {
            s += A[i];
            s %= K;
            v.push_back(s);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    ll ans = 0;
    {
        vector<queue<ll>> q(v.size());
        ll s = 0;
        q[0].push(-1);
        REP(i, N)
        {
            s += A[i];
            s %= K;
            ll index = lower_bound(v.begin(), v.end(), s) - v.begin();
            while (!q[index].empty() && i - q[index].front() >= K)
                q[index].pop();
            ans += q[index].size();
            q[index].push(i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 137712
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
using namespace std;
#define REP(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define REP1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    int N;
    long long int sum=0;
    cin>>N;
    for(int i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e9))
#define pi (1.0*acos(-1))
#define M ((int)(258280327))
#define NN ((ll)(305))
#define N ((ll)(2e5+7))
#define eps 0
#define log 20


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;


typedef tree < ll,  null_type,  less < ll >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;

int curr[10], curc[10];

int x[] = {0,-1,0,1};
int y[] = {-1,0,1,0};

char s[N], t[N];

int main()
{
    string str;
    str = "LURD";
    int n, m, l;
    scanf("%d %d %d",&n,&m,&l);
    int r, c;
    scanf("%d %d",&r,&c);
    scanf("%s %s",s,t);
    for(int i = 0; i<4; i++){
        curr[i] = r;
        curc[i] = c;
    }

    for(int i = 0; i<l; i++){
        for(int j = 0; j<4; j++){
            if(s[i]==str[j]){
                curr[j] += x[j];
                curc[j] += y[j];
            }
            if(min(curr[j],curc[j])<1 || curr[j]>n || curc[j]>m){
                printf("NO\n");
                return 0;
            }
            if(t[i]==str[(j+2)%4]){
                curr[j] -= x[j];
                curc[j] -= y[j];
                if(min(curr[j],curc[j])<1 || curr[j]>n || curc[j]>m){
                    curr[j] += x[j];
                    curc[j] += y[j];
                }
            }

        }
    }

    printf("YES\n");
    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
ll a[100001];
vector<ll> vs;
map<ll,ll> tot;

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

  cin>>n;
  rep(i,n){
    cin>>a[i];
    vs.push_back(a[i]);
    tot[a[i]]++;
  }
  sort(all(vs)); uni(vs);
  if(vs.size()>3){
    cout<<"No"<<endl;
    return 0;
  }

  rep(i,vs.size())rep(j,vs.size()){
    bool ok=true;
    map<ll,ll> cnt=tot;
    ll b[3];
    b[0]=vs[i]; b[1]=vs[j]; b[2]=vs[i]^vs[j];
    rep(k,n){
      if(cnt[b[k%3]]==0)ok=false;
      cnt[b[k%3]]--;
    }
    if((b[0]^b[1]^b[(n-1)%3])!=0)ok=false;
    if(ok){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

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


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

#define mod 1'000'000'007
typedef long long ll;

template <typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << '\n';
}

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<bool> a(n);
    for (int i = 0; i < n; ++i)
    {
        char c;
        cin >> c;
        a[i] = c == '1';
    }
    vector<pair<int, int>> x;
    for (int i = 0; i < n; ++i)
    {
        if (a[i])
            continue;
        int s = i;
        while (i < n && !a[i])
            ++i;
        x.push_back({s, --i});
    }
    if (x.size() <= k)
    {
        cout << n << '\n';
        return;
    }
    //deb({x.size()});
    int first = 1, last = k;
    int ans = x[k].first;
    while (last < x.size())
    {
        int cnt = - x[first - 1].second;
        cnt += (last + 1 == x.size()) ? n - 1 : x[last + 1].first - 1;
        ans = max(ans, cnt);
        ++first;
        ++last;
    }
    cout << ans << '\n';
}

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

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

    return 0;
}


Measured memory_bytes: 896