akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=155;
int n,k,mo;
namespace solver1{
	int f[N][N];
	void solve(){
		int v1=n/2,v2=n-n/2;
		f[0][0]=1; k/=2;
		For(i,1,v2) For(j,0,k){
			f[i][0]=(f[i][0]+f[i-1][j])%mo;
			f[i][j+1]=(f[i][j+1]+f[i-1][j])%mo;
		}
		int ans1=0,ans2=0;
		For(j,0,k){
			ans1=(ans1+f[v1][j])%mo;
			ans2=(ans2+f[v2][j])%mo;
		}
		printf("%lld\n",1ll*ans1*ans2%mo);
	}
}
namespace solver2{
	int f[2][N][N][N];
	void solve(){
		int v=(k+3)/2,pre=0,suf=1;
		f[0][0][0][(n+3)/2]=1;
		For(i,1,n){
			int mx=min(v,i/2),val;
			For(p1,0,mx) For(p2,0,mx) For(p3,1,(n+3)/2)
				if (val=f[pre][p1][p2][p3]){
					int np1,np2,np3;
					np1=min(v,p2+1); np2=p1; np3=p3-(p2>=v);
					if (np1>=v&&np2) np3=min(np3,k+2-v-np2);
					if (np3) f[suf][np1][np2][np3]=(f[suf][np1][np2][np3]+val)%mo;
					np1=0; np2=p1; np3=(p2>=v?(n+3)/2:p3);
					if (np3) f[suf][np1][np2][np3]=(f[suf][np1][np2][np3]+val)%mo;
					f[pre][p1][p2][p3]=0;
				}
			swap(pre,suf);
		}
		int ans=0;
		For(p1,0,v) For(p2,0,v) For(p3,1,(n+3)/2)
			ans=(ans+f[pre][p1][p2][p3])%mo;
		printf("%d\n",ans);
	}
}
int main(){
	scanf("%d%d%d",&n,&k,&mo);
	if (k%2==0) solver1::solve();
	else solver2::solve();
}

Measured memory_bytes: 15616
#include<stdio.h>

int main(void){
  int n,i;
  char a[100],t[100];
  
  scanf("%d",&n);
  scanf("%s",a);
  scanf("%s",t);
  
  for(i=0;i<n;i++){
    printf("%c%c",a[i],t[i]);
  }
  
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int a;
	std::string s;
	std::cin >> a >> s;
	if(a < 3200) s = "red";
	std::cout << s << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff(i,n) for(i=0;i<n;i++)
int main()
{	
   ll t;
   t = 1;
   for(ll test=1;test<=t;test++)
    {
       ll i,j,n,k,p,f,ans=-1;
       cin>>n>>k;
	   ll brr[n],l=1,r=0;
	   ff(i,n)
	   {
		   cin>>brr[i];
		   r+=brr[i];
	   }
	   while(l<=r)
	   {
		   	ll mid=(l+r)/2;
		    ll c=0;
		    if(mid==0)
		    {
		    	break;
			}
		    ff(i,n)
		    {
		      	if(brr[i]%mid==0)
					c+=brr[i]/mid-1;
			    else
					c+=brr[i]/mid;  	
			}
			if(c<=k)
			{
			   	ans=mid;
			   	r=mid-1;
			}
			else
			{
				l=mid+1;
			}   
	   } 
	   cout<<ans<<endl;
    }
   return 0 ;
}

Measured memory_bytes: 5128
k = gets.to_i
if k % 2 == 0 || k % 5 == 0
  puts '-1'
else
  cnt = 1
  n = 7
  k.times do
    break if n % k == 0
    n = (n * 10 + 7) % k
    cnt += 1
  end
  puts cnt
end

Measured memory_bytes: 14320
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define M 1000000007
#define all(a) a.begin(), a.end()

int main(){
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
	int da = abs(x - a);
	int db = abs(x - b);
	if(da < db) puts("A");
	else puts("B");
	return 0;
}


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

static class Program
{
    static IEnumerable<long> Search(long n)
    {
        long d = n % 10;
        var values = new List<long> { n * 10 + d };
        if (d != 0) { values.Add(n * 10 + d - 1); }
        if (d != 9) { values.Add(n * 10 + d + 1); }
        values.Sort();
        return values;
    }

    static long Solve(int K)
    {
        var lists = new List<long>[10];
        lists[0] = new List<long> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        for (int i = 1; i < 10; ++i)
        {
            lists[i] = new List<long>();
            foreach (int v in lists[i - 1])
            {
                lists[i].AddRange(Search(v));
            }
        }
        var values = new List<long>();
        foreach (var list in lists) { values.AddRange(list); }
        return values[K - 1];
    }

    static void Main(string[] args)
    {
        int K = int.Parse(Console.ReadLine());
        Console.WriteLine(Solve(K));
        }
}


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

int n,S;
int a[3123];
long long dp[3123][3123];
long long MOD = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);

    cin>>n>>S;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        for(int s=0;s<=S;s++){
            dp[i][s] = dp[i-1][s];
            if(s-a[i]>0){
                dp[i][s] += dp[i-1][s-a[i]];
                dp[i][s]%=MOD;
            }
        }
        dp[i][a[i]]+=i;
        dp[i][a[i]]%=MOD;
    }
    long long res = 0;
    for(int i=1;i<=n;i++){
        res = (res+dp[i][S])%MOD;
    }
    cout << res;
}


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

int N, A, ans = 0;
int a, b, c, d, e, k;
vector<int> v;
int main(){
    cin >> a >> b;

    for(int i=0; i<2; i++){
	if(a>b){
	    ans += a;
	    a--;
	}else{
	    ans += b;
	    b--;
	}
    }    
	
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int s,f[4][4];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    in(f[1][1]);in(f[1][2]);in(f[2][2]);
    s=3*f[2][2];
    f[1][3]=s-f[1][1]-f[1][2];
    f[3][1]=s-f[2][2]-f[1][3];
    f[2][1]=s-f[1][1]-f[3][1];
    f[2][3]=s-f[2][1]-f[2][2];
    f[3][2]=s-f[1][2]-f[2][2];
    f[3][3]=s-f[1][3]-f[2][3];
    for(int i=1;i<=3;i++){
    	for(int j=1;j<=3;j++){
    		printf("%d ",f[i][j]);
		}
		printf("\n");
	}
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

main(){
  
  char s[100];
  char this[10]="this";
  char that[10]="that";
  char the[10]="the";

  while(fgets(s,sizeof(s),stdin)!=NULL){
  
    int n,i;
  
    n=strlen(s);
  
  
    while(1){

      int co=0;
      
      for(i=0;i<n;i++){
	if(97<=s[i] && 122>=s[i]){
	  s[i]--;
	  if(s[i]==96){
	    s[i]=122;
	  }
	}
      }
    
      for(i=0;i<n;i++){
	if(s[i]==this[0]){
	  if(s[i+1]==this[1]){
	    if(s[i+2]==this[2]){
	      if(s[i+3]==this[3]){
		co=1;
	      }
	    }
	    else if(s[i+2]==that[2]){
	      if(s[i+3]==that[3]){
		co=1;
	      }
	    }
	    else if(s[i+2]==the[2]){
	      co=1;
	    }
	  }
	}
      }

      if(co==1){
	break;
      }
      
    }
    printf("%s",s);
  }  
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

void solve()
{
	ll n;
	cin >> n;
	ll a[n],cf[n+1];
	memset(cf,0,sizeof(cf));
	for(ll i=0;i<n;i++)
	{
		cin >> a[i];
		cf[i+1]=cf[i]+a[i];
		// s=s+a[i];
	}
	ll ans=0,sum;
	for(ll i=0;i<n-1;i++)
	{
		sum=(cf[n]-cf[i+1])%mod;
		ans=ans+sum*a[i];
		ans=ans%mod;
	}
	cout << ans<<"\n";

}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("ouput.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 6644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
 
int main(){
    ll l,r;cin>>l>>r;
    vector<int> vec;
    int ans=2020;
    for(int i=l;i<=min(r,l+2040)-1;i++){
        for(int j=i+1;j<=min(r,l+2040);j++){
            ans=min(ans,((i%2019)*(j%2019))%2019);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 998244353;
const ll INF = 1e16;
const ll MAX_N = 600010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n, a, b, k;
    cin >> n >> a >> b >> k;

    init();

    ll ans = 0;
    exrep(x, 0, min(k/a, n)) {
        if((k - a*x)%b == 0) {
            ll y = (k - a*x)/b;
            ans += Comb(n, x)*Comb(n, y)%mod;
            ans %= mod;
        }
    }
    
    out(ans);
    re0;
}

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

template <typename T, typename K> struct P {
	T a;
	K b;
};

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, M;
	cin >> N >> M;
	int bi = pow( 2, M );
	cout << (ll)100 * bi * ( N - M ) + (ll)1900 * bi * M << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

#define rep(i, n) for(long long i=0;i<n;i++)
using ll = long long;
const ll INF = (1LL<<60);

int main(){

    string s, t; cin >> s >> t;
    ll a, b; cin >> a >> b;
    string u; cin >> u;

    if(u==s) a--;
    if(u==t) b--;

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define rep(i, n) for( int i = 0; i < n; i++ )
typedef vector<int> vec;

int main(){
    int r, c;
    cin >> r >> c;
    vector< vec > data(r+1, vec(c+1));
    vec s_c(c+1);
    fill(s_c.begin(), s_c.end(), 0);
    rep(i, r){
        int sum = 0;
        rep(j, c){
            cin >> data[i][j];
            sum += data[i][j];
            s_c[j] += data[i][j];
        }
        data[i][c] = sum;
        s_c[c] += sum;
    }
    rep(i, c+1){
        data[r][i] = s_c[i];
    }
    // cout << endl;
    rep(i, r+1){
        rep(j, c+1){
            if( j == 0 ) cout << data[i][j];
            else cout << ' ' << data[i][j];
        }
        cout << endl;
    }

}

Measured memory_bytes: 1256
# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


N = int(input())
L = list(map(int, input().split()))
L.sort()
bit = BIT(L[-1]*2+1)
bit.add(L[0]+L[1], 1)
total = 1
ans = 0
for k in range(2, N):
  ans += total - bit.sum(L[k])
  for j in range(k):
    bit.add(L[j]+L[k], 1)
    total += 1

print(ans)  


Measured memory_bytes: 74128
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 165, task D, 2020/05/02
//ms,
/*
講評
内側のif文はelseの方しか走らない。

*/

int f(int64_t x, int64_t A, int64_t B){
  return (A*x)/B - A*(x/B);
}

int main(void){
  int64_t A, B, N;
  cin >>A >>B >>N;

  if(N<B) cout<<f(N,A,B);
  else{
    if(f(B,A,B)<f(0,A,B)) cout <<f(B-1,A,B);
    else cout <<max(f((N/B)*B-1,A,B),f(N,A,B));
  }

  return 0;
}
/*
*/

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int K, N;
    cin >> K >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
        cin >> a.at(i);
    int max = a.at(0) + K - a.at(N - 1);
    for (int i = 0; i < N - 1; i++){
        if (a.at(i + 1) - a.at(i) > max)
            max = a.at(i + 1) - a.at(i);
    }
    int an = K - max;
    cout << an << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N   = 1e5+10;
#define rep(i,x,y) for (int i=x;i<=y;++i)
int n,a[N],flag;
signed main()
{
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	sort(a+1,a+1+n);reverse(a+1,a+1+n);
	rep(i,1,n) if (i+1>a[i+1]) 
	{
		for (int j=i+1;a[j]==i;++j)flag^=1;
	    flag|=a[i]-i&1;
	    break;
	}
	return printf("%s",flag?"First":"Second"),0;	
}

Measured memory_bytes: 640
a, b = map(int, input().split())
s = input()
count = 0

for i in range(a+b+1):
    if s[i] == "-":
        count += 1
        if i != a:
            print("No")
            exit()

if count != 1:
    print("No")
    exit()
else:
    print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	stack<int>p;
	stack<int>s;
	int n;
	
	while (cin >> n) {
		if (n == 0) {
			s.push(p.top());
			cout << s.top() << endl;
			p.pop();
		}
		else {
			p.push(n);
		}
	}
	
	return 0;
}

Measured memory_bytes: 3096
N,M,X=map(int,input().split())
C=[0]*N
A=[]
for i in range(N):
  x=list(map(int,input().split()))
  C[i]=x[0]
  A.append(x[1:])
ans=sum(C)+1
for i in range(2**N):
  summ=0
  x=[0]*M
  flag=True
  for j in range(N):
    if(i>>j & 1):
      for k in range(M):
        x[k]+=A[j][k]
      summ+=C[j]
  for k in range(M):
    if(x[k]<X):
      flag=False
  if(flag==True):
    ans=min(ans,summ)
if(ans<=sum(C)):
  print(ans)
else:
  print(-1)

Measured memory_bytes: 9248
from itertools import combinations

n, k = map(int, input().split())

if k > (n - 1) * (n - 2) // 2:
  print(-1)
else:
  print(n - 1 + (n - 1) * (n - 2) // 2 - k)
  for i in range(2, n + 1):
    print(1, i)
  comb = list(combinations([i for i in range(2, n + 1)], 2))
  for i, j in comb[:(n - 1) * (n - 2) // 2 - k]:
    print(i, j)

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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> inline ll lcm(T& a, T& b) {
    ll z = a * b;
    ll x = max(a, b);
    ll y = min(a, b);
    ll r = x % y;
    while (r != 0) {
        x = y;
        y = r;
        r = x % y;
    }
    return z / y;
}


int main() {
    /* input */
    int N;  cin >> N;
    vector<ll> a(N); rep(i, N) cin >> a[i];

    // 方針：少なくとも m = LCM-1 の時，f の各項が最大値を取るので，f は最大となる．
    // 　　　つまり，各項が a[i]-1 の時，ｆ は最大

    ll ans = 0;
    rep(i, N) {
        ans += a[i] - 1;
    }

    print(ans);

    return 0;
}


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

typedef long long lli;

const int MAXN = 4004;
struct S {
  lli sum;
  int a, b;
  bool operator < (const S &s) const {
    if(sum != s.sum) return sum < s.sum;
    if(a != s.a) return a > s.a;
    if(b != s.b) return b < s.b;
    return false;
  }
};

int N;
lli A[MAXN];
int dp[MAXN];
int prev[MAXN][MAXN];

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];

  vector<S> s;
  for(int i = 0; i < N; ++i) {
    lli sum = A[i];
    for(int j = i+1; j <= N; ++j) {
      s.push_back((S){sum,i,j});
      if(j < N) sum += A[j];
    }
  }
  sort(s.begin(), s.end());
  fill(dp, dp+MAXN, -1);
  dp[0] = 0;
  vector<int> ans;
  for(int i = 0; i < (int)s.size(); ++i) {
    int a = s[i].a;
    int b = s[i].b;
    if(dp[a] != -1 && dp[b] < dp[a] + 1) {
      dp[b] = dp[a] + 1;
      prev[dp[b]][b] = a;
    }
  }
  for(int c = dp[N], p = prev[dp[N]][N]; p; --c, p = prev[c][p]) {
    ans.push_back(p);
  }
  reverse(ans.begin(), ans.end());
  cout << ans.size()+1 << endl;
  for(int i = 0; i < (int)ans.size(); ++i) {
    cout << string((bool)i,' ') << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 134428
(let* ((n (read))
       (k (read))
       (p (make-array (list (1+ n))))
       (s (make-array (list (1+ n)) :initial-element 0))
       (ans 0))
  (loop :for i :from 1 :to k
        :do (let ((x (read)))
              (setf (aref p i) x)
              (incf (aref s k) (aref p i))))
  (setf ans (aref s k))
  (loop :for i :from (1+ k) :to n
        :do (let ((x (read)))
              (setf (aref p i) x)
              (setf (aref s i) (+ (aref s (1- i)) (aref p i) (- (aref p (- i k)))))
              (setf ans (max ans (aref s i)))))
  (format t "~F~%" (/ (+ ans k) 2)))


Measured memory_bytes: 79688
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, m, a[200000], b[200000], c[200000], s;
int main() {
	cin >> n >> m; for (int i = 1; i <= n - 1; i++)cin >> a[i];
	for (int i = 1; i <= m; i++) cin >> b[i]; b[0] = 1;
	for (int i = 1; i <= m; i++)b[i] += b[i - 1];
	for (int i = 1; i <= m; i++) { int J1 = b[i], J2 = b[i - 1]; if (J1 > J2)swap(J1, J2); c[J1]++; c[J2]--; }
	for (int i = 1; i <= n; i++)c[i] += c[i - 1];
	for (int i = 1; i < n; i++) { s += a[i] * c[i]; s %= 100000; }
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 4280
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	if(a>b){
	c=a-b;
	printf("%d\n",c);
	}
	else {
	c=b-a;
	printf("%d\n",c);
	}
	return 0;
}
	


Measured memory_bytes: 2124
#include<stdio.h>

int main(){
    char s1[100],s2[100],s3[100];
    scanf("%s %s %s",s1,s2,s3);
    char ans1,ans2,ans3;
    ans1=s1[0]-32;
    ans2=s2[0]-32;
    ans3=s3[0]-32;
    printf("%c%c%c\n",ans1,ans2,ans3);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int n;
int a[20];
int x[20][20];
int y[20][20];

int counter(int x) {
  if (x == 0) return 0;
  return counter(x >> 1) + (x&1);
}

int main () {
  cin >> n;
  rep(i,n) {
    cin >> a[i];
    rep(j,a[i]) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  int ans = 0;
  rep(b,1<<n) {
    bool ok = true;
    rep(i,n) {
      if (!(b&(1<<i))) continue;
      // 正直者の証言が矛盾しないか確認
      rep(j,a[i]) {
        //if ((b&(1<<x[i][j])) ^ y[i][j]) ok = false;
        if (((b>>x[i][j])&1) ^ y[i][j]) ok = false;
      }
    }
    if (ok) ans = max(ans, counter(b));
    //if (ok) debug(b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

#define PI (3.1415926535898)

int main(void) {

	int n;

	double x[100];
	double y[100];

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lf", &x[i]);
	}

	for (int i = 0; i < n; i++) {
		scanf("%lf", &y[i]);
	}

	double total1 = 0.0;
	double total2 = 0.0;
	double total3 = 0.0;
	double total4 = 0.0;
	for (int i = 0; i < n; i++) {
		double tmp = fabs(y[i] - x[i]);
		total1 += tmp;
		total2 += (tmp * tmp);
		total3 += (tmp * tmp * tmp);
		if (total4 < tmp) {
			total4 = tmp;
		}
	}
	total2 = sqrt(total2);
	total3 = cbrt(total3);

	printf("%lf\n", total1);
	printf("%lf\n", total2);
	printf("%lf\n", total3);
	printf("%lf\n", total4);


}

Measured memory_bytes: 2872
/*/**/

#include <bits/stdc++.h>

using namespace std;

int main() {
	long long n, x;
	cin >> n >> x;
	long long a = x;
	long long b = n - x;
	long long ans = a + b;
	while(a and b) {
		if(a > b) {
			swap(a, b);
		}
		ans += b / a * 2 * a;
		b %= a;
	}
	cout << ans - a << endl;
	return 0;
}


Measured memory_bytes: 256
n, W = map(int, input().split())
WV = []
for i in range(n):
    w, v = map(int, input().split())
    WV.append((w, v))

MAXV = 10**5+1
INF = 10**18
dp = [[INF]*(MAXV+1) for _ in range(n+1)]
dp[0][0] = 0
for i in range(n):
    w, v = WV[i]
    for j in range(MAXV+1):
        dp[i+1][j] = dp[i][j]
    for j in range(MAXV+1):
        if j+v <= MAXV:
            dp[i+1][j+v] = min(dp[i][j]+w, dp[i+1][j+v])
ans = 0
for i in range(n+1):
    for j in range(MAXV+1):
        temp = dp[i][j]
        if temp <= W:
            ans = max(j, ans)
print(ans)


Measured memory_bytes: 147356
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

s = input()
ans = []
for i in range(len(s)):
    ans.append('x')

print(''.join(ans))

Measured memory_bytes: 31220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int VMAX = 310;
const int EMAX = VMAX*(VMAX-1)/2;
const ll INF = 1e15;
int V,E,L;
vector<vector<ll> > d(VMAX,vector<ll> (VMAX,INF));

void warshall_floyd(){
  rep(k,V) rep(i,V) rep(j,V){
    ll dist = d[i][k] + d[k][j] <= L? d[i][k]+d[k][j] : INF;
    d[i][j] = min(d[i][j],dist);
  }
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cin >> V >> E >> L;
  rep(i,E){
    int x,y,c;cin >> x >> y >> c;
    --x;--y;
    d[x][y] = d[y][x] = c<=L?c:INF;
  }
  rep(i,V) d[i][i] = 0;
  warshall_floyd();
  rep(i,V) rep(j,V){
    if(i==j)continue;
    d[i][j] = d[i][j]<=L?1:INF;
  }
  warshall_floyd();
  int Q;cin >> Q;
  while(Q--){
    int s,t;cin >> s >> t;--s;--t;
    if(d[s][t] == INF) cout << -1 << endl;
    else cout << d[s][t]-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  ll n;
  cin >> n;
  ll ans=n;
  
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ans=min(ans,i+n/i-2);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
ID: varunra2
LANG: C++
TASK: a
*/

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

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

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

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

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


int main() {

  cin.sync_with_stdio(0); cin.tie(0);

  int x;
  cin >> x;

  if(x >= 30) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
using namespace std;

int main()
{
    int n,t[102],sum=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&t[i]);
        if(i%2!=0&&t[i]%2!=0)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  map<char, int> mp;
  string s;
  cin >> s;
  for (char &c : s) {
    mp[c]++;
  }
  for (char c = 'a'; c <= 'z'; c++) {
    if (mp[c] % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
WA = {i : 0 for i in range(1,N+1)}
AC = defaultdict(int)
boollist = [False]*N

for _ in range(M):
    p,s = input().split()
    p = int(p)
    if s == 'WA' and not boollist[p-1]:
        WA[p] += 1
    elif s == 'AC':
        boollist[p-1] = True
        AC[p] = 1
print(sum(AC.values()), sum([a for a,b in zip(WA.values(), boollist) if b==True]))

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

typedef long long Int;

inline Int TWO(int e) { return 1LL << e; }

int main() {
	int n,k;cin>>n>>k;
	vector<Int>ca(n+1);for(int i=0;i<n;i++){int x;cin>>x;ca[i+1]=ca[i]+x;}
	vector<Int> cum; for (int l=0; l<n; l++) for(int r=l; r<n; r++) cum.push_back(ca[r+1] - ca[l]);
	Int S = 0;
	for (int b=60; b>=0; b--) {
		int cnt=0; for (Int v : cum) if (v & TWO(b)) cnt++;
		if (cnt >= k) {
			S |= TWO(b);
			vector<Int> cum2;
			for (Int v : cum) if (v & TWO(b)) cum2.push_back(v);
			cum = cum2;
		}
	}
	cout << S << endl;
}


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

using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> as(n + 1, 0);
  int a;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    as[a]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << as[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4044
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define pi pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912

const long double PI = acos(-1);
const ll DEP = 1LL << 50;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
const int NMAX = 1000;
const int MMAX = 2000;
int N,M; int a[MMAX],b[MMAX];
ll c[MMAX];
int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }
    ll dist[NMAX];

    for(int i = 0; i < N; i++){
        dist[i] = DEP;
    }
    dist[0] = 0;

    for(int loop = 0; loop < N-1; loop++){
        for(int i = 0; i < M; i++){
            if(dist[a[i]-1] == DEP) continue;
            if(dist[b[i]-1] > dist[a[i]-1]+c[i]){
                dist[b[i]-1] = dist[a[i]-1] + c[i];
            }
        }
    }
    ll ans = dist[N-1];

    bool negative_edge[NMAX];

    for(int i = 0; i < N; i++){
        negative_edge[i] = false;
    }

    for(int loop = 0; loop < N; loop++){
        for(int i = 0; i < M; i++){
            if(dist[a[i]-1] == DEP) continue;
            if(dist[b[i]-1] > dist[a[i]-1] + c[i]){
                dist[b[i]-1] = dist[a[i]-1] + c[i];
                negative_edge[b[i]-1] = true;
            }

            if(negative_edge[a[i]-1] == true){
                negative_edge[b[i]-1] = true;
            }
        }
    }
    if(negative_edge[N-1]){
        cout << "inf" << endl;
    } else {
        cout << -ans << endl;
    }
    
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
/*
vector<string> split(string& s, char x){ // O(s.length())
  int i;
  vector<string> res(1);

  int word = 0;
  rep(i,s.size()){
    if(s[i] != x) res[word].push_back(s[i]);
    else if(i != 0 && i != s.size()-1){
      word++;
      res.push_back("");
    }
  }

  return res;
}
*/
int main(){
  int i,j,N;

  scanf("%d\n",&N);
  rep(i,N){
    string in;
    getline(cin,in);
/*
    vector<string> sp = split(in,' ');
    rep(j,sp.size()){
      if(sp[j] == "Hoshino") sp[j] = "Hoshina";
      if(sp[j] == "Hoshino.") sp[j] = "Hoshina.";
      cout << sp[j];
      if(j != sp.size()-1) cout << ' '; else cout << endl;
    }
  */
    int found = -1;
    while((found = in.find("Hoshino")) != -1) in[found + 6] = 'a';
    cout << in << endl;
  }

  return 0;
}

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


int main(){
  int64_t H,ans=0,i=1;
  cin >> H;
  while(true){
    if(H==1){
      ans+=i;
      break;
    }
    ans+=i;
    H/=2;
    i*=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    X, Y, Z = map(int, input().split())
    rest = X - Z
    c = 0
    while rest > 0:
        rest = rest - Y - Z
        if rest < 0:
            print(c)
            return
        elif rest == 0:
            print(c+1)
            return
        else:
            c += 1
main()


Measured memory_bytes: 9060
#include<iostream>
using namespace std;
int main()
{
    int n,k;
     cin>>n>>k;
    int p[n];
    int j,i,flag;
    for (i=0;i<n;i++)
    {
        //cout<<"hello"<<i;
        cin>>p[i];
        //cout<<"ip";
    }
        int sum=0,min;
    flag=0;
    for (j=0;j<k;j++)
    {
        
        min=p[0];
        for (i=0;i<n;i++)
       {
            if(p[i]<=min){ min=p[i];flag=i;}
       }
        sum+=min; p[flag]=9999;
       
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
vector<int> paths[650];
long double dp[650];
int N, M;
long double ans;
 
void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        int s, t;
        cin >> s >> t;
        paths[s].push_back(t);
    }
}
void f(int block) {
    //cout<<"block"<<block<<endl;
    dp[N] = 0;
    for(int i = N - 1; i >= 1; i--) {
        long double sum = 0.0;
        long double maxi = 0.0;
        int num = paths[i].size();
        for(auto to : paths[i]) {
            sum += dp[to];
            chmax(maxi, dp[to]);
           // printf("i=%d,maxi=%lf,to=%d,dp[%d]=%lf\n",i,maxi,to,to,dp[to]);
        }
        if(i == block && num >= 2) {
            //printf("i==block,before,sum=%lf,num=%d\n",sum,num);
            num--;
            sum -= maxi;
        }
        dp[i] = sum / num + 1;
        //printf("i=%d,dp[%d]=%lf,sum=%lf,num=%d\n",i,i,dp[i],sum,num);
    }
    chmin(ans, dp[1]);
}
 
void solve() {
    input();
    ans = 1e18;
    for(int i = 1; i <= N - 1; i++) {
        f(i);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return;
}
int main() {
    solve();
    return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int n;
  if(b<10) n=a*10+b;
  else if(b<100) n=a*100+b;
  else n=a*1000+b;
  
  bool ans=false;
  for(int i=0;i*i<=n;++i)
    if(i*i==n) ans=true;
  
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import Data.Foldable (traverse_)

call n = traverse_ (\i -> putStr $ " " ++ show i) $ filter (\i -> mod3 i || inc3 i) [1..n]
  where
  mod3 i = i `mod` 3 == 0
  inc3 i = not . null $ filter (\x -> x `mod` 10 == 3) $ takeWhile (> 0) $ iterate (`div` 10) i

main = readLn >>= call >> putStrLn ""



Measured memory_bytes: 4124
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

bool isPrime(int num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    for (int i = 2; i * i < num; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int x;
    cin >> x;
    while (!isPrime(x))
        x++;
    OUT(x);
}

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

const int M = 1e9+7;

int bs(vector<int> &v , int idx , int rest) {
    int n = v.size();
    int l = 0 , r = n-1 , ans = -1;
    while(l <= r) {
        int mid = l + (r-l)/2;
        if(v[mid] >= idx) {
            ans = mid;
            r = mid-1;
        }
        else l = mid+1;
    }
    int num = 0;
    if(ans != -1) num = n - ans;
    bool found = false;
    l = 0 , r = n-1;
    while(l <= r) {
        int mid = l + (r-l)/2;
        if(v[mid] > rest) r = mid-1;
        else if(v[mid] < rest) l = mid+1;
        else {
            found = true;
            break;
        }
    }
    if(found) num--;
    return num;
}

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<char , vector<int>> map;
    for(int i = 0; i < n; i++) {
        map[s[i]].push_back(i);
    }
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(s[i] != s[j]) {
                int d = j-i;
                int num = 0;
                if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
                    num = bs(map['B'] , j+1 , j+d);
                    cnt += num;
                }
                else if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
                    num = bs(map['G'] , j+1 , j+d);
                    cnt += num;
                }
                else if((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')) {
                    num = bs(map['R'] , j+1 , j+d);
                    cnt += num;
                }
            }
        }
    }
    cout << cnt << "\n";
    return 0;
}


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

typedef long long int ll;

int main(){
	int n; scanf("%d",&n);
	set<string> ens;
	for(int i=0;i<n;i++){
		string s; cin>>s;
		ens.insert(s);
	}
	printf("%d",(int)ens.size());
}


Measured memory_bytes: 19316
/*
 * Problem     : AOJ0010
 * Title       : A New Plan of Aizu Ski Resort (会津山スキー場の新企画)
 * Author      : mizo0203
 * Copyright   : Your copyright free
 * Description : 外接円の中心座標を計算する
 */

#include <stdio.h>
#include <math.h>
using namespace std;

int n;
double x[3], y[3], xp, yp, r;

void init() {
  scanf("%d", &n);
}

bool input() {
  int i;

  if (!n)
    return false;
  n--;

  for (i = 0; i < 3; i++) {
    scanf("%lf %lf", &x[i], &y[i]);
  }

  return true;
}

int main() {
  double A1, B1, C1, A2, B2, C2;
  init();
  while (input()) {
    A1 = 2 * (x[1] - x[0]);
    B1 = 2 * (y[1] - y[0]);
    C1 = x[0] * x[0] - x[1] * x[1] + y[0] * y[0] - y[1] * y[1];
    A2 = 2 * (x[2] - x[0]);
    B2 = 2 * (y[2] - y[0]);
    C2 = x[0] * x[0] - x[2] * x[2] + y[0] * y[0] - y[2] * y[2];
    xp = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1);
    yp = (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1);
    r = sqrt((x[0] - xp) * (x[0] - xp) + (y[0] - yp) * (y[0] - yp));
    printf("%.3f %.3f %.3f\n", xp, yp, r);
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const   int MaxN=1e5+5;
int p[MaxN],a[MaxN][10],q[MaxN];
string s;

void Data()
{
    a[1][1]=5;a[1][2]=3;a[1][3]=2;a[1][4]=4;
    a[2][1]=4;a[2][2]=3;a[2][3]=6;a[2][4]=1;
    a[3][1]=5;a[3][2]=6;a[3][3]=2;a[3][4]=1;
    a[4][1]=5;a[4][2]=1;a[4][3]=2;a[4][4]=6;
    a[5][1]=6;a[5][2]=3;a[5][3]=1;a[5][4]=4;
    a[6][1]=2;a[6][2]=3;a[6][3]=5;a[6][4]=4;
    for(int i=1;i<=6;i++) q[i]=i;
}

int ans=1,temp;

void F_S()
{
    temp=q[1];
    q[1]=q[5];q[5]=q[6];q[6]=q[2];q[2]=temp;
}

void F_E()
{
    temp=q[1];
    q[1]=q[4];q[4]=q[6];q[6]=q[3];q[3]=temp;
}

void F_W()
{
    temp=q[1];
    q[1]=q[3];q[3]=q[6];q[6]=q[4];q[4]=temp;
}

void F_N()
{
    temp=q[1];
    q[1]=q[2];q[2]=q[6];q[6]=q[5];q[5]=temp;
}

void solve()
{
    Data();
    for(int i=0;i<s.size();i++)
        if (s[i]=='S') F_S();
        else
            if (s[i]=='E')F_E();
            else
                if (s[i]=='W') F_W();
                else F_N();
}
int main()
{
    for(int i=1;i<=6;i++)
        scanf("%d",&p[i]);
    scanf("\n");
    getline(cin,s);
    solve();
    printf("%d\n",p[q[1]]);
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    cout << (B*(int)((T+0.5)/A)) << endl;
    return 0;
}


Measured memory_bytes: 256
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c - b == b - a) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

vector<int>s[100010];

int main(void){
    int n,k=0;
    cin>>n;
    while(true){
        if(k*(k-1)/2<n)k++;
        else{
            if(k*(k-1)/2==n)break;
            else{
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    int index=1;
    for(int i=0;i<k-1;i++){
        for(int j=i+1;j<k;j++){
            s[i].push_back(index);
            s[j].push_back(index);
            index++;
        }
    }
    cout<<k<<endl;
    for(int i=0;i<k;i++){
        int ssize=(int)s[i].size();
        cout<<ssize<<" ";
        for(int j=0;j<ssize;j++){
            if(j==ssize-1)cout<<s[i][j]<<endl;
            else cout<<s[i][j]<<" ";
        }
    }
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int x, t; cin >> x >> t;
  cout << max(x - t, 0) << '\n';
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc169/tasks/abc169_f

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 
#define ll long long

const int MOD = 998244353;
ll dp[3005][3005];
int a[3005];

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

    dp[0][0] = 1;
    int N, S;
    cin >> N >> S;    
    
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    for(int i = 0; i <= N-1; i++) {
        for(int j = 0; j <= S; j++) {
            dp[i+1][j] += dp[i][j]*2;
            dp[i+1][j] %= MOD;

            if(j+a[i] <= S) {
                dp[i+1][j+a[i]] += dp[i][j];
                dp[i+1][j+a[i]] %= MOD;                
            }
        }
    }

    cout << dp[N][S] << endl;
}


Measured memory_bytes: 74036
//<============ Author --> @venom ============>//
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fo(i,n)           for(int i=0;i<n;i++)
#define int               long long
#define pb                emplace_back
#define mp                make_pair
#define ff                first
#define ss                second
#define all(x)            x.begin(), x.end()
#define sortall(x)        sort(all(x))
#define sortrev(x)        sort(all(x), greater<int>())
#define w(x)              int x; cin>>x; while(x--)
#define trunc(x,y)        fixed<<setprecision(y)<<x
#define mk(arr, n, type)  type *arr=new type[n];
#define PI                3.1415926535897932384626
#define mod               1000000007
#define inf               1e9 + 5
#define FIO               ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int, int>    pi;
typedef vector<int>       vi;
typedef vector<pi>        vpi;
typedef vector<vi>        vvi;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;
const int N = 3e5, M = N;
int mpow(int base, int exp);
int gcd(int a, int b) {if (a == 0) return b; return gcd(b % a, a);}
//<----------------------------------------------------------------------------->//
void fastIO()
{
  FIO;
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
  FIO;

  int n, k; cin >> n >> k;
  int x;
  vi h;

  fo(i, n)
  {
    cin >> x;
    h.pb(x);
  }

  vi dp(n, inf);
  dp[0] = 0;

  fo(i, n)
  {
    for (int j = i + 1; j <= i + k; j++)
    {
      if (j < n)
      {
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
      }
    }
  }

  cout << dp[n - 1] << "\n";

  return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((int)result * base) % mod;
    base = ((int)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long int> A(n);
  map<long long int, int> count;
  vector<long long int> side(0);
  for(int i=0;i<n;i++) {
    cin >> A[i];
    count[A[i]]++;
    if(count[A[i]] % 2 == 0) side.push_back(A[i]);
  }

  sort(side.rbegin(), side.rend());

  if(side.size() < 2) cout << 0 << endl;
  else cout << side[0] * side[1] << endl;
}

Measured memory_bytes: 7296