akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
S = [input() for i in range(H)]
C = [[0 for i in range(W)] for j in range(H)]

dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      for k in range(8):
        if 0 <= j + dx[k] < W and 0 <= i + dy[k] < H:
          if S[i +dy[k]][j + dx[k]] == '#':
            C[i][j] += 1
          else:
            pass
        else:
          pass
    else:
      C[i][j] = '#'

for i in range(H):
  for j in range(W):
    print(C[i][j], end = '')
  print('\n')
  

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

signed main(){
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1){
        cout << 1 << endl;
        return 0;
    }
    if((h*w)%2==0){
        cout << h*w/2 << endl;
        return 0;
    }
    else{
        cout << (h*w)/2+1 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
class UnionFindTree:
    """Disjoint-Set Data Structure
       Union-Find Tree
       complexity:
          init: O(n)
          find, unite, same: O(alpha(n))
       used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ)
    """
    def __init__(self, n):
        self.par = list(range(n))  # parent
        self.rank = [0] * n  # depth of tree

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

H, W = map(int, input().split())
uft = UnionFindTree(H * W)
board = [input() for _ in range(H)]
drc = [(1, 0), (0, 1)]
for r in range(H):
    for c in range(W):
        if r < H - 1 and board[r + 1][c] != board[r][c]:
            uft.unite(r * W + c, (r + 1) * W + c)
        if c < W - 1 and board[r][c + 1] != board[r][c]:
            uft.unite(r * W + c, r * W + c + 1)
par_dict_w, par_dict_b = dict(), dict()
for r in range(H):
    for c in range(W):
        par = uft.find(r * W + c)
        if board[r][c] == "#":
            par_dict_b[par] = par_dict_b.get(par, 0) + 1
        else:
            par_dict_w[par] = par_dict_w.get(par, 0) + 1
print(sum(par_dict_w[k] * par_dict_b.get(k, 0) for k in par_dict_w.keys()))


Measured memory_bytes: 70512
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

int n, p[MAXN];

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

	cin >> n;

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

	int cnt = 0;

	for(int i = 1 ; i < n - 1 ; ++i) {
		cnt += (p[i] >= p[i - 1] && p[i] <= p[i + 1]) || (p[i] <= p[i - 1] && p[i] >= p[i + 1]);
	}
	
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
def calc_ssum(s):
    if len(s) == 1:
        res = [[s]]
        return res
    else:
        resprev = calc_ssum(s[:len(s)-1])
        res = []
        for string in resprev:
            tmp = string + [s[-1]]
            res.append(tmp)
            tmp2 = string
            tmp2[-1] = tmp2[-1] + s[-1]
            res.append(tmp2)
        return res

s = input()
all_s = calc_ssum(s)

result = 0
for l in all_s:
    l_int = list(map(int, l))
    result += sum(l_int)

print(result)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outs(vector<T> V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
//const long mod=(long)1e9+7;
bool isOK(long x,long y){
  long cnt=1,t=2;;
  while(x>1){
    cnt+=t;
    x/=2;
    t*=2;
  }
  // cout<<"cnt y"<<endl;
  // cout<<cnt<<":"<<y<<endl;
  if(cnt<=y)return true;
  else return false;
}
inline void solve(void){
  long H;in(H);
  long ok=1L<<60,ng=-1;
  while(abs(ok-ng)>1){
    // cout<<"ok ng"<<endl;
    // cout<<ok<<":"<<ng<<endl;
    long mid=(ok+ng)/2L;
    if(isOK(H,mid))ok=mid;
    else ng=mid;
  }
  out(ok);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
#define MOD 998244353

//セグ木ここから
//*
//↓ここを変える
typedef struct atai{ll a;}atai;
atai xx(atai x,atai y){
	atai r;
	r.a=(x.a+y.a)%MOD;
	return r;
}
atai aid={0};
//↑ここを変える

int segNUM;
atai *segN,*seg;
void seguse(int n){
	segN=(atai*)calloc(2*n,sizeof(atai));
	segNUM=n;
	seg=segN+segNUM;
	rep(i,1,2*segNUM)segN[i]=aid;
}
//seg[]に値を与えてから初期化
void seginit(){for(int node=segNUM-1;node;node--)segN[node]=xx(segN[node*2],segN[node*2+1]);}
void segupdate(int node,atai x){
	//seg[node]をxに更新
	node+=segNUM;
	segN[node]=x;
	while(node/=2)segN[node]=xx(segN[node*2],segN[node*2+1]);
}

atai segcalcsub(int l,int r,int k,int cl,int cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return segN[k];

	int cm=(cl+cr)/2;
	//左側だけ
	if(r<=cm)return segcalcsub(l,r,2*k  ,cl,cm);
	//右側だけ
	if(cm<=l)return segcalcsub(l,r,2*k+1,cm,cr);
	//両方
	return xx(segcalcsub(l,r,2*k,cl,cm),segcalcsub(l,r,2*k+1,cm,cr));
}
atai segcalc(int l,int r){return segcalcsub(l,r,1,0,segNUM);}
//セグ木ここまで
//*/

int main(){
	int n,k,p;
	scanf("%d%d%d",&n,&k,&p);
	int prob=p*invp(100,MOD)%MOD*invp(n,MOD)%MOD;
	seguse(1<<18);
	seg[0].a=1;
	seginit();
	rep(i,1,n+k){
		ll temp=segcalc(max(0,i-n),min(i,k)).a;
		atai x={temp*prob%MOD};
		segupdate(i,x);
	}
	printf("%lld\n",segcalc(k,n+k).a*invp(p,MOD)%MOD*100%MOD);
}


Measured memory_bytes: 5968
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define scan(a,n) for(long int index=0;index<n;index++) cin>>a[index];
#define print(a,n) for(long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int,long long int>>
#define vsi vector<string>
#define vci vector<char>


 
int main() {
   #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fast;
    string s;
    cin>>s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<3;
    else if((s[0]=='R' && s[1]=='R')||(s[1]=='R' && s[2]=='R')) cout<<2;
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R') cout<<1;
    else cout<<0;
        

      

 

      
return 0;    
 }  

Measured memory_bytes: 3636
# 入力
a,b=map(int,input().split())

# 柱の高さ（1本目）
x1=1

# 高低差（0本目との差は1なので1から）
y=1

for i in range(998):
  # 高低差を+1
  y+=1

  # 2本目の高さを求める
  x2=x1+y

  # 2本の高低差が一致した場合
  if x2-x1==b-a:
    # 足りない長さが積雪量（x2-bでも可）
    print(x1-a)
    break

  # 次の比較のために1本目の柱の高さを更新
  x1=x2

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

const int N = 100 * 1000 + 20;
int dp[N][3], sum[3];

int main() {
  	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  	int n, k;
  	string t;
  	map<char, int> mp;
  	mp['r'] = 0;
  	mp['s'] = 1;
  	mp['p'] = 2;
  	cin >> n >> k >> sum[0] >> sum[1] >> sum[2] >> t;
 	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
          	if (i >= k)
              	for (int g = 0; g < 3; g++)
                  	if (j ^ g)
                      	dp[i][j] = max(dp[i][j], dp[i - k][g]);
        	dp[i][j] += (j == ((mp[t[i]] - 1) % 3 + 3) % 3? sum[j]: 0);
        }
    }
  	int ans = 0;
  	for (int i = n - 1; i >= n - k && i >= 0; i--)
      	ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
 	cout << ans << '\n';
  	return 0;
}


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

using namespace std;
long long f[100001][2];
bool visited[100001];
vector<long long> gr[100001];
#define mod 1000000007
void dfs(long long cur,long long prev)
{
    f[cur][0]=1;
    f[cur][1]=1;
    if (gr[cur].size() == 0 || (gr[cur].size() == 1 && prev != -1)) {
        return;
    }
    for(auto node : gr[cur])
    {
        if(node!=prev)
        {
            dfs(node,cur);
            f[cur][0]=(f[cur][0]*(f[node][0]+f[node][1])%mod)%mod;
            f[cur][1]=(f[cur][1]*f[node][0])%mod;
        }
    }
}
int main()
{
    long long n;
    cin >> n;
    long long a,b;
    for(long long i=0;i<n-1;i++)
    {
        cin >> a >> b;
        a--;
        b--;
        gr[a].push_back(b);
        gr[b].push_back(a);
    }
    dfs(0,-1);
    cout << (f[0][0]+f[0][1])%mod;
    return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
// #define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
const int INF = 1e9 + 1;

void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}


bool pr(int n)
{
	for(int i = 2; i * i <= n; ++i) if(!(n % i)) return false;
	return true;
}
string s[N];
void solve()
{	
	int n, k;
	cin >> n >> k;
	ll r, ss, p;
	cin >> r >> ss >> p;
	for(int i = 0; i < n; ++i){
		char c;
		cin >> c;
		s[i % k] += c;
	}
	ll res = 0;
	for(int i = 0; i < k; ++i){
		// cout << s[i] << endl;
		for(int j = 0; j < s[i].size(); ++j){
			ll points = 0, cnt = 0;
			if(s[i][j] == 's') points = r;
			else if(s[i][j] == 'p') points = ss;
			else points = p;
			ll q = j;
			while(q < sz(s[i]) && s[i][j] == s[i][q]) ++cnt, ++q;
			res += points * (cnt / 2 + cnt % 2);
			j = q - 1;
		}
	}
	cout << res;
}

int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 12160
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int N, cnt = 0;
    string S;
    cin >> N >> S;
    REP(i, N-2){
        if (S.substr(i,3) == "ABC"){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100000
#define INF 1000000000
using namespace std;

typedef long long ll;

int main()
{
    double t ,x;
    cin >> t >> x;
    cout << t/x << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	int cnt = 0, i = 0;
	char s[100];
	cin >> s;
	while (s[i] != '\0') {
		i++;
		cnt++;
	}
	for (int x = 1; x <= cnt; x++) {
		cout << "x";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int N;
	cin >> N;
	vector<string> S( N );
	for( int i = 0; i < N; i++ ) {
		cin >> S[i];
	}
 
	vector<vector<int>> g( N );
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) {
			if( S[i][j] == '1' ) {
				g[i].push_back( j );
				g[j].push_back( i );
			}
		}
	}
	vector<int> color( N );
	typedef pair<int, int> P;
	queue<P> que;
	que.push( P( 0, 1 ) );
	color[0] = 1;
	while( !que.empty() ) {
		int v, col;
		tie( v, col ) = que.front();
		que.pop();
		color[v] = col;
		for( int e : g[v] ) {
			if( color[e] == col ) {
				cout << -1 << endl;
				return 0;
			}
			if( color[e] == 0 ) {
				que.push( P( e, -col ) );
				color[e] = -col;
			}
		}
	}
	const int INF = 201;
	vector<vector<int>> mat( N, vector<int>( N, INF ) );
	for( int i = 0; i < N; i++ ) mat[i][i] = 0;
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) {
			if( S[i][j] == '1' ) {
				mat[i][j] = 1;
				mat[j][i] = 1;
			}
		}
	}
	for( int k = 0; k < N; k++ ) {
		for( int i = 0; i < N; i++ ) {
			for( int j = 0; j < N; j++ ) {
				mat[i][j] = min( mat[i][j], mat[i][k] + mat[k][j] );
			}
		}
	}
	int ans = 0;
	for( int i = 0; i < N; i++ ) {
		for( int j = 0; j < N; j++ ) {
			if( mat[i][j] == INF ) continue;
			ans = max( ans, mat[i][j] );
		}
	}
	ans++;
 
	cout << ans << endl;
}


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

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

	int n;
    cin >> n;
    int p[100001] = {0};

    bool f  = true;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
    }
    int ans = 0;
    if(p[1] == 1){
        swap(p[1], p[2]);   ans++;
    }
    if(p[n] == n)   {swap(p[n], p[n-1]);ans++;}

    while(f){
        f=false;
        for(int i = 2; i < n; i++){
            if(p[i] == i){
                if(p[i-1] == i-1){
                    swap(p[i], p[i-1]);
                }else if(p[i+1] == i+1){
                    swap(p[i], p[i+1]);
                }else{
                    swap(p[i], p[i-1]);
                }
                ans++;
            }
        }
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  private static final long MOD = 1000000007L;

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    long k = sc.nextLong();

    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    long result = 0;
    for (int i = 0; i < n; i++) {
      long l = 0;
      long r = 0;

      for (int j = 0; j < i; j++) {
        if (a[i] > a[j]) {
          l++;
        }
      }
//      long addL = ((k - 1) * k / 2) % MOD * l % MOD;
//      if (addL < 0) throw new IllegalStateException();
//      result += addL;
//      result %= MOD;

      for (int j = i + 1; j < n; j++) {
        if (a[i] > a[j]) {
          r++;
        }
      }
//      long addR = (k * (k + 1) / 2) % MOD * r % MOD;
//      if (addR < 0) throw new IllegalStateException();
//
//      result += addR;
//      result %= MOD;

      result += calc(r, k, l + r);
      result %= MOD;
    }

    os.println(result);
  }

  private static long calc(long a, long n, long d) {
    long result = 0;
    result += (n * a) % MOD;
    result += (n * (n - 1) / 2) % MOD * d % MOD;
    return result % MOD;
//    return ((n * (2 * a + (n - 1) * d)) / 2) % MOD;
  }
}

Measured memory_bytes: 27576
def check(a):
    path = []
    for direct in a[1:].split("/"):
        if   direct == ".": continue
        elif direct == "" : direct = "/"
        elif direct == "..":
            if len(path) == 0 or max(url.find("/"+"/".join(path)+"/") for url in urls) == -1: return False
            path.pop()
            continue
        path.append(direct)
    url = "/"+"/".join(path)
    while "//" in url: url = url.replace("//","/")
    if url in urls: return url
    url = (url+"/index.html").replace("//","/")
    return url if url in urls else False
    
while 1:
    n,m = map(int,raw_input().split())
    if n == 0: break
    urls = [raw_input() for i in xrange(n)]
    for loop in xrange(m):
        a = check(raw_input())
        b = check(raw_input())
        if not (a and b): print "not found"
        elif a != b: print "no"
        else: print "yes"

Measured memory_bytes: 4256
#!/usr/bin/env python3
import sys
import math


def solve(N: int):
    answer = 0
    for i in range(1, N+1):
        ratio = N // i
        answer += i * (ratio * (ratio + 1)) // 2
    print(answer)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#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
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  cout << a + b / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C;
    bool r = false;
    cin >> A >> B >> C;
    if(A==B){
        if(B!=C){
            r = true;
        }
    }
    if(B==C){
        if(B!=A){
            r = true;
        }
    }
    if(A==C){
        if(B!=C){
            r = true;
        }
    }
    if(r){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
 int S,h,m,s;

 cin >> S;

 h = S/3600;
 S %= 3600;

 m = S/60;
 S %= 60;

 s = S;

 cout << h << ":" << m << ":" << s << endl;

 return 0;
}

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

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

	int N;
	scanf("%d", &N);
	int pattern = (N + 1) / 2;

	vector<int> num(pattern, 0);

	int tmp;
	for (int i = 0; i < N; i++) {
		scanf("%d", &tmp);
		num[tmp / 2]++;
	}

	int ret;
	if (N % 2 == 1) {
		if (num[0] != 1) {
			goto fail;
		}
		ret = 1;
	} else {
		if (num[0] != 2) {
			goto fail;
		}
		ret = 2;
	}

	for (int i = 1; i < pattern; i++) {
		if (num[i] != 2) {
			// printf("fail at %d\n", i);
			goto fail;
		} else {
			ret = ret * 2 % 1000000007;
		}
	}
success:
	printf("%d", ret);
	return 0;
fail:
	printf("0");
	return 0;
}

Measured memory_bytes: 512
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    vector<int> num(4, 0);
    for (int i = 0; i < 3; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        num[a]++, num[b]++;
    }
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < 4; i++) {
        if (num[i] == 1)
            cnt1++;
        else if (num[i] == 2)
            cnt2++;
    }
    cout << (cnt1 == 2 && cnt2 == 2 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
h,w,k = map(int, input().split())
l = [None]*h
for i in range(h):
    l[i] = list(input())

init_B=0
for i in range(h):
    cnt = l[i].count('#')
    init_B+=cnt

from itertools import *

ans=0
for hs in product([True,False], repeat=h):
    for ws in product([True,False], repeat=w):

        cnt=0
        for i in range(h):
            tmp = hs[i]
            if tmp: # check
                cnt += l[i].count("#")
        for j in range(w):
            tmp = ws[j]
            if tmp: # check
                for i in range(h):
                    if l[i][j] == "#" and not hs[i]:
                        cnt+=1

        if (init_B-cnt)==k:
            ans+=1
print(ans)

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

using ll = long long;
using vi = vector<int>;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

class WUF {
	private:
	vi par;
	vi dw;
	public:
	WUF() {}
	~WUF() {}
	void init(int n) {
		this->par.resize(n);
		this->dw.resize(n);
		for(int i=0;i<n;i++)this->par[i] = i, this->dw[i] = 0;
	}
	int root(int x) {
		if(this->par[x]==x)return x;
		else {
			int r = this->root(this->par[x]);
			this->dw[x] += this->dw[this->par[x]];
			return this->par[x] = r;
		}
	}
	bool same(int x, int y) {
		return this->root(x) == this->root(y);
	}
	int weight(int x) {
        this->root(x);
        return this->dw[x];
    }
	int diff(int x, int y) {
        return this->weight(y) - this->weight(x);
    }
	void unite(int x, int y, int z) {
        z -= this->diff(x, y);
        x = this->root(x);
        y = this->root(y);
		if(x == y)return ;
        this->par[y] = x;
        this->dw[y] = z;
	}
};

WUF a;

int main(){
	cin.tie(0);
	
	int n, q;
	cin>>n>>q;
	
	a.init(n);
	
	rep(i, q) {
		int c, x, y, z;
		cin>>c>>x>>y;
		if(c) {
			if(a.same(x, y))cout<<a.diff(x, y)<<endl;
			else cout<<'?'<<endl;
		} else {
			cin>>z;
			a.unite(x, y, z);
		}
	}

	return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i,n) cin >> a.at(i);

  for(int i = 1; i <n; i++){
    if(a.at(i).front() != a.at(i-1).back()){
      cout << "No" << endl;
      return 0;
    }
  }
  set<string> b;
  rep(i,n) b.insert(a.at(i));
  if(a.size() != b.size()){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;

 }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#include <limits>

template <typename T>
void vc(T t) {
    std::cout << t << " ";
}

template<typename T, typename... Args>
void vc(T t, Args... args) {
// recursive variadic function
    std::cout << t << " ";
    vc(args...) ;
}

const int N = 100000;
std::vector<int> dp(N + 1, -1);
int dpf(const std::vector<int>& h, int r, int n, int k) {
  if (dp[r] != -1) {
    return dp[r];
  }
  if (r == n) {
    return 0;
  }
  // if (r == n - 1) {
  //   dp[r] = std::abs(h[r] - h[n]);
  //   return dp[r];
  // }
  dp[r] = 0x3fffffff;
  for (int i = 1; i <= k && r + i <= n; ++i) {
    dp[r] = std::min(dp[r], std::abs(h[r] - h[r + i]) + dpf(h, r + i, n, k));
  }
  // vc(" +", r, dp[r], "\n");
  return dp[r];
}

void once() {
  int n, k;
  std::cin >> n >> k;
  std::vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i) {
    std::cin >> h[i];
  }
  std::cout << dpf(h, 1, n, k) << std::endl;
}

int
main() {
  int n = 1;
  std::ios::sync_with_stdio(false);
  // std::cin >> n;
  while (n--) {
    once();
  }
}

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

int main(){
    int h,w,n;
    cin >> h >> w >>n;
    int ans=0;
    int a,b;
    if(h>w){a=h;b=w;}
    else {a=w;b=h;}
    int sum = 0;
    rep(i,b){
        sum += a;
        ans++;
        if(n <= sum){break;}
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,C;
    cin >> N >> C;
    vector<vector<ll>> D(C,vector<ll>(C)), c(N,vector<ll>(N));
    rep(i,C){
        rep(j,C){
            cin >> D[i][j];
        }
    }
    map<ll,ll>mp[3];
    rep(i,N){
        rep(j,N){
            cin >> c[i][j];
            c[i][j]--;
            mp[(i+j+2)%3][c[i][j]]++;
        }
    }
    ll ans = 1e18;
    rep(s,C){
        REP(t,0,C){
            REP(r,0,C){
                if(s==t || t==r || r==s)continue;
                ll tmp = 0;
                rep(i,C){
                    tmp += D[i][s]*mp[0][i];
                    tmp += D[i][t]*mp[1][i];
                    tmp += D[i][r]*mp[2][i];
                }
                /*
                rep(i,N){
                    rep(j,N){
                        if((i+j+2)%3 == 0){
                            if(c[i][j] != s){
                                tmp += D[c[i][j]][s];
                            }
                        }else if((i+j+2)%3 == 1){
                            if(c[i][j] != t){
                                tmp += D[c[i][j]][t];
                            }
                        }else{
                            if(c[i][j] != r){
                                tmp += D[c[i][j]][r];
                            }
                        }
                    }
                }
                */
                cmin(ans,tmp);
            }            
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 2176
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++)
			h[i] = scan.nextInt();
		
		AdjancencyList[] list = new AdjancencyList[n];
		for(int i = 0; i < n; i++)
			list[i] = new AdjancencyList();
		
		for(int i = 0; i < m; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();
			list[a-1].push(b-1);
			list[b-1].push(a-1);
		}
		scan.close();
		
		int ans = 0;
		for(int i = 0; i < n; i++) {
			ans++;
			while(!list[i].isEmpty()) {
				int c = list[i].poll();
				if(h[i] <= h[c]) {
					ans--;
					break;
				}
			}
		}
		
		System.out.println(ans);
	}
}

class AdjancencyList{
	LinkedList<Integer> list = new LinkedList<>();
	
	public AdjancencyList() {
	}
	
	public void push(int a) {
		list.add(a);
	}
	
	public int poll() {
		return list.poll();
	}
	
	public boolean isEmpty() {
		return list.isEmpty();
	}
}


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


void solve(long long N, std::string S){
    for(int i = 0; i < S.size(); ++i){
        int x = S[i] - 'A';
        x = (x + N) % 26;
        cout << (char)(x + 'A');
    }
    cout << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
    long[][] nums = new long[2*n][];//座標と種類
    long memo = 0;
    long answer = 1;
    long mod = 1000000007;
    for(long i = 0; i < n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 0;
    }
    for(long i = n; i < 2*n; i++)
    {
      nums[i] = new long[2];
      nums[i][0] = long.Parse(Console.ReadLine());
      nums[i][1] = 1;
    }
    Array.Sort(nums, (a, b) => a[0].CompareTo(b[0]));
    for(long i = 0; i < 2*n; i++)
    {
      if(nums[i][1] == 0)
      {
        memo++;
        if(memo > 1) answer *= Math.Abs(memo);
        answer %= mod;
      }
      else
      {
        memo--;
        if(memo < -1) answer *= Math.Abs(memo);
        answer %= mod;
      }
      //Console.WriteLine(answer);
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
  
}


Measured memory_bytes: 25424
#include<cstdio>
#include<map>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int,int>P;
int main()
{
	int n,h,m,s,r;
	P p;
	while(scanf("%d",&n),n)
	{
		priority_queue<P,vector<P>,greater<P> >q1,q2;
		while(n--)
		{
			scanf("%d:%d:%d",&h,&m,&s);
			p.first=(h*60+m)*60+s;
			scanf("%d:%d:%d",&h,&m,&s);
			p.second=h*3600+m*60+s;
			q1.push(p);
		}
		r=0;
#define F p=q1.top(),q1.pop(),q2.push(P(p.second,p.first))
		while(q1.size()||q2.size())
		{
			if(q1.size()&&q2.size())
			{
				if(q1.top().first<q2.top().first)
					F;
				else q2.pop();
			}
			else if(q1.size())F;
			else break;
			s=q2.size();
			r=(r>s?r:s);
		}
		printf("%d\n",r);
	}
	return 0;
}

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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

void solve(){
    ll x,t,z;
    cin>>x>>t>>z;
    swap(x,t);
    swap(x,z);
    cout<<x<<" "<<t<<" "<<z<<endl;
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
n, m, q = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0


def dfs(u, A):
    global n, m, q, l, ans
    if len(A) == n:  # lの長さがnになったらscoreの計算をする
        score = 0
        for i in range(q):
            a, b, c, d = l[i]
            a, b,  = a - 1, b - 1
            if A[b] - A[a] == c:
                score += d
        ans = max(ans, score)
    else:  # 再帰的にリストに番号を追加していく
        for i in range(u, m + 1):
            dfs(i, A + [i])


def main():
    dfs(1, [1])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9228
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	ll a,b,c;
	cin >> a >> b >> c;
	set<ll>s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout << s.size() << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9+7;
const int maxn = 100005;
int n;
double dp[301][301][301];
double solve(int x, int y, int z) {
	if (x == 0 && y ==0 && z == 0) {
		return 0;
	}
	if (dp[x][y][z] != 0) {
		return dp[x][y][z];
	}
	double ans = 0;
	double add = (double)n / (double)(x + y + z);;
	if (x) {
		ans += (add + solve(x - 1, y, z)) / (double)(x + y + z) * (double)x;
	}
	if (y) {
		ans += (add + solve(x + 1, y - 1, z)) / (double)(x + y + z) * (double)y;
	}
	if (z) {
		ans += (add + solve(x, y + 1, z - 1)) / (double)(x + y + z) * (double)z;
	}
	return dp[x][y][z] = ans;
}
void go() {
	cin >> n;
	int c[3] = {};
	f(n) {
		int x;
		cin >> x;
		c[x - 1]++;
	}
	cout << fixed << setprecision(10) << solve(c[0], c[1], c[2]) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
    
}

Measured memory_bytes: 111192
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>
#include <numeric>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);j++)
#define frk(n) for(k=0;k<(n);k++)
#define frl(n) for(l=0;l<(n);l++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vvvd vector<vector<vector<double>>>


//#define int long long

using namespace std;


const int MAX = 510000;

ll mod_inverse(int a,int M){
	int x=M-2;
	ll temp=a;
	ll ret=1;
	//a^(MOD-1)==1(mod MOD)を利用
	//a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める

	while(x!=0){
		if(x%2==1){
			ret=(ret*temp)%M;
		}
		temp=(temp*temp)%M;
		x=x/2;
	}
	return ret;
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed compare_int(const void *a, const void *b)
{
	int *A = (int *)a;
	int *B = (int *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}


int gcd(int a,int b){
	while(1==1){
		if(a==0||b==0){
			return a+b;
		}else if(a>b){
			a %= b;
		}else{
			b %= a;
		}
	}
}

signed main(void)
{
	//変数の宣言
	long long n,m,a,b;
	int h,w;
	static int s[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	long long temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	vector<int> vec;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	vvi graph;

	//データの読み込み


	scanf("%lld",&n);
	//scanf_s("%lld",&n);


	//scanf("%s",&s);
	//scanf_s("%s",&s,200010);


	/*for(i=0;i<n;i++){
	//scanf("%lld",&a[i]);
	scanf_s("%lld",&a[i]);
	}*/

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



	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	//	clock_t start=clock();
	//	COMinit();

	temp=100;
	while(temp<n){
		temp=(long long)(temp*1.01);
		count++;
	}

	printf("%lld",count);

	//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力

	//printf("%d",(d[i-1][j-1]+1)/2);

	//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



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

int main() {
  int n;
  string s;
  cin >> n >> s;

  int ans = 1;
  for(int i = 1; i < n; i++) {
    if(s.at(i) != s.at(i-1)) {
      ans += 1;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;

int main(){
	ll T = 1;
	//cin >> T;
	while (T--){
		int n;
     cin >> n;
      while (n > 1000) {
		  n = n - 1000;
		  
	  }
	  cout << 1000 - n << endl;
	}
}
	

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



int main(){
    ll n;cin>>n;
    string s;cin>>s;
    if(n<=3){
        cout<<0<<endl;
        return 0;
    }
    vector<ll> r,g,b;
    rep(i,0,n){
        if(s[i]=='R')r.push_back(i);
        else if(s[i]=='G')g.push_back(i);
        else if(s[i]=='B')b.push_back(i);
    }
    if(r.size()*b.size()*g.size()==0){
        cout<<0<<endl;
        return 0;
    }
    ll an=0;
    rep(i,0,n-2){
        rep(j,i+1,n-1){
            if(s[i]==s[j])continue;
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')){
                ll tm=b.end()-lower_bound(b.begin(),b.end(),j+1);
                an+=tm;
                if(j+(j-i)<n){
                    auto upp=lower_bound(b.begin(),b.end(),2*j-i);
                    ll tmp= *upp;
                    if(upp!=b.end()&&tmp==2*j-i)an--;
                }
            }
            else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B')){
                ll tm=r.end()-lower_bound(r.begin(),r.end(),j+1);
                an+=tm;
                if(j+(j-i)<n){
                    auto upp=lower_bound(r.begin(),r.end(),2*j-i);
                    ll tmp= *upp;
                    if(upp!=b.end()&&tmp==2*j-i)an--;
                }
            }
            else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')){
                ll tm=g.end()-lower_bound(g.begin(),g.end(),j+1);
                an+=tm;
                if(j+(j-i)<n){
                    auto upp=lower_bound(g.begin(),g.end(),2*j-i);
                    ll tmp= *upp;
                    if(upp!=b.end()&&tmp==2*j-i)an--;
                }
            }
        }
    }
    cout<<an<<endl;
}
    









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

int main(void){
  while(true){
    int e;
    cin >> e;
    if(e == 0){ break; }

    int ans = e;
    for(int z = 0; z * z * z <= e; z++){
      for(int y = 0; y * y + z * z * z <= e; y++){
        int x = e - (y * y + z * z * z);
        ans = min(ans, x + y + z);
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3008
#include <iostream>
#include <string>

using namespace std;

int main(){
  int input, res, max;
  string s;
  cin >> s;
  input = stoi(s);
  res = 1;
  max = 0;
  for(int i=1;i<=input;i++){
    int counter = 0;
    int temp = i;
    while(temp % 2 == 0){
     counter += 1;
     temp = temp/2;
    }

    if (counter > max){
      max = counter;
      res = i;
    }
  } 
  cout << res <<endl; 
  return 0;
}


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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> G[100010],F[100010];
vector<bool> used(100010,false);
vector<int> cnt(100010,0);
unordered_set<ll> st;

void dfs(int i,int p = -1) {
    used[i] = true;
    for (int& j : G[i]) if (j != p) {
        if (!used[j]) dfs(j,i);
    }
    for (int& j : G[i]) if (st.find((ll)i*100010+j) == st.end() && st.find((ll)j*100010+i) == st.end()) {
        if (j == p && cnt[i]) {
            cnt[i] ^= 1;
            F[i].push_back(j);
        } else {
            cnt[j] ^= 1;
            F[j].push_back(i);
        }
        st.insert((ll)i*100010+j);
    }
}

int main() {
    int n,m;
    cin >> n >> m;
    for (int i = 0;i < m;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0);
    if (m%2 == 0) {
        for (int i = 0;i < n;++i) for (int j : F[i]) cout << i+1 << " " << j+1 << "\n";
    } else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 23076
#!/usr/bin/env ruby
# vim:set fileencoding=utf-8:

class Dice

  def initialize( given_ary )
    @ary = given_ary
  end

  def topface( val )
    4.times do
      self.roll( "E" )
      if self.top == val
        return
      end
    end
    3.times do
      self.roll( "N" )
      if self.top == val
        return
      end
    end
  end

  def frontface( val )
    4.times do
      tmp = @ary[1]
      @ary[1] = @ary[2]
      @ary[2] = @ary[4]
      @ary[4] = @ary[3]
      @ary[3] = tmp
      if @ary[1] == val
        return
      end
    end
  end

  def roll( direction )
    case direction.downcase
    when "e"
      tmp = @ary[0]
      @ary[0] = @ary[3]
      @ary[3] = @ary[5]
      @ary[5] = @ary[2]
      @ary[2] = tmp
    when "w"
      tmp = @ary[0]
      @ary[0] = @ary[2]
      @ary[2] = @ary[5]
      @ary[5] = @ary[3]
      @ary[3] = tmp
    when "s"
      tmp = @ary[0]
      @ary[0] = @ary[4]
      @ary[4] = @ary[5]
      @ary[5] = @ary[1]
      @ary[1] = tmp
    when "n"
      tmp = @ary[0]
      @ary[0] = @ary[1]
      @ary[1] = @ary[5]
      @ary[5] = @ary[4]
      @ary[4] = tmp
    end
  end

  def top
    @ary[ 0 ]
  end

  def front
    @ary[ 5 ]
  end

  def right
    @ary[ 2 ]
  end

end

dice = Dice.new( gets.split.map(&:to_i) )
gets.to_i.times do
  top, front = gets.split.map(&:to_i)
  dice.topface( top )
  dice.frontface( front )
  puts dice.right
end

Measured memory_bytes: 6128
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

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

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    vmax(a)        *max_element(all(a))
#define    vmin(a)        *min_element(all(a))
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

int main() {ikarus_101

    int  n , m , i , j , k , x ;


    cin >> n;
    ll u=1,a=1,b=1;
    rep(i,n)
    {
        u = (u * 10) % M ;
        a = (a * 9) % M ;
        b = (b * 8) % M ;
    }
    ll ans = (u + M - a + M - a + b) % M ;
    cout << ans << endl;











    return 0;
}


Measured memory_bytes: 3624