akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>

int main()
{
  char s[101];
  scanf("%s", s);
  bool uni = true;
  for (int i = 1; s[i]; ++i)
  {
    if (s[i] != s[0])
    {
      uni = false;
      break;
    }
  }
  if (uni)
  {
    puts("0");
    return 0;
  }
  
  int ans = 1e5;
  char t[2][101];
  for (char c = 'a'; c <= 'z'; ++c)
  {
    strcpy(t[0], s);
    for (int i = 0; true; ++i)
    {
      uni = true;
      char *p, *q;
      for (p = t[i & 1], q = t[(i & 1) ^ 1]; *(p + 1); ++p, ++q)
      {
        if (*p == c)
        {
          *q = *p;
        }
        else if (*(p + 1) == c)
        {
          *q = *(p + 1);
        }
        else
        {
          *q = *p;
          uni = false;
        }
      }
      *q = 0;
      if (uni)
      {
        if (ans > i + 1) ans = i + 1;
        break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int a[100100], dp[100100];
const int mx = 1e9 + 1000;

int min(int a, int b){
    return (a < b ? a : b);
}

int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    for(int i = 0; i < n; i++) dp[i] = mx;
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = i - 1; j >= i - 2 && j >= 0; j--){
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }
    printf("%d\n", dp[n - 1]);
}

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

int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		int sum=0;
		int m;
		for(int i=0;i<n/4;i++){
			cin >> m;
			sum += m;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
long long int gcd(long long int x,long long int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
long long exp(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = exp(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int prime(long long x){
if(x%2==0)

    return 0;
else{
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)
            return 0;
    }
}
return 1;
}
//main
int main() {
IOS;
ll x,k,d,b;
cin>>x>>k>>d;
if(x<0)x=-x;
b=x/d;
if(b>=k)cout<<x-k*d<<"\n";
else{
    if((b-k)%2==0)cout<<x%d;
    else cout<<d-x%d;
}
return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int H,W,h,w;
int a[505][505];
int main(){
	cin >> H >> W >> h >> w;
	if(H%h == 0 && W%w == 0){
		puts("No"); return 0;
	}
	puts("Yes");
	int cnt = 0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i==0&&j==0){
				a[i][j] = 3999; cnt += 3999;
			}
			else if(i==h-1&&j==w-1){
				a[i][j] = -cnt-1;
			}
			else{
				a[i][j] = 4000;cnt+=4000;
			}
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			printf("%d%c",a[i%h][j%w],(j==w?'\n':' '));
		}
	}
}

Measured memory_bytes: 2432
#include<stdio.h>
int N,M,A[106],i,j,l,r,a=0;

int main()
{
	scanf("%d%d",&M,&N);
	for(i=0;i<M;i++)
	{
		for(j=0;j<N;j++)
		{
			scanf("%d",&A[j]);
			if(i!=0)A[j]^=1;
		}
		for(l=0,r=N-1;l<=r;)
		{
			if(A[l]==1)
			{
				a++;
				A[++l]^=1;
			}
			else if(A[r]==1)
			{
				a++;
				A[--r]^=1;
			}
			else
			{
				A[++l]^=1;
			}
		}
	}
	printf("%d\n",a);
	return 0;
}

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

int main() {
  string S;
  cin >> S;

  bool ok = false;
  int ans = 0;
  do {
    S.pop_back();
    if (S.size() % 2 != 0) continue;
    int med = S.size() / 2;
    if (S.substr(0,med) == S.substr(med, med)) {
      ok = true;
      ans = med * 2;
    }
  } while (!ok);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    const int INF = 1e9 + 7;
    ii mn = {INF, INF};
    int n;
    cin >> n;
    vector <ii> a;
    int maxlen = 0;
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        if (r < mn.s)
            mn = mp(l, r);
        a.app(mp(l, r));
        maxlen = max(maxlen, r - l + 1);
    }   
    sort(all(a));

    //auto t = find(a.begin(), a.end(), mn);
    //a.erase(t);

    vector <ii> pref(n + 1), post(n + 1);
    pref[0] = mp(0, INF);
    for (int i = 0; i < a.size(); ++i) {
        pref[i + 1] = mp(max(pref[i].f, a[i].f), min(pref[i].s, a[i].s));
    }   
    post[a.size()] = mp(0, INF);
    for (int i = (int)a.size() - 1; i >= 0; --i) {
        post[i] = mp(max(post[i + 1].f, a[i].f), min(post[i + 1].s, a[i].s));
    }   

    //cout << mn.f << ' ' << mn.s << endl;

    int ans = 0;
    for (int i = 0; i < a.size(); ++i) {
        int l = max(pref[i].f, post[i + 1].f), r = min(pref[i].s, post[i + 1].s);
        ans = max(ans, a[i].s - a[i].f + 1 + max(0ll, r - l + 1));
    }
    for (int i = 0; i < a.size(); ++i) {
        int l = max(mn.f, pref[i].f), r = min(mn.s, pref[i].s);

        //cout << i << ' ' << l << ' ' << r << ' ' << post[i].f << ' ' << post[i].s << endl;

        ans = max(ans, max(0ll, r - l + 1) + max(0ll, post[i].s - post[i].f + 1));
    }   
    
    cout << ans << endl;
}

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

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        cout << 1 << endl;
    } else if (a != b && b != c && a != c) {
        cout << 3 << endl;
    } else {
        cout << 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int R,G,B;
    cin >> R >> G >> B;
    int all = B+(10*G)+(100*R) ;
    if (all%4==0)
        cout <<"YES" << endl;
    else 
        cout << "NO" << endl;
    
}

Measured memory_bytes: 3492
use std::io::Write;

/// input macro
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
///
/// # Example
///
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! eprintln (
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn main() {
    input! {
        data: [i32; 2],
    }
    let n = data[0];
    let Y = data[1];

    let mut x: i32 = -1;
    let mut y: i32 = -1;
    let mut z: i32 = -1;
    for i in 0..n + 1 { // 10000
        for j in 0..n + 1 - i{ // 5000
            for k in 0..n + 1 - (i + j) { // 1000
                if i + j + k != n {
                    continue;
                }
                if i * 10000 + j * 5000 + k * 1000 == Y {
                    // 1つ例を見つけたら終了
                    x = i;
                    y = j;
                    z = k;
                    break;
                }
            }
        }
    }

    println!("{} {} {}", x, y, z);
}



Measured memory_bytes: 4352
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    S = input().strip()
    if S[2] == S[3] and S[4] == S[5]:
        return 'Yes'
    return 'No'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <math.h>
#include <iomanip>

typedef long long ll;
using namespace std;

int main(){
    double w, h;
    double x, y;
    cin >> w >> h >> x >> y;
    double cx, cy;
    cx = w / 2.0;
    cy = h / 2.0;
    double s = (w * h) / 2.0;
    cout << fixed << setprecision(1) <<  s << " " << int((cx==x)&&(cy==y)) << endl;
    return 0;
}


Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            StringBuffer sb = new StringBuffer(br.readLine());
            String line = sb.reverse().toString();
            System.out.println(line);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

ll mod2(ll n) {
    ll ans = 0;
    while (n % 2 == 0) {
        n /= 2;
        ans++;
    }
    return ans;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        ans += mod2(a);
    }

    cout << ans << endl;
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b
int main() {
	int ans, n;
	for (; fscanf(stdin, "%d", &n), n; P(d, ans)) {
		ans = 0;
		int i, a;
		for (i = 0; i < n / 4; i++)  S(d, a),ans +=a;
	}
	return 0;
}

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

long long gcd(long long a, long long b){ return b ? gcd(b, a%b) : a;}

long long lcm(long long a, long long b){ return a/gcd(a,b)*b;}

long long f(long long x, int c, int d){
    long long res = x;
    res -= x/c;
    res -= x/d;
    res += x/lcm(c,d);
    return res;
}


int main(void){
   long long a, b;
   int c, d;
   cin >> a >> b >> c >> d;
   long long ans = f(b, c, d) - f(a-1, c, d);
   cout << ans;
  
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;

typedef long long ll;

list<int> L;

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

    REP(i, n) {
        string com;
        int key;
        cin >> com;

        if (com == "insert") {
            cin >> key;
            L.push_front(key);
        } else if (com == "delete") {
            cin >> key;
            for (auto it = L.begin(); it != L.end(); ++it) {
                if (*it == key) {
                    L.erase(it);
                    break;
                }
            }
        } else if (com == "deleteFirst") {
            L.pop_front();
        } else if (com == "deleteLast") {
            L.pop_back();
        }
    }

    int i = 0;
    for (int k : L) {
        if (i++) cout << ' ';
        cout << k;
    }
    cout << "\n";
}



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

int main() {
    vector<int> prev = {0, 0, 0}, curr;
    int n, score;
    cin>>n;
    while(n--) {
        curr = {0, 0, 0};
        for(int i=0; i<3; i++) {
            cin>>score;
            for(int j=0; j<3; j++)
                if(i != j) curr[i] = max(curr[i], prev[j] + score);
        }
        prev = curr;
    }
    cout<< *max_element(prev.begin(), prev.end()) <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
    char ch[10000];
    cin>>ch;
    int len = strlen(ch);

    int r = 100;
    int ans[1000];
    for(int i= 0;i<len;i++)
    {
        if(ch[i]=='0')
        {
            ans[r] = 0;
            r++;
        }
        else if(ch[i] == '1')
        {
            ans[r] = 1;
            r++;
        }
        else if(ch[i]=='B')
        {
            if(r==100)
                continue;
            r--;
        }
    }
    for(int i = 100;i<r;i++)
        cout<<ans[i];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;


int N;
pair<ll, ll> a[100000];

int main()
{
	cin >> N;
	rep(i, N)
	{
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a, a + N);
	cout << a[0].second;
	rep(i, N - 1)
	{
		cout << ' ' << a[i + 1].second;
	}

	return 0;
}


Measured memory_bytes: 2432
Mod = 10 ** 9 + 7

n, k = map(int, input().split())
gcd_dp = [0] * (k + 1)

for i in range(k, 0, -1):
    gcd_dp[i] = pow(k // i, n, Mod)
    a = 2
    while i * a <= k:
        gcd_dp[i] -= gcd_dp[i * a]
        a += 1

ret = 0
for i in range(k + 1):
    ret += (i % Mod) * (gcd_dp[i] % Mod)
    ret %= Mod
print(ret)

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] input = new char[20];
		br.read(input);

		for (int i = input.length; i > 0; i--) {
			System.out.print(input[i - 1]);
		}
		System.out.println();

	}
}

Measured memory_bytes: 16848
n, m = map(int, input().split())
dp = [0] * (n + 1)
a = []
for i in range(m):
    aa = int(input())
    dp[aa] = -1
    a.append(aa)
for i in range(m - 1):
    if a[i] + 1 == a[i + 1]:
        print(0)
        exit()
mod = 10 ** 9 + 7

dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1
for i in range(1, n):
    if dp[i + 1] == -1:
        dp[i + 1] = 0
    else:
        dp[i + 1] = (dp[i] + dp[i - 1]) % mod
print(dp[n])

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

#define pb push_back
using pint = pair<int,int>;
const int maxn = 100000+5;

int N, M, S, T;
vector<vector<int>> mem;
queue<pint> que;
vector<vector<int>> ans(maxn, vector<int>(3, -1));

int solve()
{
    ans[S][0] = 0;
    que.push({S, 0});
    while(!que.empty())
    {
        pint cur = que.front(); que.pop();
        int idx = cur.first;
        int num = cur.second;
        for(auto n_idx : mem[idx])
        {
            int n_num = (num+1)%3;
            if(ans[n_idx][n_num] == -1)
            {
                ans[n_idx][n_num] = ans[idx][num] + 1;
                que.push({n_idx,n_num});
            } 
        }
    }
    if(ans[T][0] == -1) return -1;
    else return ans[T][0] / 3;
}

int main()
{
    cin >> N >> M;
    int u, v;
    mem.assign(N, vector<int>());
    for(int i = 0; i < M; i++)
    {  
        cin >> u >> v; 
        u--, v--;       
        mem[u].pb(v);
    }
    cin >> S >> T;
    --S, --T;
    cout << solve() << endl;
}

Measured memory_bytes: 11136
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    A, B, C = map(int, input().split())
    K = int(input())

    while K >= 0:
        if A < B < C:
            print("Yes")
            exit()
        else:
            if A >= B:
                B *= 2
                K -= 1
            else:
                C *= 2
                K -= 1
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        l:f32,
    }

    let res = (l / 3.0).powi(3);
    println!("{}", res);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fastin ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
char s[1010],t[1010];
int main(){
	scanf("%s%s",s+1,t+1);
	int ls=strlen(s+1),lt=strlen(t+1);
	int ans=1e9;
	for(int i=1;i+lt-1<=ls;i++){
		int tmp=0;
		for(int j=0;j<lt;j++){
			if(t[j+1]!=s[i+j]){
				tmp++;
			}
		}
		ans=min(ans,tmp);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
using namespace std;
 
 
int main()
{
  int n;
  std::cin>>n;
  int count=0;
  int i=0;
  for(i=1;i<=n;i++)
  {
    if(i%2!=0)
    count+=1;
  }
  double p=(double)(count)/(double)(n);
  std::cout<<p;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int A, B, C;
int X;
int solve(){
int ans = 0;
for(int i = 0; i <= A; ++i){
for(int j = 0; j <= B; ++j){
for(int k = 0; k <= C; ++k){
int tmp = i * 500 + j * 100 + k * 50;
if(tmp == X) ans++;
}
}
}
return ans;
}
int main(){
scanf("%d%d%d%d", &A, &B, &C, &X);
int ans = solve();
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define optimize ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 2000000020LL
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define POS(n, x) (lower_bound(ALL(n), x) - (n).begin())
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define PB push_back
#define EB emplace_back
#define MOD 1000000007
#define PRIME 101 
#define MAXN 3030
#define MAXL 23
#define endl '\n'

using namespace std;

// (1 + sqrt(5)) / 2
const ld GOLDEN_RATIO = 1.6180339887498949025257388711906969547271728515625;
const ld PI = 2.0 * acos(0.0);
const int BLOCK = 333;

int dp[MAXN][MAXN];

string S, T;

int solve(int i, int j)
{
	if(i < 0 || j < 0) return 0;
	if(dp[i][j] != -1) return dp[i][j];

	return dp[i][j] = (S[i] == T[j] ? 1 + solve(i - 1, j - 1) : max(solve(i - 1, j), solve(i, j - 1)));
}

int main(int argc, char const *argv[])
{
	optimize;

	memset(dp, -1, sizeof dp);
	
	cin >> S >> T;

	int N = S.length() - 1;
	int M = T.length() - 1;

	solve(N, M);

	string ans = "";

	while(N >= 0 && M >= 0)
	{
		if(S[N] == T[M])
		{
			ans += S[N];

			N--;
			M--;
		}
		else
		{
			if(!N)
				M--;
			else if(!M)
				N--;
			else if(dp[N - 1][M] > dp[N][M - 1])
				N--;
			else
				M--;
		}
	}

	reverse(ALL(ans));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 39844
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int n;
  cin >> n;
  int x[n], y[n];
  ll h[n];
  ll max_h = 0, max_x, max_y;
  REP(i,n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]>=max_h){
      max_h = h[i];
      max_x = x[i], max_y = y[i];
    }
  }
  for(int cx = 0; cx <=100; cx++){
    for(int cy = 0; cy <=100; cy++){
      ll ch = max_h + abs(max_x-cx) + abs(max_y-cy);
      REP(i,n){
        if(h[i]!=max((ll)0,ch-abs(x[i]-cx)-abs(y[i]-cy))){
          goto next;
        }
      }
      cout << cx << " "<< cy <<" " << ch << endl;
      return 0;
      next:;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    cin >> n;
    VI a;
    map<int, int> map;
    int in, ans = 0;
    FOR(i, 0, n) {
        cin >> in;
        if (!map[in])ans++;
        map[in]++;
    }
    cout << ans - 1 + ans % 2 << "\n";
}


Measured memory_bytes: 4992
using System;
class aoj{
    public static void Main(){
        String[] str = Console.ReadLine().Split(' ');
        double a = double.Parse(str[0]);
        double b = double.Parse(str[1]);
        double C = double.Parse(str[2]);
        double c = Math.Sqrt(a*a + b*b - 2*a*b*Math.Cos(C*Math.PI/180));
        double S = (a*b*Math.Sin(C*Math.PI/180))/2;
        double h = 2*S/a;
        Console.WriteLine("{0}\n{1}\n{2}",S,a+b+c,h);
    }
}


Measured memory_bytes: 15964
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
  int c,n=0,X,T,ans;
while((c=getchar())!=EOF)
{
if(c=='\n'){
	break;
}else if(c=='0'){
	n+=0;
}else if(c=='1'){
	n+=1;
}else if(c=='2'){
	n+=2;
}else if(c=='3'){
	n+=3;
}else if(c=='4'){
	n+=4;
}else if(c=='5'){
	n+=5;
}else if(c=='6'){
	n+=6;
}else if(c=='7'){
	n+=7;
}else if(c=='8'){
	n+=8;
}else if(c=='9'){
	n+=9;
}

}  
if(n%9==0){
printf("Yes\n");
}else{
printf("No\n");
}
  return 0;
}


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

int main(){
  int X, Y, Z, K, S;
  cin >> K >> S;
  
  int ans = 0;
  for (int X = 0; X <= K; ++X){
    for (int Y = 0; Y <= K; ++Y){
      Z = S - X - Y;
      if(0 <= Z and Z <= K) ++ans;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, X, Y = MI()

aaa = [None] * (N + 1)
for v0 in range(1, N + 1):
    dx = [0] * N
    seen = set()
    seen.add(v0)
    q = deque()
    q.append((v0, -1, 0))
    while len(q) > 0:
        v, p, dist = q.popleft()

        dx[v - 1] = dist
        next = []
        if v > 1: next.append(v - 1)
        if v < N: next.append(v + 1)
        if v == X: next.append(Y)
        if v == Y: next.append(X)
        for next_v in next:
            if next_v not in seen:
                q.append((next_v, v, dist + 1))
                seen.add(next_v)
    d = defaultdict(int)
    for x in dx:
        d[x] += 1
    aaa[v0] = d

for k in range(1, N):
    ans = 0
    for i in range(1, N + 1):
        ans += aaa[i][k]
    print(ans // 2)

Measured memory_bytes: 494216
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int dp[100][100];
int main(){
    CIN(N);
    string ans ="";
    while(N != 0){
        if(N % 2 != 0){
            N--;
            ans = "1" + ans;
        }
        else ans = "0" + ans;
            N /= -2;

    }
    if(ans=="")ans="0";
    COUT(ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
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 ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  int n;
  cin >> n;
  vi a(n+2,0);
  rep2(i,1,n+1) cin >> a[i];
  ll sum = 0;
  rep(i,n+1){
    sum+=abs(a[i]-a[i+1]);
  }
  rep2(i,1,n+1){
    cout << sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << endl;
  }
    
}




Measured memory_bytes: 1664
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    solve(S);
}

void solve(string S){
    if (S=="RRR")
    {
        writeln(3);
        return;
    }
    if (S=="RRS" || S == "SRR")
    {
        writeln(2);
        return;
    }
    if (S[0] == 'R' || S[1] == 'R'||S[2] == 'R')
    {
        writeln(1);
        return;
    }
    writeln(0);
}



Measured memory_bytes: 3684
n,k = map(int,input().split())
d =[]
nu = []
snu =set()
for i in range(k):
    d.append(int(input()))
    nu.append(list(map(int,input().split())))

for i in range(k):
    snu|=set(nu[i])

print(n-len(snu))

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  string s;
  cin >> s;

  if (s == "SUN") cout << 7 << '\n';
  else if (s == "MON") cout << 6 << '\n';
  else if (s == "TUE") cout << 5 << '\n';
  else if (s == "WED") cout << 4 << '\n';
  else if (s == "THU") cout << 3 << '\n';
  else if (s == "FRI") cout << 2 << '\n';
  else if (s == "SAT") cout << 1 << '\n';

  return (0);
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

ll s(ll n){
  ll res = 0;
  while(n>0){
    res += n%10;
    n/=10;
  }
  return res;
}

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

  ll k;
  cin >> k;
  ll keta = 10;
  vector<ll> tsnuke;
  vector<ll> snuke;
  rep1(i,9) snuke.pb(i);


  while(1){
    ll cn = snuke.size();
    if(k <= snuke.size()) break;
    tsnuke.clear();
    rep(i,cn){
      rep1(j,9){
        tsnuke.pb(keta*j+snuke[i]);
      }
    }
    sort(tsnuke.begin(),tsnuke.end(),[](auto const& lhs, auto const& rhs){
      return lhs*s(rhs) < rhs * s(lhs);
    });
    ll cmax = tsnuke[0];
    rep(i,tsnuke.size()){
      if(cmax <= tsnuke[i]) {
        snuke.pb(tsnuke[i]);
        cmax = tsnuke[i];
      }
    }
    keta *= 10;
  }
  rep(i,k){
    cout << snuke[i] << endl;//<<  " " << ((long double)((snuke[i])))/((long double)(s(snuke[i]))) << endl;
  }
  // rep(i,k){
  //   if(i%10==9){
  //     cout << i << " " << ((long double)((i)))/((long double)(s(i))) << endl;
  //   }

  // }

return 0;
    

}


Measured memory_bytes: 384
/*
 *
 */
#include <cstdio>
#include <iostream>

typedef long long ll;
using namespace std;

ll N, K;
ll A[100005], B[100005];
ll ans = 0LL;


bool check(ll Ai, ll k) {
    do {
        if (((Ai & 1LL) == 1LL) && ((k & 1LL) == 0LL)) {
            return false;
        }
        Ai >>= 1;
        k >>= 1;
    } while (Ai > 0 || k > 0);
    return true;
}


ll calc_max_k(ll k) {
    ll a = 0LL;
    for (int i = 0; i < N; ++i) {
        if (check(A[i], k)) {
            a+= B[i];
        } else {
            // cout << "false" << A[i] << k << endl;
        }
    }
    return a;
}


ll loop_k(ll k, ll parent) {
    ll ref_k = 1LL;
    ll k2 = k >> 1;
    while (k2 > 0) {
        //cout << "k" << k << endl;
        k2 >>= 1;
        ref_k <<= 1;
    }
    // 1. check ref_k - 1
    //cout << "check" << parent + ref_k - 1 << endl;
    ll a = calc_max_k(parent + ref_k - 1);
    ans = max(a, ans);

    // 2. check ref_k with highest 1 fixed, recursively
    ll next_k = k - ref_k;
    ll next_parent = parent + ref_k;
    if (next_k >= 0) {
        //cout << "next_k, next_parent, ref_k, k" << next_k << next_parent << ref_k << k << endl;
        loop_k(next_k, next_parent);
    } else {
        // check original value
        //cout << "check" << k + parent << endl;
        a = calc_max_k(k + parent);
        ans = max(a, ans);
    }
    return ans;
}


int main(){
    //freopen("d3.in", "r", stdin);

    cin >> N >> K;
    for (ll i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }
    ll ans = loop_k(K, 0LL);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int min(int x, int y) {
    return (x < y) ? x : y;
}

int abs(int x) {
    return (x > 0) ? x : (-1 * x);
}

int main() {
    int n;
    scanf("%d", &n);
    int dp[n], nums[n];
    dp[0] = 0;

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

    for (int i = 1; i < n; i++) {
        if (i == 1) dp[i] = abs(nums[1] - nums[0]);
        else dp[i] = min(dp[i - 1] + abs(nums[i] - nums[i - 1]), dp[i - 2] + abs(nums[i] - nums[i - 2])); 
    }

    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		Set<Integer> set1 = new TreeSet<>();
		Set<Integer> set2 = new HashSet<>();
		for (int i = 0; i < n; i++) {
			set1.add(sc.nextInt());
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			set2.add(sc.nextInt());
		}
		Set<Integer> set3 = new HashSet<>(set2);
		set2.retainAll(set1);
		set3.removeAll(set2);
		set1.removeAll(set2);
		set1.addAll(set3);
		for (int num : set1) {
			sb.append(num);
			sb.append('\n');
		}
		System.out.print(sb.toString());
	}
}



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

int main(){
	int n,m,i;
	cin>>n>>m;
	int arr[n],tot=0,count=0;
	for(i=0;i<n;i++){
		cin>>arr[i];
		tot+=arr[i];
	}
	float temp=1.0*tot/(4*m);
	for(i=0;i<n;i++){
		if(arr[i]>=temp) count++;
	}
	if(count>=m) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

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

int main(void)
{
    string s;
    int count = 0;
    bool flag =false;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(i == 0){
            if(s[i] == 'R'){
                count++;
            }
        }
        else{
            if(s[i] == 'R' && s[i - 1] == 'R'){
                count++;
            }
            else if(s[i] == 'R' && count == 0){
                count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3592
r = list(map(int,input().split()))
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if r[0]==2 or r[0]==2:
  print('No')
elif len(list(set(r) & set(a))) == 2:
  print('Yes')
elif len(list(set(r) & set(b))) == 2:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9176
// header {{{
using namespace std;

// C++
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#pragma GCC optimization_level 3

// util {{{
#define print(x)	        cout << (x)
#define printvec(x)       for(int i = 0;i < (x).size();i++)cout << (x).at(i) << " ";cout << endl
#define println(x)	        cout << (x) << endl
#define printn		        cout << endl
#define read(x)	            cin >> (x)
#define readvec(x)        for(int i = 0; i < (x).size();i++)cin >> (x).at(i)

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

#define all(x) 		        (x).begin(),(x).end()
#define vint                vector<int>
#define outif(x,y,z)        if(x) cout<<(y)<<endl; else cout<<(z)<<endl
#define loop 		        while(true)

// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

void solve() {
    vector<pair<int,int>> vec;
    loop{
        int a,b;
        pair<int,int> pairs;
        read(a);
        read(b);
        if(a == b && b == 0)break;
        if(a > b){
            pairs.first = b;
            pairs.second = a;
        } else {
            pairs.first = a;
            pairs.second = b;
        }
        vec.push_back(pairs);
    }
    rep(i,vec.size()){
        cout << vec.at(i).first << " " << vec.at(i).second << endl;
    }
}

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


Measured memory_bytes: 3164
#include<stdio.h>
#include<stdlib.h>
int main() {
	int a, b, c, d;
	scanf("%d %d %d %d", &a,&b,&c,&d);//とりあえず値を代入

	if(abs(c-a)<= d){
		printf("Yes\n");
	}
	else if ((abs(c - b) <= d) && (abs(b - a) <= d)) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)

int n, q;
vector<int> edge[200020];
vector<ll> vec;
void dfs(int v, int p) {
    for(auto nv : edge[v]) {
        if(nv == p) continue;
        vec[nv] += vec[v];
        dfs(nv, v);
    }
}

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

    cin >> n >> q;
    rep(_, n-1) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        edge[x].emplace_back(y);
        edge[y].emplace_back(x);
    }
    vec.resize(n);
    rep(i, q) {
        int p, x; cin >> p >> x;
        p--;
        vec[p] += x;
    }
    dfs(0, -1);
    rep(i, n) cout << vec[i] << (i == n-1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 24320
# 通らなかった

n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
m = max(max(x), a)
dp = [[[0 for _ in range(n*m+1)] for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for j in range(1, n+1):
  for k in range(n+1):
    for s in range(n*m+1):
      if s<x[j-1]:
        dp[j][k][s] = dp[j-1][k][s]
      elif k>=1:
        dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-x[j-1]]
ans = 0
for i in range(1, n+1):
  ans += dp[n][i][i*a]
print(ans)

Measured memory_bytes: 98524
#include<iostream>
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<<"Balanced\n";
  }
  else if (l>r)
  {
    cout<<"Left\n";
  }
  else if (l<r)
  {
    cout<<"Right\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n,k,s;
    cin>>n>>k>>s;

    for(int i=0;i<n;i++){
        if(i<k)cout<<s;
        else {
            if((i-k)%s!=s-1)cout<<1;
            else {
                if(s+1<1000000000)cout<<s+1;
                else cout <<1;
            }
        }

        if(i<n-1)cout<<" ";
        else cout<<endl;
        
    }

    return 0;

}

Measured memory_bytes: 1280
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    string S;
    cin >> N >> S;
    vector<char> rgb = {'R', 'G', 'B'};
    vector<int> rgb_count(3, 0);
    rep(i, 3){
        rep(j, N){
            if(S[j] == rgb[i]) rgb_count[i]++;
        }
    }

    ll ans = 1;
    rep(i, 3) ans *= rgb_count[i];
    
    for(int i = 1; i <= (N - 1)/2; i++){
        for(int j = 0; j + 2 * i < N; j++){
            if(S[j] != S[j + i] && S[j + i] != S[j + 2 * i] && S[j] != S[j + 2 * i]){
                ans--;
            }
        }
    }

    cout << ans << endl;   
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri(), m = ri();
	int k = ri();
	int64_t sum0[n + 1];
	sum0[0] = 0;
	for (int i = 0; i < n; i++) sum0[i + 1] = sum0[i] + ri();
	
	int64_t sum1[m + 1];
	sum1[0] = 0;
	for (int i = 0; i < m; i++) sum1[i + 1] = sum1[i] + ri();
	
	int res = 0;
	int head = 0;
	for (int i = m; i >= 0; i--) {
		while (head <= n && sum0[head] + sum1[i] <= k) head++;
		if (head) res = std::max(res, head + i - 1);
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 6892
//
// Created on 2020/08/15.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    double ans = 0;
    for (int i = 0; i < n; ++i) {
        double x;
        string y;
        cin>>x>>y;
        if(y == "JPY"){
            ans += x;
        }else{
            ans += (x * 380000.0);
        }
    }

    printf("%.10f\n", ans);
    return 0;
}


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

//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;

void solve1()
{
	string a, b, c;
	cin >> a;
	b = a;
	reverse(b.begin(), b.end());
	if(a != b){
		cout << "No";
		return;
	}
	b = a.substr(0, a.size() / 2);
	c = b;
	reverse(c.begin(), c.end());
	if(b != c){
		cout << "No";
		return;
	}
	b = a.substr((a.size() + 3) / 2 - 1, a.size() / 2);
	c = b;
	reverse(c.begin(), c.end());
	if(b != c){
		cout << "No";
		return;
	}
	cout << "Yes";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int  mod = 1e9 + 1;

int main() {
	int n; cin >> n;
	set<string>s;
	while (n--) {
		string st; cin >> st;
		s.insert(st);
	}
	cout << s.size();
	return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 5*1e5;
int n, m;

int arr[N+5];
int occur[N+5];
int BIT[N+5];

struct node{
    int l, r, i;
} q[N];

int block;
int result[N+5];

bool cmp(node a, node b){
    return a.r < b.r;
}

int sum(int pos){
    pos+=1;
    int sum=0;
    while(pos>0){
        sum+=BIT[pos];
        pos-=pos&(-pos);
    }
    return sum;
}

void update(int pos, int val){
    pos+=1;
    while(pos<=n){
        BIT[pos]+=val;
        pos+=pos&(-pos);
    }
}



int main(){
    AC
    cin>>n>>m;
    block = sqrt(n);
    for(int i=0; i<n; i++){
        cin>>arr[i];
    }
    for(int i=0; i<m; i++){
        int l, r;
        cin>>l>>r;
        q[i].l = --l;
        q[i].r = --r;
        q[i].i = i;
    }

    sort(q, q+m, cmp);
    memset(occur, -1, sizeof(occur)); 

    int start=0;
    for(int i=0; i<m; i++){
        int L = q[i].l, R = q[i].r;
        //cout<<"current L and R "<<L<<" "<<R<<endl;
        for(int j=start; j<=R; j++){
            if(occur[arr[j]]>=0) update(occur[arr[j]], -1);
            update(j, 1);
            occur[arr[j]] = j;
        }
        start = R+1;
        result[q[i].i] = sum(R)-sum(L-1);
        //cout<<sum(R)<<" "<<sum(L-1)<<endl;
    }

    for(int i=0; i<m; i++){
        cout<<result[i]<<endl;
    }

}

Measured memory_bytes: 17376
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    a,b,c,d = LMIIS()
    ans = -10**20
    for i in [a,0,b] if a<= 0 <= b else [a,b]:
        for j in [c,0,d] if c <= 0 <= d else [c,d]:
            ans = max(ans,i*j)
    print(ans)
    
main()

Measured memory_bytes: 65216
import java.util.Scanner;
public class Main {
	private static Scanner stdIn;
	public static void main(String args[]){
		stdIn = new Scanner(System.in);
		String s = stdIn.next();
		String a = s.substring(0,5);
		String b = s.substring(6,13);
		String c = s.substring(14);
		
		System.out.println(a+' '+b+' '+c);
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    string str = "";
    while(N != 0) {
        int r = N % 2;
        if(r < 0) r += 2;

        N = (N - r) / (-2);

        str += (char)('0' + r);
    }

    reverse(str.begin(), str.end());

    if (str == "") str = "0";
    cout << str << endl;

    return 0;
}



Measured memory_bytes: 256
use std::io::prelude::*;
use std::{io};
use std::collections::{HashMap, HashSet, VecDeque};
use std::cmp::Ordering;

fn string_to_nums(s: String) -> Vec<isize> {
    let mut v = Vec::new();
    for part in s.split_whitespace() {
        v.push(part.parse::<isize>().unwrap())
    }
    v
}

fn read_a_line() -> String {
    let mut s = String::new();
    assert!(io::stdin().read_line(&mut s).is_ok());
    s.trim().to_string()
}

fn read_nums() -> Vec<isize> {
    string_to_nums(read_a_line())
}

fn read_next(bytes: &mut io::Bytes<io::Stdin>) -> u64 {
    let mut n = 0;
    while let Some(b) = bytes.next() {
        let b = b.unwrap();
        if b == 32 || b == 10 { return n; }
        n = n * 10 + (b - 48) as u64;
    }
    return n;
}

fn main() {
    let t = read_nums();
    let n = t[0] as u64;
    let t = t[1] as u64;

    let mut bytes = io::stdin().bytes();
    let mut total = 0u64;
    let mut last = read_next(&mut bytes);
    for _ in 1..n {
        let ti = read_next(&mut bytes);
        if ti - last < t {
            total += ti - last
        }
        else {
            total += t
        }
        last = ti;
    }
    total += t;
    println!("{}", total);
}


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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  int q = 'A' - 'a';
  printf("%c%c%c\n", a[0]+q, b[0]+q, c[0]+q);
  return 0;
}


Measured memory_bytes: 256