akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
bool agari(int num[]){
 for(int head = 1;head<10;head++){
  if(num[head]>=2){
   int hands[12] = {0};
   for(int i = 1;i<10;i++)hands[i] = num[i];
   hands[head]-=2;
   bool agari = true;
   for(int i=0;i<10;i++)
    while(hands[i]%3)
     for(int j=0;j<3;j++){
      hands[i+j]--;
      if(hands[i+j]<0)agari = false;
     }
   if(agari)return true;
  }
 }
 return false;
}
int main(){
 long long hand;
 while(cin>>hand){
  int num[10] = {0};
  for(;hand>0;hand/=10)num[hand%10]++;
  bool tenpai = false;
  for(int i=1;i<10;i++)
   if (num[i]<4){
    num[i]++;
    if(agari(num)){
     if(tenpai)cout<<" ";
     cout<<i;
     tenpai = true;
    }
    num[i]--;
   }
  if(!tenpai)cout<<0;
  cout<<endl;
 }
}

Measured memory_bytes: 0
#include <stdio.h>
#define N 9

int main(void) {
    int a[N];
    int i, s, x;

    while(1) {
        scanf("%d", &s);
        if(s==0) break;

        x=0;
        for(i=0; i<N; i++) {
            scanf("%d", &a[i]);
            x += a[i];
        }
        printf("%d\n", s-x);
    }

    return (0);

}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define forx(i,a,b) for(ll i=0;i<a;i++)
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9 + 7;

int main()
{
	fast;
    ll k,x;
    cin>>k>>x;
    if(k*500 >=x)
    {
    	cout<<"Yes"<<endl;
    }
    else
    {
    	cout<<"No"<<endl;
    }
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    long int x;
    cin >> x;
    int m[n];
    for ( int i = 0; i < n; i++ )
        cin >> m[i];
    
    int min = m[0];
    for ( int i = 0; i < n; i++ )
    {
        x -= m[i];
        if ( min > m[i] )
            min = m[i];
    }
    
    int ans = n;
    ans += x / min;
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 
#define lo long long int

int n,a[400000],l,r,p,q;
lo c;




int main() {
	
	cin >> n;
	fori0(n) {
		cin >> a[i];
	}
	//c++;
	

	while (r<=n-1) {
		//printf("%d,%d,%d,%d\n", l, r, p,c);
		if ((p + a[r]) == (p | a[r])) { c += (r - l + 1); p += a[r];r++; }
		else { p -= a[l]; l++; }
	}
	//printf("%d\n",7 | 4);
	cout << c << endl;;
	

	//system("pause");
	return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 800;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int sx, sy;
int n, m, k, ans = INT_MAX;

int dis[N + 5][N + 5];
char grid[N + 5][N + 5];

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

void bfs() {
    queue<pii> q;

    memset(dis, oo, sizeof dis);
    dis[sx][sy] = 0;
    q.push(pii(sx, sy));

    while(!q.empty()) {
        int x = q.front().fst, y = q.front().snd; q.pop();

        if(dis[x][y] > k) continue;

        chkmin(ans, x);
        chkmin(ans, y);
        chkmin(ans, n - 1 - x);
        chkmin(ans, m - 1 - y);

        for(int i = 0; i < 4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= n || ny < 0 || ny >= m || grid[nx][ny] == '#') continue;
            if(chkmin(dis[nx][ny], dis[x][y] + 1)) {
                q.push(pii(nx, ny));
            }
        }
    }
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif 

    scanf("%d%d%d", &n, &m, &k);
    for(int i = 0; i < n; ++i) {
        scanf("%s", grid[i]);
        for(int j = 0; j < m; ++j) {
            if(grid[i][j] == 'S') {
                sx = i, sy = j;
                break;
            }
        }
    }
    bfs();
    printf("%d\n", (ans + k - 1) / k + 1);

    return 0;
}


Measured memory_bytes: 3456
#include<cstdio>
#include<algorithm>
using namespace std;
int f(int x)
{
	register int sum=0;
	for(register int i=1;i<=x;i+=2)
		if(x%i==0)sum++;
	return sum;
}
int main()
{
	int ans=0,i,j,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	if(f(i)==8)
		ans++;
	printf("%d",ans);
	return 0;
 } 

Measured memory_bytes: 128
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 100 B
 */
public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int D = scanner.nextInt();
		int N = scanner.nextInt();

		int result = (int) Math.pow(100, D) * N;
		if (N == 100) {
			result += (int) Math.pow(100, D);
		}

		System.out.println(result);

	}

}


Measured memory_bytes: 21844
def inpl(): return input().split()
n, k = map(int, inpl())
M = list(list(map(int, inpl())) for _ in range(n))
M = sorted(M, key=lambda x:x[0])
for i in range(n):
    a, b = M[i]
    if k <= b:
        print(a)
        exit()
    else:
        k -= b

Measured memory_bytes: 29912
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

vector<int> report, actual;

map<int, int> cnt;

int n;

int main() {
    GI(n); int p;

    FOR1(i, n) {
        GI(p);
        actual.PB(p);
        cnt[p]++;
    }

    FOR1(i, n) {
        report.PB(abs(i - 1 - (n - i)));
    }

    sort(actual.begin(), actual.end());
    sort(report.begin(), report.end());

    if (actual != report) {
        printf("0\n");
        return 0;
    }

    LL res = 1;

    for (auto& c : cnt) {
        res = (res * c.SS) % MOD;
    }

    printf("%lld\n", res);
    return 0;
}

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

int n;

const int N = 1010;

pii match;
vector<pii> g[N][N];
int indegree[N][N];

void addedge(int u, int v, int uu, int vv)
{
    if (u > v) swap(u, v);
    if (uu > vv) swap(uu, vv);
    g[u][v].push_back({uu, vv});
    indegree[uu][vv]++;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        vector<int> a(n - 1);
        for (int &u : a)
        {
            cin >> u;    
        }
        for (int j = 0; j < a.size() - 1; j++)
        {
            addedge(i, a[j], i, a[j + 1]);
        }
    }
    queue<pii> q;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if (!indegree[i][j]) q.push({i, j});
        }
    }
    int ans = 0;
    while (!q.empty())
    {
        vector<pii> cur;
        while (!q.empty())
        {
            pii u = q.front(); q.pop();
            cur.push_back(u);
        }
        ans ++;
        for (auto v : cur)
        {
            for (auto w : g[v.first][v.second])
            {
                indegree[w.first][w.second] --;
                if (!indegree[w.first][w.second])
                    q.push(w);
            }
        }
    }
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
        {
            if (indegree[i][j])
            {
                cout << -1 << endl;
                return 0;
            }
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 43776
#include <iostream>
#include <algorithm>

using namespace std;

const long long int Nmax = 2e5;
pair<long long int, long long int> v[Nmax+1];
long long int N;

void solve()
{
    bool atLeastOneDiff = false;
    long long int smallestBI = -1;
    long long int sumAi = 0;

    for (int i=0;i<N;++i) {
        sumAi += v[i].first;
        if (v[i].first > v[i].second) {
            if (smallestBI == -1 || v[smallestBI].second > v[i].second) {
                smallestBI = i;
            }
            atLeastOneDiff = true;
        } else if (v[i].first < v[i].second) {
            atLeastOneDiff = true;
        }
    }

    long long int sol;
    if (!atLeastOneDiff) {
        sol = 0;
    } else {
        sol = sumAi;

        if (smallestBI != -1) {
            sol = sumAi - v[smallestBI].second;
        }
    }

    printf("%lld\n", sol); 
}

int main()
{
    pair<long long int,long long int> val;
    scanf("%lld", &N);
    for (int i=0;i < N;++i) { scanf("%lld", &val.first); scanf("%lld", &val.second); v[i] = val; }

    solve();

    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())
    sum_all = 0
    for i in range(k, n+2):
        # sum_min = sum(list(range(1, i+1)))
        # sum_max = sum(list(range(n+2-i, n+2)))
        # sum_all += (sum_max-sum_min+1)
        sum_all += (n+1-i)*i+1
        sum_min = 0
        sum_max = 0

    # sum_all = (sum_max-sum_min) % (10**9+7)
    print(sum_all % (10**9+7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62896
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner a = new Scanner(System.in);
        int s1 = a.nextInt();
        a.close();
        if (s1 - 111 == 0) {
            System.out.print("3");
        }
        if (s1 - 110 == 0) {
            System.out.print("2");
        }
        if (s1 - 101 == 0) {
            System.out.print("2");
        }
        if (s1 - 100 == 0) {
            System.out.print("1");
        }
        if (s1 - 11 == 0) {
            System.out.print("2");
        }
        if (s1 - 10 == 0) {
            System.out.print("1");
        }
        if (s1 - 1 == 0) {
            System.out.print("1");
        }
        if (s1 - 0 == 0) {
            System.out.print("0");
        }
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline void read (int &x) {
	char ch = getchar(); int f = 0; x = 0;
	while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2e5 + 10, mod = 2019; 
char ch[N]; int n, res, p[N], c[N]; 
signed main() {
	scanf ("%s", ch + 1); int sum = 0;
	n = strlen (ch + 1); p[0] = 1; c[0] = 1;
	for (int i = 1; i < N; ++i) p[i] = p[i - 1] * 10 % mod;
	for (int i = n; i >= 1; --i) {
		int now = (ch[i] - '0') * p[n - i + 1];
		res += c[(now + sum) % mod];
		++c[(now + sum) % mod]; sum = (sum + now) % mod;
	} return printf ("%lld\n", res), 0;
}

Measured memory_bytes: 5620
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
	

bool isPrime(int n){
	if(n<=1) return false;
	if(n==2) return true;
	int f = sqrt(n);
	rep(i, 2, f+1) if(n%i==0) return false;
	return true;
}

int main(){
	
	ll a, b;
	cin >> a >> b;
	cout << a*b/__gcd(a, b) << '\n';

	
	return 0;
}

Measured memory_bytes: 256
import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)

# cnt = 0
# def count():
#     global cnt
#     cnt+=1
#     print(cnt)

def flag(point,P,now):
    if point+100*(now+1)*(P-1) >= g: return 1
    elif point+100*(now+1)*P + C[now] >= g: return 2
    else: return 0

m = 10**9
def score(point = 0, n = 0, now=-1, remain = list(range(d))):
    global m
    if m <= n: return
    elif now == -1:
        for i in remain:
            score(point, n, i, remain)
    elif point >= g: m = n
    elif flag(point,P[now],now) == 1:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: m = n
    elif flag(point,P[now],now) == 2:
        n += P[now]
        if m > n: m = n
    else:
        if m <= n+P[now]: return
        else:
            remain = remain[:]
            remain.remove(now)
            nxtp = point + P[now]*100*(now+1) + C[now]
            for i in remain:
                score(nxtp, n + P[now], i, remain)

score()
print(m)


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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
#define MOD 1000000007

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<ll> llList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  llList p, q, r;
  ll a;
  for(int i=0;i<A;i++){
    cin >> a;
    p.push_back(a);
  }
  for(int i=0;i<B;i++){
    cin >> a;
    q.push_back(a);
  }
  for(int i=0;i<C;i++){
    cin >> a;
    r.push_back(a);
  }
  
  p.sort();
  q.sort();
  r.sort();
  for(int i=0;i<A-X;i++){
    p.pop_front();
  }
  for(int i=0;i<B-Y;i++){
    q.pop_front();
  }
  p.merge(move(q));
  p.merge(move(r));
  p.reverse();
  ll sum = 0;
  for(ll i=0;i<X+Y;i++){
    sum += p.front();
    //cout << p.front() << endl;
    p.pop_front();
  }
    
  
    
  cout << sum << endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int count = 0;
  
  for (int i = A; i <= B; i++) {
    int a = i % 10;
    int j = i / 10;
    int b = j % 10;
    j /= 100;
    int c = j % 10;
    int d = i / 10000;
    if ( a == d && b == c) count++;  
  }
  
  cout << count <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=998244353;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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

void next(vector<int> &use){
    bool ans=true;
    int cnt=0;
    while(ans){
        use[cnt]++;
        if(use[cnt]<=2)ans=false;
        else use[cnt]=0;
        cnt++;
    }
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
  
  int n;cin >> n;
  vector<ll> a(n);
  long double can=0;
  rep(i,n){
    cin >> a[i];
    if(a[i]==0){cout << 0 << endl;return 0;}
    can+=log(a[i]+0.0)/log(10.0);
  }
  if(can>18){cout << -1 << endl;return 0;}
  ll ans=1;
  rep(i,n){
    ans*=a[i];
    if(ans>1000000000000000000){cout << -1 << endl;return 0;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	while(cin>>n,n){
		vi a(n);
		rep(i,n)cin>>a[i];
		vvi dp(n+1,vi(n+1,0));
		rep(i,n-1) if(abs(a[i]-a[i+1])<=1) dp[2][i]=1;
		for(int l=4;l<=n;l+=2)rep(i,n-l+1){
		    dp[l][i]|=(dp[l-2][i+1] and abs(a[i]-a[i+l-1])<=1);
		    for(int k=2;k<l;k+=2){
		        dp[l][i]|=(dp[k][i] and dp[l-k][i+k]);
		    }
		}
		vi ans(n+1,INF);
		deque<pii> d({{0,0}});
		while(ans[n]==INF){
		    int p,c;
		    tie(p,c)=d.front();
		    d.pop_front();
		    if(ans[p]!=INF) continue;
		    //cout<<"頂点"<<p<<", コスト"<<c<<endl;
		    ans[p]=c;
		    d.emplace_back(p+1,c+1);
		    for(int l=2;l<=n;l+=2){
		        if(dp[l][p] and ans[p+l]==INF) d.emplace_front(p+l,c);
		    }
		}
		cout<<n-ans[n]<<endl;
	}
	return 0;
}



Measured memory_bytes: 3240
"""
とても雑な計測で

import 330ms
ノード・エッジリストの計算 400ms
Graph オブジェクト生成 420ms
マッチングの計算 510ms
加工して出力 530ms
"""
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M].astype('U1')

A = []
B = []
E = []

for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == '#':
        continue
    elif (i + j) & 1:
        A.append((i, j))
    else:
        B.append((i, j))

for i, j in A:
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != '#':
            E.append(((i, j), (i1, j1)))

G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)

M = nx.bipartite.maximum_matching(G, A)
for key, item in M.items():
    i, j = key
    i1, j1 = item
    if i1 == i + 1:
        a, b = 'v', '^'
    elif i1 == i - 1:
        a, b = '^', 'v'
    elif j1 == j + 1:
        a, b = '>', '<'
    else:
        a, b = '<', '>'
    S[i, j], S[i1, j1] = a, b

print(len(M) // 2)
for row in S:
    print(''.join(row))


Measured memory_bytes: 69744
S = input()

n = len(S)

start_0 = ""
start_1 = ""

for i in range(n):
    if i % 2 == 0:
        start_0 += "0"
        start_1 += "1"
    else:
        start_0 += "1"
        start_1 += "0"

ans_0 = 0
ans_1 = 0

for i in range(n):
    t1 = start_0[i]
    t2 = start_1[i]
    s = S[i]
    if t1 != s:
        ans_0 += 1
    if t2 != s:
        ans_1 += 1

print(min(ans_1, ans_0))


Measured memory_bytes: 3316
# maximum flow
from collections import defaultdict

def ford_fulkerson(graph, start, end):
    """ 
    graph: [dict<int,int>]
    start: int
    end: int
    """
    INF = 10**9
    network = [defaultdict(int, paths) for paths in graph]

    def dfs(start, end, visited):
        """
        None: unreachable
        (): reached
        """
        if start == end:
            return ()
        visited.add(start)
        for next_, capacity in filter(lambda next_capacity: next_capacity[0] not in visited and next_capacity[1] > 0, network[start].items()):
            path = dfs(next_, end, visited)
            if path is not None:
                return (next_, capacity, path)
        return None

    def margin(path, min_margin=INF):
        if path == ():
            return min_margin
        _, capacity, remaining_path = path
        return margin(remaining_path, min(min_margin, capacity))

    def flush(start, path, amount):
        if path == ():
            return
        next_, _, remaining_path = path
        network[start][next_] -= amount
        network[next_][start] += amount
        flush(next_, remaining_path, amount)

    while True:
        path = dfs(start, end, set())
        if path == None:
            break
        flush(start, path, margin(path))

    return sum(cap for _, cap in graph[start].items()) - sum(cap for _, cap in network[start].items())

h, w = map(int, input().split())
A = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if A[i][j] == 'S':
            s = (i, j)
        if A[i][j] == 'T':
            t = (i, j)

if t[0] == s[0] or t[1] == s[1]:
    print(-1)
else:
    INF = 10**8
    si = h + w
    ti = h + w + 1
    graph = [{} for _ in range(h + w + 2)]
    graph[si][s[0]] = INF
    graph[si][h + s[1]] = INF
    graph[t[0]][ti] = INF
    graph[h + t[1]][ti] = INF
    for i in range(h):
        for j in range(w):
            if A[i][j] == 'o':
                graph[i][h + j] = 1
                graph[h + j][i] = 1
    print(ford_fulkerson(graph, si, ti))

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

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int tmp=0,sum=0;
    for(int i=1;i<=n;i++){
        int num=i;
        while(num>0){
            tmp += num%10;
            num /= 10;
        }
        if((a<=tmp) && (tmp<=b)) sum+=i;
        tmp=0;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
numset = set([])
q = int(input())
for i in range(q):
    query, x = list(map(int, input().split(' ')))
    if query == 0:
        numset.add(x)
        print(len(numset))
    else:
        if set([x]).issubset(numset):
            print(1)
        else:
            print(0)


Measured memory_bytes: 23360
#include<stdio.h>

int main()
{
  int i, j, H, W;

  while(1){
    scanf("%d%d", &H, &W);
    if(H == 0 && W == 0) break;

    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

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

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

  int bingo[3][3] = {};
  for (int i = 0; i < n; i++) {
    int num = b[i];
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (num == a[j][k]) {
          bingo[j][k] = 1;
        }
      }
    }
  }

  int ans = 0;
  bool naname1 = 1;
  bool naname2 = 1;
  for (int i = 0; i < 3; i++) {
    bool tate = bingo[0][i] && bingo[1][i] && bingo[2][i];
    bool yoko = bingo[i][0] && bingo[i][1] && bingo[i][2];
    if (!bingo[i][i]) {
      naname1 = false;
    }
    if (!bingo[i][2 - i]) {
      naname2 = false;
    }

    if (tate) ans++;
    if (yoko) ans++;
  }

  if (naname1) ans++;
  if (naname2) ans++;
  cout << (ans > 0 ? "Yes" : "No") << ln;

  return 0;
}

Measured memory_bytes: 256
# 15分.
# アルゴリズムの理解に間違いがあり余計な時間を撮ってしまった

a = list(input())
b = list(input())
for i in range(len(a)):
    a.insert(0, a.pop(-1))
    if a == b:
        print('Yes')
        break
else:
    print('No')


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
	int a,b,c,x,i;
	i=0;
	scanf("%d %d %d",&a,&b,&c);
	for(x=a;x<=b;x++){
		if(c%x==0){
			i=i+1;
		}
	}
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    int N;
    cin>>N;
    vector<int> prime;
    bool hoge;
    rep(i,100){
        if(i<2) continue;
        if(i==2) prime.push_back(i);
        else{
            hoge=true;
            rep(j,prime.size()){
                hoge=hoge && (i%prime[j]!=0);
            }
            if(hoge) prime.push_back(i);
        }
    }
    

    int num,p,pp;
    vector<int> vec;
    while(!prime.empty()){
        num=0;
        p=prime.back();
        pp=p;
        prime.pop_back();
        while(true){
            if(N<p) break;
            else {
                num+=N/p;
                p=p*pp;
            }
        }
        vec.push_back(num);
    }
    
    int ans=0;
    // 74
    ans+=distance(lower_bound(vec.begin(),vec.end(),74),vec.end());
    // (2,24)
    ans+=distance(lower_bound(vec.begin(),vec.end(),24),vec.end())*(distance(lower_bound(vec.begin(),vec.end(),2),vec.end())-1);
    //(4,14)
    ans+=distance(lower_bound(vec.begin(),vec.end(),14),vec.end())*(distance(lower_bound(vec.begin(),vec.end(),4),vec.end())-1);
    //(2,4,4)
    ans+=distance(lower_bound(vec.begin(),vec.end(),4),vec.end())*(distance(lower_bound(vec.begin(),vec.end(),4),vec.end())-1)*(distance(lower_bound(vec.begin(),vec.end(),2),vec.end())-2)/2;

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

#define N -1
#define M 100010
struct Node { int p, l, r; };
Node T[M]; int A[M];

void print(int a) {
    int i = 0, b = T[a].l;
    printf("node %d: parent = %d, depth = %d, ", a, T[a].p, A[a]);
    if(T[a].p == N) printf("root, [");
    else if(T[a].l == N) printf("leaf, ["); 
    else printf("internal node, [");
    for(; b!=N; ++i, b=T[b].r) {
        if(i) printf(", ");
        printf("%d", b);
    }
    printf("]\n");
}

void rec(int a, int b) {
    A[a] = b;
    if(T[a].r != N) rec(T[a].r, b);
    if(T[a].l != N) rec(T[a].l, b+1);
}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif 

    int a, b, c, d, i, j, n, r;
    scanf("%d", &n);
    for(i=0; i<n; ++i) T[i].p = T[i].l = T[i].r = -1;

    for(i=0; i<n; ++i) {
        scanf("%d%d", &a, &b);
        for(j=0; j<b; ++j) {
            scanf("%d", &c);
            if(!j) T[a].l = c;
            else T[d].r = c;
            d = c; T[c].p = a;
        }
    }
    for(i=0; i<n; ++i) {
        if(T[i].p == N) { r = i; break; }
    }

    rec(r, 0);
    for(i=0; i<n; ++i) print(i);

    return 0;
}


Measured memory_bytes: 7376
# coding: utf-8
# Your code here!

import heapq
from collections import defaultdict
baito = defaultdict(list)
n,m = map(int,input().split())

for _ in range(n):
    a,b = map(int,input().split())
    baito[a-1].append(b)

ans = 0
sl = []
heapq.heapify(sl)
for a in range(m):
    for b in baito[a]:
        heapq.heappush(sl, -b)
    if len(sl) > 0:
        ans -= heapq.heappop(sl)
    
print(ans)

Measured memory_bytes: 77528
fn main() {
    proconio::input! {
        k: u64,
    }
    let mut r = 0;
    for i in 1..=k {
        r = (r * 10 + 7) % k;
        if r == 0 {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 2172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define MAX 505

int n,m;


int main(){
  while(1){
    cin>>n>>m;
    vector<int> G[MAX];
    int num[n+5];
    int used[n+5];
    int ans=0;
    if(n==0&&m==0) break;
    for(int i=0; i<n+5; i++) for(int j=0; j<n+5; j++) {num[i]=INF; used[i]=0;}
    for(int i=0; i<m; i++){
      int a,b;
      cin>>a>>b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    
    queue<int> que;
    que.push(1);
    num[1]=0;
    used[1]=true;
    while(!que.empty()){
      int v=que.front(); que.pop();
      for(int i=0; i<G[v].size(); i++){
        int e=G[v][i];
        if(used[e]) continue;
        num[e]=num[v]+1;
        used[e]=true;
        que.push(e);
      }
    }
    
    for(int i=1; i<=n; i++){
      if(num[i]<=2) {
        ans++;
      }
    }
    
    cout<<ans-1<<en
  }
}


Measured memory_bytes: 3128
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){

  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans = 0;

  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        if(500*i+100*j+50*k == X) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
num = 0
n.times do |i|
  (n-1).downto(i+1) do |j|
    if a[j] < a[j-1]
      tmp = a[j]
      a[j] = a[j-1]
      a[j-1] = tmp
      num += 1
    end
  end
end
puts a.join(' ')
puts num

Measured memory_bytes: 8632
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int n;
int a[2][110];
int dp[2][110];

void rec(int i, int j,int candy){
  
  //ゴールにたどり着いたら終了
  if(i == 1 && j == n){
    return;
  }
  
  //キャンディを拾う
  candy += a[i][j];
  //dpテーブルに記録
  chmax(dp[i][j], candy);
  
  //場外に出なければ右に移動
  if(j+1 < n)rec(i,j+1,candy);
  //場外に出なければ下に移動
  if(i == 0)rec(i+1,j,candy);
}

int main(){
  cin >> n;
  rep(i,2){
    rep(j,n){
      cin >> a[i][j];
      dp[i][j] = -1;
    }
  }
  rec(0,0,0);
  
  cout << dp[1][n-1];
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int const nmax = 100;
char echo[1 + nmax];

int main()
{
  int n;
  char read;
  cin >> n;
  if(n % 2 == 0){
    for(int i = 1;i <= n / 2;i++){
      cin >> echo[i];
    }
    for(int i = 1;i <= n / 2;i++){
      cin >> read;
      if(read != echo[i]){
        cout << "No";
        return 0;
      }
    }
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void debug_out() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H), debug_out(T...);
}
const ll m=1e9+7;
ll mulmod(ll a, ll b) {
    ll r = a*b-(ll)((long double)a*b/m+.5)*m;
    return r < 0 ? r+m : r;
}
ll binpow(ll a,ll n) {
    if(n==0)return 1;
    else if(n&1)return mulmod(a,binpow(mulmod(a,a),n/2));
    else return binpow(mulmod(a,a),n/2);
}
int main() {
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
#define debug(...) 3
    fastIO;
#endif
    ll n;
    cin>>n;
    cout<<(binpow(10ll,n)%m-mulmod(2,binpow(9ll,n))%m+binpow(8ll,n)%m+m)%m<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h> 
using namespace std;
 
#define sz(a) int(a.size())
#define reset(a,b) memset(a,b,sizeof(a))
#define pb					push_back
#define eb					emplace_back
#define mp					make_pair
#define endl 				'\n'
#define gc					getchar_unlocked
#define pc					putchar_unlocked
#define FASTIO std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define MAX_DIGITS 7 // 7 digits in 1 000 000
static const long long buf_len = (1 << 14);
static const long long buf_max = (1 << 04);
static char buf_out[buf_len];
static char buf_num[buf_max];
static long long buf_pos = 0;
#ifdef _WIN32
#define GETCHAR() _getchar_nolock()
#define PUTCHAR(c) _putchar_nolock(c)
#elif __unix__
#define GETCHAR() getchar_unlocked()
#define PUTCHAR(c) putchar_unlocked(c)
#else
#define GETCHAR() getchar()
#define PUTCHAR(c) putchar(c)
#endif
#define MOD 1000000007  
#define lld long long 
typedef long long ll;
static const lld nax=1e6+5;
 
const ll INF2=-1e18;
const int MAXN = 16;
const int MAXL = (1 << 16) + 10;
 
vector<int> grafo[MAXL];
ll valor[MAXL],dp[MAXL],mat[MAXN][MAXN];
int vis[MAXL],N;
 
void brute(int pos,int bitmask,int submask){
 
	if(pos == N){
		if(__builtin_popcount(submask) == 0) return;
		grafo[bitmask].push_back(submask);
		return;
	}
 
	brute(pos+1,bitmask,submask);
	brute(pos+1, bitmask | (1 << pos), submask );
	brute(pos+1, bitmask | (1 << pos), submask | (1 << pos) );
 
}
 
void calcula(){
 
	for(int bitmask = 1;bitmask < (1 << N);bitmask++){
		for(int i = 0;i<N;i++){
			if(!(bitmask & (1 << i))) continue;
			for(int j = i+1;j<N;j++){
				if(!(bitmask & (1 << j))) continue;
				valor[bitmask] += mat[i][j];
			}
		}
	}
 
}
 
ll solve(int bitmask){
 
	if(bitmask == 0) return 0;
	if(vis[bitmask]) return dp[bitmask];
 
	vis[bitmask] = 1;
 
	ll best = INF2;
 
	for(int submask : grafo[bitmask]){
		best = max(best, solve(bitmask ^ submask) + valor[submask] );
	}
 
	return dp[bitmask] = best;
 
}
 
int main() {
    FASTIO
    
    cin >> N;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<N;j++){
			cin >> mat[i][j];
		}
	}
 
	brute(0,0,0);
	calcula();
 
    cout<<solve((1 << N) - 1);
    return 0;
}

Measured memory_bytes: 178468
import { readFileSync } from 'fs'

function main(input: string) {
  const [[N, M], ...lines] = input.split('\n').map(v => v.split(' ').map(Number))

  const begin = lines.reduce((max, [begin, end]) => max > begin ? max : begin, 0)
  const end = lines.reduce((min, [begin, end]) => min < end ? min : end, Infinity)

  const result = Math.max(end - begin + 1, 0)

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


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

using namespace std;

#define ll long long

void solve()
{
    string S;
    cin >> S;
    ll N = S.size();
    string Sr = S;
    reverse(Sr.begin(), Sr.end());
    string sub1 = S.substr(0, (N - 1) / 2);
    string sub2 = S.substr((N + 3) / 2 - 1, N - 1);
    string sub1r = sub1;
    string sub2r = sub2;
    // cout << sub1 << endl;
    // cout << sub2 << endl;
    reverse(sub1r.begin(), sub1r.end());
    reverse(sub2r.begin(), sub2r.end());
    if (Sr == S && sub1r == sub1 && sub2r == sub2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return;
}

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


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

int main() {
	int x, y;
	cin >> x >> y;
	if (x == 2 && y == 2) {
		cout << "Yes" << endl;
	}
	else if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11)) {
		cout << "Yes" << endl;
	}
	else if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int a[100000];
	rep(i, n) {
		cin >> a[i];
	}
	int cnt = 0;
	rep(i, n-1) {
		if (a[i] == i+1) {
			swap(a[i], a[i + 1]);
			cnt++;
		}
	}
	if (a[n - 1] == n)cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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<typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7 
ll solve(int a,int n){
    ll sum=0;
    int da=log10(a)+1;
    int dn=log10(n)+1;
    int f=a/(pow(10,da-1));
    int l=a%10;
    int nf=n/(pow(10,dn-1));
    int nl=n%10;
    if(f==0||l==0)return 0;
    if(f==l&&f<=n)sum++;
    if(dn>=3)sum+=((pow(10,dn-2)-1)/9);
    if(nf>l)sum+=pow(10,dn-2);
    if(nf==l){
        int c=(n%(int)pow(10,dn-1))/10+1;
        if(c==1&&dn<2)c--;
        sum+=c;
        if(nl<f)sum--;
    }
    return sum;
}
int main() {
    int n;
    cin>>n;
    ll sum=0;
    REP(i,n){
        sum+=solve(i+1,n);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 896
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn main() {
    input! {
        r: usize,
    }

    let ans = 2.0 * r as f64 * std::f64::consts::PI;

    echo!(ans);
}


Measured memory_bytes: 2212
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val s = in.readLine()

    val rc = Array.ofDim[Int](n)
    val gc = Array.ofDim[Int](n)
    val bc = Array.ofDim[Int](n)

    for (i <- n - 1 to 0 by -1) {
      s(i) match {
        case 'R' => rc(i) = 1
        case 'G' => gc(i) = 1
        case 'B' => bc(i) = 1
      }
      if (i != n - 1) {
        rc(i) += rc(i + 1)
        gc(i) += gc(i + 1)
        bc(i) += bc(i + 1)
      }
    }

    var count = 0L

    for (i <- 0 until n - 2) {
      for (j <- i + 1 until n - 1) {
        if (s(i) != s(j)) {
          count += {
            List('R', 'G', 'B').filter(c => c != s(i) && c != s(j)).head match {
              case 'R' => rc(j + 1) - {
                if (j + j - i < n && s(j + j - i) == 'R') {
                  1
                } else {
                  0
                }
              }
              case 'G' => gc(j + 1) - {
                if (j + j - i < n && s(j + j - i) == 'G') {
                  1
                } else {
                  0
                }
              }
              case 'B' => bc(j + 1) - {
                if (j + j - i < n && s(j + j - i) == 'B') {
                  1
                } else {
                  0
                }
              }
            }
          }
        }
      }
    }

    out.println(count)

    out.flush()
  }

}


Measured memory_bytes: 57244
import java.util.Scanner;

class Main {
    void solve() {
        Scanner in = new Scanner(System.in);
        String string  = in.nextLine();
        
        if(string.startsWith("YAKI")) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 22996
program handstand
  implicit none
  integer :: n, k, a(100000) = 0, b(0:100000) = 0, m = 0, x = 0, i, j
  character(100001) :: s
  read(*,*) n, k
  read(*,'(a)') s
  s(n+1:n+1) = "X"
  i = 1
  do j = 2, n+1
    if (s(j:j) == s(j-1:j-1)) cycle
    m = m+1
    a(m) = (2*(ichar(s(i:i))-48)-1)*(j-i)
    i = j
  end do
  do i = 1, m
    b(i) = b(i-1)+abs(a(i))
  end do
  do i = 1, m
    if (a(i) > 0) then
      x = max(x,b(min(i+2*k,m))-b(i-1))
    else
      x = max(x,b(min(i+2*k-1,m))-b(i-1))
    end if
  end do
  write(*,'(i0)') x
end program handstand

Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

// 集合にデータを入れたい時
template <class T> 
struct UnionFind {
  vector<int> data;
  vector<T> val;
  UnionFind(int size) : data(size, -1), val(size) {
    REP(i,size) {
      val[i] = i;
    }
  }
  bool unionSet(int x, int y, T v) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
      val[x] = v;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
  T &value(int x) {
    return val[root(x)];
  }
};

int p[100000];
char c[100000];int a[100000];
bool v[100000];

int main() {
  int n,q;
  while(cin>>n>>q,n||q) {
    p[0] = -1;
    REP(i,n-1) {
      cin >> p[i+1];
      p[i+1]--;
    }
    memset(v,0,sizeof(v));
    v[0] = 1;
    REP(i,q) {
      cin >> c[i] >> a[i];
      a[i]--;
      if (c[i] == 'M') {
        if (v[a[i]]) c[i] = '.';
        else v[a[i]] = 1;
      }
    }
    UnionFind<int> uf(n);
    REP(i,n) {
      if (!v[i]) {
        uf.unionSet(i,p[i],uf.value(p[i]));
      }
    }
    // REP(i,n) {
    //   cout << uf.value(i) << endl;
    // }
    ll ans = 0;
    for (int i=q-1; i>=0; --i) {
      if (c[i] == 'Q') {
        ans += uf.value(a[i])+1;
      } else if (c[i] == 'M') {
        uf.unionSet(a[i],p[a[i]],uf.value(p[a[i]]));
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  int a,b,c,d,l,r;
  cin >> a >>b >> c >> d;
  l = a+b;
  r = c+d; 
  
  if (l > r){
  	cout << "Left";
  }
  else if (r>l) {
  	cout << "Right";
  }
  else {
  	cout << "Balanced";
  }
}



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

using namespace std;

const int mx = 1 << 18;
vector<int> dp[mx];

vector<int> tmp;

void join(int x, int y) {
  tmp.clear();
  for (int it: dp[x]) tmp.push_back(it);
  for (int it: dp[y]) tmp.push_back(it);
  sort(tmp.rbegin(), tmp.rend());
  while (tmp.size() > 2) tmp.pop_back();
  dp[x] = tmp;
}

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  tmp.reserve(10);
  int n, x;
  cin >> n;
  const int N = 1 << n;

  for (int i = 0; i < N; ++i) {
    cin >> x;
    dp[i].push_back(x);
  }

  for (int i = 0; i < n; ++i) {
    for (int mask = 1; mask < N; ++mask) {
      if (mask >> i & 1) {
        join(mask, mask ^ (1 << i));
      }
    }
  }

  int premax = 0;
  for (int i = 1; i < N; ++i) {
    int sum = 0;
    for(int x: dp[i]) sum += x;
    if (premax < sum) {
      premax = sum;
    }
    cout << premax << '\n';
  }

  return 0;
}

Measured memory_bytes: 17408
package main

import (
	"fmt"
)

func main() {
	var s string
	var k int
	fmt.Scan(&s, &k)

	var cnt int
	var ans string
	for i, c := range s {
		d := 'z' - c + 1
		if i != len(s)-1 {
			if c != 'a' && cnt+int(d) <= k {
				c = 'a'
				cnt += int(d)
			}
		} else {
			e := int32(k-cnt) % 26
			if c+e > 'z' {
				c = c + e - 26
			} else {
				c = c + e
			}
		}
		ans += string(c)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 8064
#include <stdio.h>
int main(void){
	int sleep,change,x,y,charge;
	scanf("%d%d%d%d",&sleep,&change,&x,&y);
	if(sleep<change){
		charge=(sleep*x);
	}else{
		charge=((change*x)+((sleep-change)*y));
	}
	printf("%d",charge);
	return 0;
}	

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

ans = 0

lst = [1000] * (N)

for i in range(N): #買うところを選択
    a = A[i]
    for j in range(i + 1, N):
        if A[j] > a:
            tmp = lst[i] // a * A[j] + lst[i] % a
            lst[j] = max(max(lst[j], tmp), lst[j - 1])
        else:
            lst[j] = max(lst[j], lst[j - 1])

print (lst[-1])
# print (lst)

Measured memory_bytes: 9116
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	char s[4];
	cin >> s;
	int cnt=0;
	rep(i,0,4){
		rep(j,0,4){
			if(s[i] == s[j]){
				cnt++;
			}
		}
	}
	if(cnt == 8){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
s = gets.chomp

def split_plus(s, tmp, results)
  if s.size == 0
    results << tmp
    return
  end

  for i in 1 .. s.size
    car = s[0, i]
    cdr = s[i, s.size - i]
    
    split_plus(cdr, tmp + car.to_i, results)
  end
end

ret = []
split_plus(s, 0, ret)

puts ret.inject(0, &:+)



Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    int m1 = scanner.nextInt();
	int d1 = scanner.nextInt();
	int m2 = scanner.nextInt();
	int d2 = scanner.nextInt();

	if(m1==(m2-1) || d2==1){
      System.out.println("1");
    }else{
      System.out.println("0");
    }

    
    scanner.close();

  }

}

Measured memory_bytes: 23124