akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;

const int N = (1<<18) + 10, mod = 1e9 + 7;
int h;
int perm[N], saveVal[N];
vector<int> nodesInSaveVal;

void dfs1(int node, int pathProd) {
	pathProd = (pathProd * node) % mod;
	if(node >= (1<<(h-1))) {//node is leaf
		int nodeOther = perm[node];
		while(true) {
			pathProd *= nodeOther;
			pathProd %= mod;
			nodesInSaveVal.push_back(nodeOther);
			saveVal[nodeOther] += pathProd;
			saveVal[nodeOther] %= mod;
			if(nodeOther == 1) break;
			nodeOther /= 2;
		}
	} else {
		dfs1(2*node, pathProd);
		dfs1(2*node+1, pathProd);
	}
}

int currSum;

void dfs2(int node, int pathProd) {
	pathProd = (pathProd * node) % mod;
	if(node >= (1<<(h-1))) {//node is leaf
		int nodeOther = perm[node];
		int prevNode = nodeOther;
		while(true) {
			pathProd *= nodeOther;
			pathProd %= mod;

			if(prevNode > nodeOther) {
				currSum += (pathProd * saveVal[prevNode^1]) % mod;
			}
			currSum %= mod;
			if(nodeOther == 1) break;
			prevNode = nodeOther;
			nodeOther /= 2;
		}
	} else {
		dfs2(2*node, pathProd);
		dfs2(2*node+1, pathProd);
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> h;
	for(int i = (1<<(h-1)); i < (1<<h); ++i) {
		cin >> perm[i];
		perm[i] += (1<<(h-1)) - 1;
	}
	int res = 0;
	for(int lca = 1; lca < (1<<(h-1)); ++lca) {
		int L = 2*lca;
		int R = 2*lca + 1;
		nodesInSaveVal.clear();
		dfs1(L,1);
		currSum = 0;
		dfs2(R,1);
		res += (lca * currSum) % mod;
		res %= mod;
		for(int node : nodesInSaveVal) {
			saveVal[node] = 0;
		}
	}
	cout << res;
}


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

int main(){
    string s;
    cin >> s;
    int n0 = 0,n1 = 0;

    for (int i = 0; i < s.size(); i++ ){
        if(s[i] == '0') n0++;
        else n1++;
    }
    cout << min(n0, n1)*2 << endl; 
}

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


#define int long long 


const int mod = 2e5 + 3;

int POW(int a, int b, int mod) {
	a %= mod; int r = 1;
	for(int i = b; i > 0; i >>= 1) {
		if(i & 1) r = (r * a) % mod;
		a = (a * a) % mod;
	}
	return r;
}

int generator(int p) {
	int phi = p - 1, n = phi;
	vector <int> f;
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) {
			f.push_back(i);
			while(n % i == 0) {
				n /= i;
			}
		}
	}
	if(n > 1) {
		f.push_back(n);
	}
	for(int i = 2; i < p; i++) {
		int flag = true;
		for(int d: f) {
			flag &= POW(i, phi / d, p) != 1;
		}
		if(flag) {
			return i;
		}
	}
	return -1;
}


using cd = complex<double>;
const double PI = acos(-1);

int reverse(int num, int lg_n) {
    int res = 0;
    for (int i = 0; i < lg_n; i++) {
        if (num & (1 << i))
            res |= 1 << (lg_n - 1 - i);
    }
    return res;
}

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    int lg_n = 0;
    while ((1 << lg_n) < n)
        lg_n++;

    for (int i = 0; i < n; i++) {
        if (i < reverse(i, lg_n))
            swap(a[i], a[reverse(i, lg_n)]);
    }

    for (int len = 2; len <= n; len <<= 1) {
        double ang = 2 * PI / len * (invert ? -1 : 1);
        cd wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len) {
            cd w(1);
            for (int j = 0; j < len / 2; j++) {
                cd u = a[i+j], v = a[i+j+len/2] * w;
                a[i+j] = u + v;
                a[i+j+len/2] = u - v;
                w *= wlen;
            }
        }
    }

    if (invert) {
        for (cd & x : a)
            x /= n;
    }
}


vector<int> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size()) 
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}


int rev[mod], P[mod];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int g = generator(mod);
	P[0] = 1;
	for(int i = 0; i < mod; i++) {
		rev[POW(g, i, mod)] = i;
	}
	vector <int> f(mod, 0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		int x; cin >> x;
		if(x) {
			f[rev[x]]++;
		}
	}
	int ans = 0;
	vector <int> ff = f, gg = f;
	vector <int> v = multiply(ff, gg);
	for(int i = 1; i < v.size(); i++) {
		int x = POW(g, i, mod);
		ans += (v[i] / 2) * x;
		if(i + i < v.size() && i < f.size() && f[i]) {
			v[i + i] -= f[i] * f[i];
			int y = POW(g, i + i, mod);
			ans += (f[i] * (f[i] - 1) / 2) * y;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 30300
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



int main() {


	int n,d;
	cin >> n >> d;

	int ans = n / (2 * d + 1);
	if ((n % (2 * d + 1))) {
		ans++;
	}

	cout << ans << endl;

	

	return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    a=[list(map(int,input().split())) for _ in [0]*n]
    m=(n*(n-1))//2
    d=dict()
    dr=[]
    cnt=0
    for i in range(n-1):
        for j in range(i+1,n):
            d[(i,j)]=cnt
            dr.append((i,j))
            cnt+=1
    #print(d)
    #print(dr)
    g=[[] for _ in [0]*m]
    gr=[0]*m
    for i in range(n):
        temp=[]
        for j in a[i]:
            j-=1
            if i>j:temp.append(d[(j,i)])
            else:temp.append(d[(i,j)])
        for j in range(len(temp)-1):
            g[temp[j]].append(temp[j+1])
            gr[temp[j+1]]+=1
    #print(g)
    #print(gr)
    q=[]
    for i in range(m):
        if gr[i]==0:
            q.append(i)
    cnt=0
    #print(q)
    while q:
        cnt+=1
        qq=[]#次回に回す分
        temp=[]#今回試合する分
        s=set()#戦うチーム
        while q:#今回の試合を抽出
            i=q.pop()
            x,y=dr[i]
            if (x not in s) and (y not in s):
                temp.append(i)
                s.add(x)
                s.add(y)
            else:
                qq.append(i)
        #print(temp,"t")
        while temp:
            i=temp.pop()
            for j in g[i]:
                gr[j]-=1
                if gr[j]==0:
                    qq.append(j)
        #print(qq)
        q=qq
    if sum(gr)==0:
        print(cnt)
    else:
        print(-1)



main()

Measured memory_bytes: 158180
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int grundy(int n, int k) {
    if(n % k == 0) {
        return n / k;
    } else if(n / k == 0) {
        return 0;
    } else {
        int min_same_quotient = n / k * k;
        int step_size = n / k + 1;
        int max_simultaneous_steps = max(1, (n - min_same_quotient) / step_size);
        return grundy(n - step_size * max_simultaneous_steps, k);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int ai, k;
        cin >> ai >> k;
        ans ^= grundy(ai, k);
    }
    cout << (ans ? "Takahashi" : "Aoki") << endl;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;

  vector<bool> ans(N,false);

  rep(i,K) {
    int d; cin >> d;
    vector<int> A(d);
    rep(j,d) cin >> A[j];
    
    rep(j,d) {
      ans[A[j]-1] = true;
    }
  }
  int cnt = 0;
  rep(i,N) {
    if (ans[i] == false) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3592
import heapq
N = int(input())
A = list(map(int,input().split()))
left = [sum(A[:N])]
h1 = A[:N]
heapq.heapify(h1)
for i in range(N):
    heapq.heappush(h1, A[N+i])
    temp = heapq.heappop(h1)
    left.append(left[-1] + A[N+i] - temp)
right = [sum(A[2*N:])]
h2 = list(map(lambda x: -x, A[2*N:]))
heapq.heapify(h2)
for i in range(N):
    heapq.heappush(h2, -A[2*N-1-i])
    temp = -1 * heapq.heappop(h2)
    right.append(right[-1] + A[2*N-1-i] - temp)
ans = float('-inf')
for i in range(N+1):
    ans = max(ans, left[i] - right[-(i+1)])
print(ans)

Measured memory_bytes: 39260
from itertools import *
import numpy as np
H,W,K = map(int,input().split())
C = [list(input()) for h in range(H)]
D = np.zeros((H,W),dtype=np.int)
a = 0

for h in range(H):
  for w in range(W):
    if C[h][w]=="#":
      D[h][w]=1

T = np.sum(D)

for h in range(1+H):
  for I in combinations(range(H),h):
    for w in range(1+W):
      for J in combinations(range(W),w):
        S = 0
        
        for i in I:
          for w in range(W):
            S+=D[i][w]
        for j in J:
          for h in range(H):
            S+=D[h][j]
        for i in I:
          for j in J:
            S-=D[i][j]
        
        if K==T-S:
          a+=1

print(a)

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

struct UnionFind {
    vector<int> data;
    int __size;
    UnionFind(int size) : data(size, -1), __size(size) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) != (y = root(y))) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x; __size--;
        }
        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)]; }
    int size() { return __size; }
};

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;

Edges<int> edges;
vector<vector<pair<int, int>>> mst;
vector<int> noAlt;
int dfs(int u, int p, int goal, int tgt_c) {
    if (u == goal) return true;
    for (auto e: mst[u]) if (e.first != p) {
        int v = e.first;
        Edge<int> edge = edges[e.second];
        if (dfs(v, u, goal, tgt_c)) {
            if (edge.cost == tgt_c) noAlt[e.second] = false;
            return true;
        }
    }
    return false;
}

template<typename T>
void kruskal(Edges<T> &edges, int v) {
    mst.resize(v);
    UnionFind uf(v);
    for (int i = 0; i < edges.size(); i++) {
        Edge<T> e = edges[i];
        int u = e.src, v = e.dst, c = e.cost;
        if (uf.unionSet(u, v)) {
            mst[u].emplace_back(v, i);
            mst[v].emplace_back(u, i);
            noAlt[i] = true;
        } else {
            dfs(u, -1, v, c);
        }
    }
}

int main() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int s, d, c; cin >> s >> d >> c; s--, d--;
        edges.emplace_back(s, d, c);
    }
    sort(begin(edges), end(edges), [](const Edge<int> &a, const Edge<int> &b) {
        return a.cost < b.cost;
    });
    noAlt.resize(m);
    kruskal(edges, n);
    int cnt = 0, cost = 0;
    for (int i = 0; i < m; i++) if (noAlt[i]) {
        cnt++; cost += edges[i].cost;
    }
    cout << cnt << " " << cost << endl;
    return 0;
}


Measured memory_bytes: 3812
n=int(input())
c=input()
l,r=0,n-1
a=0
while r>l:
  while c[l]=='R' and l<n-1: l+=1
  while c[r]=='W' and r>=0: r-=1
  if r>l: a+=1
  l+=1
  r-=1
print(a)

Measured memory_bytes: 9480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i];
    Y = X;
    sort(Y.begin(), Y.end());

    //中央値Bi
    for(int i=0; i<N; i++) {
        if(X[i] < Y[N/2]) {
            cout << Y[N/2] << endl;
        }
        else {
            cout << Y[N/2-1] << endl;
        }
    }
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)//rep(i,回数){処理}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    char s = 'R';
    string str;
    int count,ans;
    cin >> str;
    count, ans = 0,0;

    rep(i,3) {
        if (str[i] == s) {
            count++;
            ans = count;
        } else {
            count = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_144A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B;

            var word = Console.ReadLine().Split(' ');

            A = int.Parse(word[0]);
            B = int.Parse(word[1]);

            if (A <= 9 && A >= 1 && B <= 9 && B >= 1)
                Console.WriteLine(A * B);
            else
                Console.WriteLine("-1");
            Console.ReadKey();

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
 
int main(){
    ll n,k; cin >> n >> k;
    vl h(n);
    rep(i,n) cin >> h[i];
    sort(all(h));
    ll mn = INF;
    rep(i,n-k+1){
        mn = min(mn,h[i+k-1]-h[i]);
    }
    cout << mn << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };




int main()
{
	int n, k;
	vector<int> book[10];
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i)
	{
		int c, g;
		scanf("%d%d", &c, &g);
		book[--g].push_back(c);
	}
	vector<int> v[10];
	for (int i = 0; i < 10; ++i)
	{
		sort(rall(book[i]));
		v[i].resize(book[i].size() + 1);
		v[i][0] = 0;
		partial_sum(all(book[i]), v[i].begin() + 1);
		for (int j = 2; j < v[i].size(); ++j)
			v[i][j] += j * (j - 1);
	}

	const int INF = 1e9;
	int dp[19][2222];
	CLEAR(dp, 0);

	for (int i = 0; i < 10; ++i)
		for (int j = 0; j <= k; ++j)
			for (int t = 0; t < v[i].size() && j + t <= k; ++t)
				max_swap(dp[i + 1][j + t], dp[i][j] + v[i][t]);

	printf("%d\n", dp[10][k]);
}

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

int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	vector<int> v(n,INT_MAX);
//	b[n]={INT_MAX};
	v[0]=0;
	for(int i=0;i<n;i++){
	if((i+1)<n)
	v[i+1]=min(v[i+1],v[i]+abs(a[i]-a[i+1]));
	if((i+2)<n)
	v[i+2]=min(v[i+2],v[i]+abs(a[i]-a[i+2]));
	}
	cout<<v[n-1];
	return 0;
}

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

lli n, q;
string s;

int main(void){
	cin >> n >> q >> s;
	vector<lli> c(n);
	c[0] = c[1] = 0;
	for(int i = 1; i < n; i++){
		c[i] = c[i-1];
		if(s[i-1] == 'A' && s[i] == 'C') c[i]++;
	}
	rep(i, q){
		lli l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << c[r]-c[l] << endl;
	}
	return 0;
}


Measured memory_bytes: 4296
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009
using P = pair<int,int>;


int main(){
  #define int long long
  string o,e;
  cin >> o >> e;
  int SI = min(o.size(),e.size());
  rep(i,SI){
    cout << o[i];
    cout << e[i];
  }
  if(e.size() > o.size()){
    cout << e[e.size()-1] << endl;
  }
  if(o.size() > e.size()){
    cout << o[o.size()-1] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 520
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
char mp1[N][N], mp2[N][N];
char str[N];
int main(int argc, char const *argv[]) {
  int n = read(), m = read();
  for (int i = 1; i <= n; ++ i) {
    scanf("%s", str + 1);
    memcpy(mp1[i], str, sizeof str);
    memcpy(mp2[i], str, sizeof str);
  }
  for (int i = 1; i <= m; ++ i) {
    mp1[1][i] = '#';
    mp2[n][i] = '#';
  }
  for (int i = 1; i <= m; ++ i) {
    auto mp = (i & 1) ? mp1 : mp2;
    for (int j = 2; j < n; ++ j) {
      mp[j][i] = '#';
    }
  }
  for (int i = 1; i <= n; ++ i) {
    printf("%s\n", mp1[i] + 1);
  }
  puts("");
  for (int i = 1; i <= n; ++ i) {
    printf("%s\n", mp2[i] + 1);
  }
  return 0;
}

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

int main(){
  int R;
  cin>>R;
  
  cout<<R*2*3.141592<<endl;



}

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

  
int main(){
  int n,T;
  cin >> n >> T;
  VI c(n);
  VI t(n);
  rep(i, n){
    cin >> c.at(i) >> t.at(i);
  }
  int sum=0;
  rep(i,n){
    if(t.at(i)>T){
	c.at(i)=c.at(i)*100000;
      sum++;
    }
  } 
  if(sum==n){
    cout << "TLE" << endl;
  }
  else{
  int minn;
  rep(i,n){
    minn=min(minn,c.at(i));
  }
  cout << minn <<endl;
  }
}

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

int main() {
  string s;
  cin >> s;
  if (s == "SUN") puts("7");
  else if (s == "MON") puts("6");
  else if (s == "TUE") puts("5");
  else if (s == "WED") puts("4");
  else if (s == "THU") puts("3");
  else if (s == "FRI") puts("2");
  else puts("1");
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete
signed main(){

    ll N, M;
    cin>>N>>M;

    if(N%2){
        for(int i=0;i<M;i++){
            cout<<i+1<<" "<<N-i<<endl;
        }
        return 0;
    }
    else{
        int odd=(M+1)/2, even=M/2;
        for(int i=0;i<odd;i++)  //奇数
            cout<<i+1<<" "<<odd*2-i<<endl;
        for(int i=0;i<even;i++)
            cout<<odd*2+1+i<<" "<<odd*2+1+(even*2)-i<<endl;;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>

using namespace std;

const int N = 3e5 + 50;

int n, m, a[N];

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    cout << (n + m - 1) / m;
}

Measured memory_bytes: 256
use std::cmp::min;
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (h, w, k): (usize, usize, usize) = parse!(it, 3);
    let g: Vec<Vec<bool>> = (0..h)
        .map(|_| it.next().unwrap().chars().map(|x| x == '1').collect())
        .collect();
    let mut cwhites = vec![vec![0; w + 1]; h + 1];
    for i in 0..h {
        for j in 0..w {
            cwhites[i + 1][j + 1] =
                cwhites[i][j + 1] + cwhites[i + 1][j] - cwhites[i][j] + (g[i][j] as usize);
        }
    }
    let count_whites = |l: usize, r: usize, u: usize, d: usize| -> usize {
        cwhites[d][r] + cwhites[u][l] - cwhites[d][l] - cwhites[u][r]
    };
    let mut ret = std::usize::MAX / 10;
    'outer: for hi in 0..(1 << (h - 1)) {
        let hi: usize = hi;
        let mut pret = hi.count_ones() as usize;
        let mut bounds: Vec<usize> = (0..(h - 1))
            .filter(|i| (hi >> i) & 1 == 1)
            .map(|x| x + 1)
            .collect();
        bounds.push(h);
        let mut l = 0;
        for r in 1..(w + 1) {
            let mut u = 0;
            for &d in bounds.iter() {
                if count_whites(l, r, u, d) > k {
                    if l == r - 1 {
                        continue 'outer;
                    }
                    l = r - 1;
                    pret += 1;
                }
                u = d;
            }
        }
        ret = min(pret, ret);
    }
    println!("{}", ret);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        3 5 4
11100
10001
00111
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main() 
{
    int n;
    scanf("%d", &n);
    int a[100];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (i != n - 1) {
            printf("%d ", a[i]);
        } else {
            printf("%d\n", a[i]);
        }
    }
    
    int v = 0, j = 0;
    for (int i = 1; i < n; i++) {
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (int k = 0; k < n; k++) {
            if (k != n - 1) {
                printf("%d ", a[k]);
            } else {
                printf("%d\n", a[k]);
            }
        }
    }
}



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

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;

int n, d;
int co[15][15];

bool check(int x, int y) {
    double dis = 0;
    for (int i = 0; i < d; ++i) {
        dis += (co[x][i] - co[y][i]) *  (co[x][i] - co[y][i]);
    }
    dis = sqrt(dis);
    return ceil(dis) == floor(dis);
}

int main() {
    ios::sync_with_stdio(0);
    cin >> n >> d;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> co[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if(check(i,j)){
                ++ans;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}

int main(){
    vector<char> data(3);
    for (int i = 0; i < 3; ++i) {
        cin >> data[i];
    }
    cout << count(data.begin(), data.end(), '1') << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(x,y) ((x<y)?(x):(y))
int main(){
	int n,m,c[105][105],i,j,a,b,x;
	int used[105],v[105],ans;
	while(scanf("%d%d",&n,&m)!=EOF){
		if(n==0 && m==0)break;
		for(i=0;i<n;i++)for(j=0;j<n;j++)c[i][j]=10000000;
		for(i=0;i<m;i++){
			scanf("%d%d%d",&a,&b,&x);
			c[a][b]=c[b][a]=x;
		}
		for(i=0;i<n;i++){
			v[i]=10000000;
			used[i]=0;
		}
		ans=0;v[0]=0;
		while(1){
			x=-1;
			for(i=0;i<n;i++){
				if(used[i]==0 && (x==-1 || v[i]<v[x]))x=i;
			}
			if(x==-1)break;
			used[x]=1;
			ans+=v[x];
			for(i=0;i<n;i++){
				v[i]=min(v[i],c[x][i]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
    int sumAll;
    while(cin >> sumAll, sumAll) {
        int a[9], sum = 0;
        rep (i, 9) cin >> a[i], sum += a[i];
        cout << sumAll - sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3008
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define cerr cout
#define F first
#define S second
#define fori(i,a,b) for (i = a; i < b; ++i)
#define ford(i,a,b) for(i = a; i>=b;--i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int(x.size())
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof(a))
#define INF 1000000000
#define MOD 1000000007
#define SMOD 998244353
#define endl "\n"
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const ll N = 100043;
ll fact[N];
ll add(ll x, ll y)
{
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}
ll mul(ll x, ll y)
{
	return (x * 1ll * y) % MOD;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a = a % MOD;
    while (b>0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res % MOD; 
}
ll binpow(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}
ll inv(ll x)
{
	return binpow(x, MOD - 2);
}
ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}
void precalc()
{
	fact[0] = 1;
	ll i;
	fori(i, 1, N)
		fact[i] = mul(i, fact[i - 1]);
}
ll C(ll n, ll k)
{
	if(k > n)
	    return 0;
	return divide(fact[n], mul(fact[n - k], fact[k]));
}

bool printIndex(string str, string s) 
{ 
  
    bool flag = false; 
    for (int i = 0; i < str.length(); i++) { 
        if (str.substr(i, s.length()) == s) { 
            return true; 
        } 
    } 
  
    return false;
} 

void solve()
{
    string s;
    cin >> s;
    int i;
    if(printIndex(s, "RRR"))
        cout << 3 << endl;
    else if(printIndex(s, "RR"))
        cout << 2 << endl;
    else if(printIndex(s, "R"))
        cout << 1 << endl;
    else 
        cout << 0 << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin >> t;
    for(int i=1; i<=t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(true) {
    if(C - B <= 0) {
      cout << "Yes" << endl;
      return 0;
    } else C -= B;
    
    if(A - D <= 0) {
      cout << "No" << endl;
      return 0;
    } else A -= D;
  }
  
  return 0;
}

Measured memory_bytes: 3644
using System;
using System.Linq;
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        string[] input = ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        int plus = A + B;
        if(plus % 2 == 0)
        {
            WriteLine(plus / 2);
        }
        else
        {
            WriteLine("IMPOSSIBLE");
        }
    }
}

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

int main() {
  string A, B;
  char op;
  cin >> A >> op >> B;
  int a = stoi(A);
  int b = stoi(B);
  if (op == '+') {
    cout << a + b << endl;
  } else {
    cout << a - b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
k=int(input())

from itertools import product

pr = list(product([0,1],repeat=n))

ans=float('inf')
for p in pr:

    tmp=1
    for i in p:
        if i==0:
            tmp*=2
        else:
            tmp+=k

    ans= min(ans,tmp)


print(ans)



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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int) 1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = [", __print(x)
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)

int main()
{
    int x;
    cin >> x;
    cout << (x == 0) << "\n"; 
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  double l;cin >> l;
  printf("%.10f\n", (l/3.0)*(l/3.0)*(l/3.0));
}

Measured memory_bytes: 256
a = map(int, raw_input().split())
a.sort()
a, b, c = a
ans = 0
if (c - a) % 2 and (c - b) % 2:
    ans += 1
    a += 1
    b += 1
if (c - a) % 2:
    ans += 1
    b += 1
    c += 1
if (c - b) % 2:
    ans += 1
    a += 1
    c += 1
print ans + (c - a) / 2 + (c - b) / 2

Measured memory_bytes: 2568
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long
int h,w,d;
int t[500][500];
int yy[500000];
int xx[500000];
int ans[110000];

int lastl=-1,tans=0,td=0;
int che(int l,int r){
	int y,x,ret,tmp;
	if(l!=lastl){
	 y=yy[l],x=xx[l];
	 ret=0;
	 tmp=l;
	}
	else{
		 y=yy[td],x=xx[td];
		 ret=tans;
		 tmp=td;
	}
	//cout<<y<<" "<<x<<endl;
	while(t[y][x]!=r){
		tmp+=d;
		//cout<<y<<" "<<x<<" "<<tmp<<endl;
	
		int nx=xx[tmp],ny=yy[tmp];
		ret+=(abs(ny-y)+abs(nx-x));
		x=nx,y=ny;
	}

	td=r;
	tans=ret;
	lastl=l;
	return ret;
}


pair<P,int>X[200000];

int main(){
	cin>>h>>w>>d;
	rep(i,h){
		rep(j,w){
			cin>>t[i][j];
			yy[t[i][j]]=i;
			xx[t[i][j]]=j;
		}
	}
	int q,l,r,num;
	
	cin>>q;
	rep(i,q){
		cin>>l>>r;
		//cout<<che(l,r)<<endl;
		X[i]=mp(mp(l,r),i);
	}
	sort(X,X+q);
	rep(i,q){
		l=X[i].first.first,r=X[i].first.second,num=X[i].second;
		int ret=0;
		ret=che(l,r);
		ans[num]=ret;
	}


	rep(i,q)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 7040
nm = list(map(lambda x:int(x),input().split(" ")))

a = list()
b = list()

count = nm[0]
while count > 0:
    a += list(map(lambda x:int(x), input().split(" ")))
    count -= 1

count = nm[1]
while count > 0:
    b += {int(input())}
    count -= 1

for m in range(nm[0]):
    c = 0
    for k in range(nm[1]):
        c += a[k+m*nm[1]]*b[k]
    print(c)

Measured memory_bytes: 7092
#include <bits/stdc++.h>
using namespace std;
long long fac[600010], finv[600010], inv[600010]; 
long long MOD = 1000000007;
void COMinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < 600005; 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;
}
int main(){
	int N, M, K; cin >> N >> M >> K;
	COMinit(); 
	long long pow3[600010] = {}; 
	pow3[0] = 1; 
	for(int i = 1; i < 600005; i++) pow3[i] = pow3[i-1] * 3 % MOD; 
	long long A[600010] = {}; 
	long long B[600010] = {}; 
	long long C[600010] = {};
	A[0] = 1; 
	for(int i = 1; i <= M+K; i++){
		A[i] = ((A[i-1] * inv[i]) % MOD) * (N-1+i) % MOD; 
	}
	B[0] = 1; 
	for(int i = 1; i <= M+K; i++){
		B[i] = B[i-1] * 2 % MOD;
		long long mn = 0;  
		if(i > M){
			long long tmp = (fac[i-1] * finv[i-1-M]) % MOD; 
			tmp *= finv[M]; tmp %= MOD; mn += tmp;
		}
		if(i > K){
			long long tmp = (fac[i-1] * finv[i-1-K]) % MOD; 
			tmp *= finv[K]; tmp %= MOD; mn += tmp;
		}
		B[i] += MOD * 2 - mn; B[i] %= MOD; 
	}
	long long ans = 0; 
	for(int i = 0; i <= M+K; i++){
		ans += (B[i] * pow3[M+K-i] % MOD) * A[i] % MOD; 
		ans %= MOD;
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 31720
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main(){
string s;
int n;cin>>n;
set<string> m;
int num=0;
for(int i=0;i<n;i++){
    cin>>s;
    if(!m.count(s)){m.insert(s);num++;}
}
cout<<num;
}


Measured memory_bytes: 19224
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];

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

        int[] c = new int[m];
        int[] d = new int[m];

        for(int i = 0; i < m; i++){
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        for(int i = 0; i < n; i++){
            int min = Integer.MAX_VALUE;

            for(int j = 0; j < m; j++) {
                int tmp = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);

                min = Math.min(min, tmp);
            }

            for(int j = 0; j < m; j++){
                if(min == Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j])){
                    System.out.println(j+1);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 23764
n=int(input())
s=input()
raccum=[0]*n
gaccum=[0]*n
baccum=[0]*n
for i in range(n):
  if s[i]=='R':
    raccum[i]+=1
  if s[i]=='G':
    gaccum[i]+=1
  if s[i]=='B':
    baccum[i]+=1
for i in range(n-1):
  raccum[i+1]+=raccum[i]
  gaccum[i+1]+=gaccum[i]
  baccum[i+1]+=baccum[i]
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    if s[i]=='R':
      if s[j]=='G':
        ans+=baccum[n-1]-baccum[j-1]
        if j+j-i<n and s[j+j-i]=='B':
          ans-=1
      if s[j]=='B':
        ans+=gaccum[n-1]-gaccum[j-1]
        if j+j-i<n and s[j+j-i]=='G':
          ans-=1
    if s[i]=='G':
      if s[j]=='R':
        ans+=baccum[n-1]-baccum[j-1]
        if j+j-i<n and s[j+j-i]=='B':
          ans-=1
      if s[j]=='B':
        ans+=raccum[n-1]-raccum[j-1]
        if j+j-i<n and s[j+j-i]=='R':
          ans-=1
    if s[i]=='B':
      if s[j]=='G':
        ans+=raccum[n-1]-raccum[j-1]
        if j+j-i<n and s[j+j-i]=='R':
          ans-=1
      if s[j]=='R':
        ans+=gaccum[n-1]-gaccum[j-1]
        if j+j-i<n and s[j+j-i]=='G':
          ans-=1
print(ans)

Measured memory_bytes: 68928
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
a~>(f,x) = [a] ++ (null x)?([],f x)
half = flip div 2
aliq = ((0==).).mod

main = do
 getLine
 s <- C.getLine
 print $ solve s

solve :: C.ByteString -> Int
solve s = length $ C.group s


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

static const int P[16] = { 1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049,
              177147, 531441, 1594323, 4782969, 14348907};
int n, m, d[14348907];

int getA(int state){
    for(int i = n - 1; i >= 0; i--)
        if((state % P[i + 1]) / P[i] == 0) return i + 1;
    return 0;
}

int getB(int state){
    for(int i = n - 1; i >= 0; i--)
        if((state % P[i + 1]) / P[i] == 1) return i + 1;
    return 0;
}

int getC(int state){
    for(int i = n - 1; i >= 0; i--)
        if((state % P[i + 1]) / P[i] == 2) return i + 1;
    return 0;
}

int bfs(int state){
    fill(d, d + 14348907, -1);
    d[state] = 0;
    queue<int> todo;
    todo.push(state);
    
    while(!todo.empty()){
        int state = todo.front();
        todo.pop();
        if(d[state] == m + 1) return -1;
        if(state == 0 || state == P[n] - 1) return d[state];
        int a = getA(state), b = getB(state), c = getC(state);
        if(a != 0 && a > b){
            int nstate = state + P[a - 1];
            if(d[nstate] == -1){
                d[nstate] = d[state] + 1;
                todo.push(nstate);
            }
        }
        if(b != 0 && a < b){
            int nstate = state - P[b - 1];
            if(d[nstate] == -1){
                d[nstate] = d[state] + 1;
                todo.push(nstate);
            }
        }
        if(b != 0 && b > c){
            int nstate = state + P[b - 1];
            if(d[nstate] == -1){
                d[nstate] = d[state] + 1;
                todo.push(nstate);
            }
        }
        if(c != 0 && b < c){
            int nstate = state - P[c - 1];
            if(d[nstate] == -1){
                d[nstate] = d[state] + 1;
                todo.push(nstate);
            }
        }
    }
    return -1;
}

int main(){
    while(cin >> n){
        if(n == 0) return 0;
        cin >> m;
        int state = 0, a, b, c, x;
        cin >> a;
        for(int i = 0; i < a; i++){
            cin >> x;
        }
        cin >> b;
        for(int i = 0; i < b; i++){
            cin >> x;
            state += P[x - 1];
        }
        cin >> c;
        for(int i = 0; i < c; i++){
            cin >> x;
            state += 2 * P[x - 1];
        }
        cout << bfs(state) << endl;
    }
}


Measured memory_bytes: 59140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0;i < N;i++) {
        cin >> P.at(i);
    }
    vector<int> Q(N);
    for(int i = 0;i < N;i++) {
        cin >> Q.at(i);
    }
    vector<int> cnt(N);
    for(int i = 0;i < N;i++) {
        cnt.at(i) = i + 1;
    }
    int p = 0;
    int q = 0;
    int count = 1;
    do{
        bool pc = true;
        bool qc = true;
        for(int i = 0;i < N;i++) {
            if(P.at(i) != cnt.at(i)) {
                pc = false;
            }
        }
        for(int i = 0;i < N;i++) {
            if(Q.at(i) != cnt.at(i)) {
                qc = false;
            }
        }
        if(pc == true) {
            p = count;
        }
        if(qc == true) {
            q = count;
        }
        count++;
    }while(next_permutation(cnt.begin(),cnt.end()));
    cout << abs(p - q) << endl;
}

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


public class Main {

	public Main(){}
	static int input;
	public static void main(String args[]) throws NumberFormatException, IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		input=Integer.parseInt(str);
		System.out.println((int)Math.pow(input,3));
		
		
	}
	
}

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

using namespace std;

const int MAXN = 20;

int n;

vector< int > testimony[MAXN];

int curBit(int v, int k) 
{
	if( v & (1 << k) ) return 1;
	return 0;
}

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

	for(int i = 0 ; i < n ; i++)
	{
		int k;
		scanf("%d",&k);

		for(int j = 1 ; j <= k ; j++)
		{
			int x, y;
			scanf("%d %d",&x,&y); x--;

			if( y == 1 ) testimony[i].push_back( x );
			else testimony[i].push_back( -x );
		}
	}

	int ans = 0;

	for(int mask = 0 ; mask < (1 << n) ; mask++)
	{
		bool possible = true;

		for(int i = 0 ; i < n ; i++)
		{
			if( !( mask & (1 << i) ) ) continue;

			for(int j = 0 ; j < testimony[i].size() ; j++)
			{
				int val = testimony[i][j];
				int bit = ( val < 0 ) ? 0 : 1;

				val = abs( val );

				if( curBit( mask , val ) != bit ) possible = false;
			}
		}

		if( possible ) ans = max( ans , __builtin_popcount(mask) );
	}

	printf("%d\n",ans);
}

Measured memory_bytes: 256
// this is the memoized code

#include<bits/stdc++.h>
using namespace std;
#define I INT32_MAX
#define IM INT_MIN
#define MOD 1000000007
#define ll long long
#define lli long long int
#define rep(i,n) for (int i = 0; i < n; i++)
#define repk(i,k,n) for (int i = k; i <= n; i++)
#define repr(i,k,n) for (int i = k; i >= n; i--)
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef set<int> si;
ll n;
ll arr[100005][4];
ll dp[100005][4];

ll maxpoints(ll day, ll act) {
	if (day == n) {
		return 0;
	}
	if (dp[day][act] != -1)
		return dp[day][act];

	ll maxi = 0;
	if (act == 0) {
		maxi = max(maxi, arr[day][1] + maxpoints(day + 1, 1));
		maxi = max(maxi, arr[day][2] + maxpoints(day + 1, 2));
		maxi = max(maxi, arr[day][3] + maxpoints(day + 1, 3));
	}

	else if (act == 1) {
		maxi = max(maxi, arr[day][2] + maxpoints(day + 1, 2));
		maxi = max(maxi, arr[day][3] + maxpoints(day + 1, 3));

	}
	else if (act == 2) {
		maxi = max(maxi, arr[day][1] + maxpoints(day + 1, 1));
		maxi = max(maxi, arr[day][3] + maxpoints(day + 1, 3));
	}
	else if (act == 3) {
		maxi = max(maxi, arr[day][1] + maxpoints(day + 1, 1));
		maxi = max(maxi, arr[day][2] + maxpoints(day + 1, 2));
	}

	return dp[day][act] = maxi;
}

void solve() {
	cin >> n;

	for (ll i = 0; i < n; i++) {
		for (ll j = 1; j < 4; ++j)
		{
			cin >> arr[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	cout << maxpoints(0, 0);
}

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

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

}






Measured memory_bytes: 17612
#include<algorithm>
#include<bitset>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<math.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

ll score[200000]={};
int arrived[200000]={};
vector<int> tree[200000];
int main(){
	int n,q;

	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(int i=0;i<q;i++){
		int p;ll x;
		cin>>p>>x;
		p--;
		score[p]+=x;
	}
	queue<P> search;
	search.push(make_pair(0,score[0]));
	arrived[0]=1;
	while(search.size()>0){
		int temp=search.size();
		for(int i=0;i<temp;i++){
			P fi=search.front();
			int index=fi.first;
			ll beforescore=fi.second;
			search.pop();
			for(int j=0;j<tree[index].size();j++){
				int nextindex=tree[index][j];
				if(arrived[nextindex]==1){
					continue;
				}
				score[nextindex]+=beforescore;
				ll nextscore=score[nextindex];
				search.push(make_pair(nextindex,nextscore));
				arrived[nextindex]=1;
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<score[i];
		if(i!=n-1){
			cout<<" ";
		}
	}

	return 0;
}


Measured memory_bytes: 20556