akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;
//int t[10010];

int main()
{
    int s;
    cin >> s;
    set<int> st;

    int x = s;
    while (st.count(x) == 0)
    {
        st.insert(x);
        if (x % 2 == 0)
        {
            x /= 2;
        }
        else
        {
            x = 3 * x + 1;
        }
    }

    Cout(st.size() + 1);

    return 0;
}

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

int main(){
    int t;
    scanf("%d",&t);
    int a[t];
    for(int i = 0; i < t; ++i){
        scanf("%d",&a[i]);
    }
    int dp[t];
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2; i<t; ++i){
        if (dp[i-2]+abs(a[i]-a[i-2]) < dp[i-1] + abs(a[i-1]-a[i])){
            dp[i] = dp[i-2] + abs(a[i-2]-a[i]);
        }
        else{
            dp[i] = dp[i-1] + abs(a[i-1]-a[i]);
        }
    }
    printf("%d",dp[t-1]);
}


Measured memory_bytes: 1024
#pragma GCC optimize ("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<cmath>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<valarray>
#include<vector>
#include<array>
#include<forward_list>
#include<random>
#include<ratio>
#include<tuple>
#include<unordered_map>
#include<unordered_set>
#include<cstring>

using namespace std;
using Int = long long; using uint = unsigned int; using uInt = unsigned long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 998244353;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rer(i,l,r) for(int i=(l); i<=(r); ++i)
#define gnr(i,l,r) for(int i=(r); i>=(l); --i)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
#define priend(a) {cout<<(a)<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  cin>>m>>q;
  if(q>=(1<<m))priend(-1);
  if(!q){
    rep(i,(1<<m))cout<<i<<' '<<i<<(i==(1<<m)-1?'\n':' ');
    return 0;
  }
  if(m==1)priend(-1);
  cout<<0<<' '<<q<<' '<<0;
  rer(i,1,q-1)cout<<' '<<i;
  rer(i,q+1,(1<<m)-1)cout<<' '<<i;
  cout<<' '<<q;
  gnr(i,q+1,(1<<m)-1)cout<<' '<<i;
  gnr(i,1,q-1)cout<<' '<<i;
  cout<<'\n';
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, FastReader in, PrintWriter out) {

            int n = in.nextInt();
            int te = n;

            char[] a = in.nextLine().toCharArray();

            for (int i = 1; i < n; i++) {
                if (a[i - 1] == a[i]) te--;
            }
            out.println(te);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}



Measured memory_bytes: 25044
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 200010
using namespace std;
typedef long long ll;
int n;
int a[maxn];
int f[maxn][35];
int now[35];
ll ans;
bool check()
{
	for(int i=0;i<=20;i++)
	{
		if(now[i]>1)  return true;
	}
	return false;
}
void add(int x)
{
	for(int i=0;i<=20;i++)  now[i]+=f[x][i];
}
void del(int x)
{
	for(int i=0;i<=20;i++)  now[i]-=f[x][i];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)  scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=20;j>=0;j--)
		{
			if(a[i]&(1<<j))
			{
				f[i][j]=1;
			}
		}
	}
	int l=1,r=1;
	add(1);
	while(r<=n)
	{
		while(check()==true&&l<=n)
		{
			del(l);
			l++;
		}
//		cout<<l<<" "<<r<<endl;
		ans+=(ll)r-l+1;
		r++;
		add(r);
		//cout<<l<<" "<<r<<endl;
		//del(l);
		//l++;
		//cout<<"*"<<endl;

		//cout<<l<<" "<<r<<endl;
		//ans+=(ll)r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
#define ll long long int
vector<int> adj[2007];
ll dp[2007][2007];
int vis[2007];
int main()
{
    int n,x,y;
    cin >> n >> x >> y;
    for(int i=1;i<n;i++){
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);
    unordered_map<ll,ll> mp;
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        vector<ll> dist(n+1);
        queue<int> q;
        q.push(i);
        dist[i]=0;
        vis[i]=1;
        while(!q.empty()){
            int u = q.front();q.pop();
            for(auto v:adj[u]){
                if(!vis[v]){
                    dist[v] = dist[u]+1;
                    vis[v] = 1;
                    q.push(v);
                }
            }
        }
        for(int j=1;j<=n;j++) mp[dist[j]]++;
    }
    for(int i=1;i<n;i++) cout << mp[i]/2 << endl;
}


Measured memory_bytes: 512
n = int(input())
tmp = n
fact =  []
for i in range(2,int(-(-n**0.5//1))+1):
    while tmp%i == 0:
            fact.append(str(i))
            tmp //= i
            
if tmp != 1:
    fact.append(str(tmp))

#print(fact)
            
print(str(n) + ': ' + " ".join(fact))


Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
vector< ll > divisor(ll n) {  //公約数の列挙
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
    ll n,m;
    std::cin >> n>>m;
    std::vector<ll> di;
    di=divisor(m);
    ll ans=1ll;
    rep(i,di.size()){
        if(m/di[i]>=n)ans=di[i];
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


ll gcd(ll x,ll y){
  return y==0? x:gcd(y,x%y);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  int ans = 0;
  repeat(i,N){
    int l,r;cin>>l>>r;l--;
    ans +=r-l;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string S; cin >> S;

    char now = S[0];
    int ans = 0;
    for(int i = 1; i < S.size(); i++){
        if (now != S[i]){
            ans += 1;
            now = S[i];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3628
// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);
const int maxm = 100001;

int find(int i,int *par) 
{ 
    if(par[i] != i) 
    { 
        par[i] = find(par[i],par);
    }

    return par[i];
}

void merge(int a,int b,int *par){
   a = find(a,par);
   b = find(b,par);
   par[a]= b;
}

void solve()
{

    int n,m;
    cin>>n>>m;
    int par[n];

    loop(i,0,n)
    par[i]=i;
    
    loop(i,0,m){
        int d,b;
        cin>>d>>b;
        d--;b--;
        merge(d,b,par);
    }

    map<int,int>a;

    loop(i,0,n){
       int p = find(par[i],par);
       a[p]++;
    }
    int l=0;

    loopit(a)
    l = max(l,it->ss);

    cout << l << "\n";
}

int main()
{
    

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    io;
    solve();

    return 0;
}


Measured memory_bytes: 13692
#include<stdio.h>
int main(void)
{
	int x, y;
	x = y = 1;

	while (x!=0||y!=0)
	{
		scanf("%d %d", &x, &y);

		if (x != 0 || y !=0)
		{
			if (x <= y)
			{
				printf("%d %d\n", x, y);
			}

			if(y<x)
			{
				printf("%d %d\n", y, x);
			}
		}

		else
		{

		}
	}

	return 0;
}


Measured memory_bytes: 2104
#include<iostream>

using namespace std;

int main()
{
   
    int a,b,c,d;
    cin >> a;
    
    cin >> b>>c>>d;
    
    bool ok=false;
    bool ok1=false;
    bool ok2=false;
if(abs(a-b)<=d){
    ok1=true;
}
    if(abs(b-c)<=d){
        ok2=true;
    }
if(abs(a-c)<=d){
    ok=true;
}
    if(ok1&&ok2){
        ok=true;
    }

    if(ok){
        printf("Yes");
    }
    else
        printf("No");


    return 0;
}

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

#define N_MAX 101

int main(){

  int N, A[N_MAX], s, smax;
  cin >> N;
  for(int i = 0; i < N; i++) cin >> A[i];

  smax = 0;
  for(int i = 0; i < N-1; i++){
    for(int j = i+1; j < N; j++){
      s = A[i] - A[j];
      if(s < 0) s *= -1;
      if(smax < s) smax = s;
    }
  }

  cout << smax << endl;

  return 0;
}


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

int main(){
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;
    string ans = "";
    rep(i,n){
        ans = ans + s[i] + t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
S = list(s)
S0 = list(s)

for i in range(len(S0)):
  if(i != 0):
   if(len(S)%2 == 0):
    index = int(len(S)/2)-1
    str1 = ''.join(S[:index+1])
    str2 = ''.join(S[index+1:])
    #print(str1)
    #print(str2)
    if(str1 == str2):
      print(len(str1)*2)
      break     
  S.pop(-1)

Measured memory_bytes: 3060
N = int(input())
L = list(map(int, input().split()))
L.reverse()
lim = int(N/2)
if N%2 == 0:
    for i in range(lim):
        print(str(L[2*i]) + ' ', end="")

    L.reverse()
    for i in range(int(N/2)):
        print(str(L[2*i]) + ' ', end="")
else:
    lim += 1
    for i in range(lim):
        print(str(L[2*i]) + ' ', end="")

    L.reverse()
    for i in range(int(N/2)):
        print(str(L[2*i+1]) + ' ', end="")

Measured memory_bytes: 26020
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=110;
int a,b;

int main()
{
    while (scanf("%d%d",&a,&b)!=EOF)
    {
        printf("%d\n",a*b-a-b+1);
    }
    return 0;
}


Measured memory_bytes: 256
def readinput():
    n=int(input())
    x=list(map(int,input().split()))
    return n,x

def mean(x):
    sum=0
    for _ in x:
        sum+=_
    return sum/len(x)

def rss(x,xbar):
    sum=0
    for _ in x:
        sum+=(_-xbar)**2
    return sum

def main(n,x):
    ans=0
    xbar=mean(x)
    xbar_int=xbar//1
    if(xbar-xbar_int >0.5):
        xbar_int+=1
    ans=rss(x,xbar_int)
    return int(ans)

def main2(n,x):
    xmin=min(x)
    xmax=max(x)
    minsum=1000000

    for p in range(xmin,xmax+1):
        sum=0
        for xx in x:
            sum+=(xx-p)**2
        if(sum<minsum):
            minsum=sum

    return minsum

if __name__=='__main__':
    n,x=readinput()
    ans=main(n,x)
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];

  ll cur = 0;
  //操作回数を考える
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) continue;
    if (a[i] < b[i]) {
      int d = (b[i] - a[i]) / 2;
      cur += d;
    } else {
      cur -= (a[i] - b[i]);
    }
  }
  if (cur >= 0LL) {
    cout << "Yes" << endl;
  } else cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 384
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let s: usize = iterator.next().unwrap().parse().unwrap();

    let mut result = String::new();

    for i in 0..n {
        if i < k {
            result.push_str(&format!("{} ", s));
        } else {
            if s == 1_000_000_000 {
                result.push_str(&format!("{} ", 1));
            } else {
                result.push_str(&format!("{} ", 1_000_000_000));
            }
        }
    }

    return result.trim().to_string();
}


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

int main() {
  int N = 0;
  cin >> N;
  string color;
  
  for (int i = 0; i < N; i++){
    cin >> color;
    
    if (color=="Y"){
      cout << "Four" << endl;
      break;  
    }
  }
  if (color != "Y")
    cout << "Three" << endl;
}

Measured memory_bytes: 256
// Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
typedef long long LL;
const int MAXN = 2000;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}
inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, dp[MAXN + 5][MAXN +5];
int a[2 * MAXN + 5];
char c[MAXN * 2 + 5];
int pre_b[MAXN * 2 + 5][MAXN + 5], pre_w[MAXN * 2 + 5][MAXN + 5];
int pos_b[MAXN + 5], pos_w[MAXN + 5];

void init() {
  //enableFileIO();

  n = read();
  for (int i = 1; i <= 2 * n; ++i) {
    c[i] = getchar();
    while (c[i] != 'W' && c[i] != 'B') c[i] = getchar();
    a[i] = read();
    if (c[i] == 'W') {
      pos_w[a[i]] = i;
    } else {
      pos_b[a[i]] = i;
    }
  }
  for (int i = 1; i <= 2 * n; ++i) {
    for (int j = 0; j <= n; ++j) {
      pre_w[i][j] = pre_w[i - 1][j] + (a[i - 1] > j && c[i - 1] == 'W');
      pre_b[i][j] = pre_b[i - 1][j] + (a[i - 1] > j && c[i - 1] == 'B');
    }
  }
}
int main() {
  init();

  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (!i && !j) continue;
      int pw = pos_w[i], pb = pos_b[j];
      if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + pre_w[pw][i - 1] + pre_b[pw][j]); 
      if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + pre_w[pb][i] + pre_b[pb][j - 1]);
    }
  }
  printf("%d\n", dp[n][n]);
  return 0;
}

Measured memory_bytes: 78720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	vector<int> h(n+1,0);
	FOR(i,1,n+1) cin>>h[i];
	vector<vector<ll>> dp(n+1,vector<ll>(n+1,inf));
	dp[0][0]=0;
	rep(i,n-k)FOR(j,i+1,n+1){
		FOR(x,i,j){
			chmin(dp[i+1][j],dp[i][x]+max(0,h[j]-h[x]));
		}
	}
	cout<<*min_element(begin(dp[n-k]),end(dp[n-k]))<<endl;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))

from itertools import accumulate
accum = list(accumulate(a))

i_left = 0
i_right = 2
ans = 10**18
for i in range(1, n-2):
    while True:
        p = accum[i_left]
        q = accum[i] - p
        p_new = accum[i_left+1]
        q_new = accum[i] - p_new
        if abs(p_new - q_new) < abs(p - q):
            i_left += 1
        else:
            break
    while True:
        r = accum[i_right] - accum[i]
        s = accum[-1] - accum[i_right]
        r_new = accum[i_right+1] - accum[i]
        s_new = accum[-1] - accum[i_right+1]
        if abs(r_new - s_new) < abs(r - s):
            i_right += 1
        else:
            break

    # print(p, q, r, s)
    diff = max([p, q, r, s]) - min([p, q, r, s])
    ans = min(ans, diff)

print(ans)


Measured memory_bytes: 25068
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll h, w;
    cin>>h>>w;
    vector<string> grid(h);
    cin>>grid;

    UnionFind ds(h * w);
    rep(i, h) rep(j, w) {
        if (i - 1 >= 0 && grid[i][j] != grid[i - 1][j]) ds.merge(i * w + j, (i - 1) * w + j);
        if (i + 1 < h && grid[i][j] != grid[i + 1][j]) ds.merge(i * w + j, (i + 1) * w + j);
        if (j + 1 < w && grid[i][j] != grid[i][j + 1]) ds.merge(i * w + j, i * w + j + 1);
        if (j - 1 >= 0 && grid[i][j] != grid[i][j - 1]) ds.merge(i * w + j, i * w + j - 1);
    }

    vl bs(h * w);
    vl ws(h * w);
    rep(i, h) rep(j, w) {
        if (grid[i][j] == '#') bs[ds.root(i * w + j)]++;
        else ws[ds.root(i * w + j)]++;
    }
    ll ans = 0;
    rep(i, h * w) {
        ans += bs[i] * ws[i];
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
	int n;
	vector<int> a;
	vector<int> box;
	vector<int> ans;

	cin >> n;
	a.resize(n + 1);
	box.resize(n + 1);
	
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}

	for(int i = n; i >= 1; --i)
	{
		int sum = 0;
		for(int j = i + i; j <= n; j += i)
		{
			sum += box[j];
		}
		box[i] = (a[i] == 0 ? sum % 2 : (sum + 1) % 2);
		if(box[i] == 1) ans.push_back(i);
	}

	cout << ans.size() << endl;
	if(ans.size() > 0)
	{
		cout << ans[0];
		for(int i = 1; i < ans.size(); ++i)
		{
			cout << " " << ans[i];
		}
		cout << endl;
	}
}

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

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a,b, n;
cin >> a >> b;
n = max(a+b, a-b);
n = max(n, a*b);
cout << n << "\n";
return 0;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  string s[50];
  int dx[8] = {1, 0, -1, 1, -1, 1, 0, -1};
  int dy[8] = {1, 1, 1, 0, 0, -1, -1, -1};
  
  for(int i=0;i<h;++i){
    cin >> s[i];
  }
  
  for(int i=0;i<h;++i){
    for(int j=0;j<w;j++){
      if(s[i][j] == '#') continue;
      int count=0;
      for(int d=0;d<8;++d){
        int ni = i + dx[d];
        int nj = j + dy[d];
        
        if(ni < 0 || ni >= h) continue;
        if(nj < 0 || nj >= w) continue;
        if(s[ni][nj] == '#') count++;
      }
      s[i][j] = char(count+'0');
    }
  }
  
  for(int i=0;i<h;++i) cout << s[i] << endl;
}

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


int main(){
  int cnt = 0;
  string s;
  cin >> s;
  rep(i,3){
    if(s.at(i) == '1') cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// DFSの場合

func main() {
	N, M, X := nextInt(), nextInt(), nextInt()
	Cn := make([]int, N)
	Anm := make([][]int, N)
	A := make([]int, 0)
	ans := int(1e7)
	for i := range Anm {
		Anm[i] = make([]int, M)
	}
	for i := 0; i < N; i++ {
		Cn[i] = nextInt()
		for j := 0; j < M; j++ {
			Anm[i][j] = nextInt()
		}
	}
	dfs(A, Cn, Anm, N, M, X, &ans)
	if ans == int(1e7) {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func dfs(A []int, Cn []int, Anm [][]int, N, M, X int, ans *int) {
	if len(A) == N {
		check := make([]int, N)
		if !reflect.DeepEqual(A, check) {
			sum := 0
			checkUS := make([]int, M)
			for i := 0; i < N; i++ {
				if A[i] == 1 {
					sum += Cn[i]
					for j := 0; j < M; j++ {
						checkUS[j] += Anm[i][j]
					}
				}
				isOk := true
				for _, v := range checkUS {
					if v < X {
						isOk = false
					}
				}
				if isOk {
					if *ans > sum {
						*ans = sum
					}
				}
			}
		}
		return
	}

	for i := 0; i < 2; i++ {
		A = append(A, i)
		dfs(A, Cn, Anm, N, M, X, ans)
		A = A[:len(A)-1]
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int w, h, n;
    cin >> w >> h >> n;

    bool cood[109][109];
    for (int i = 0; i < 109; i++) {
        for (int j = 0; j < 109; j++) {
            cood[i][j] = false;
        }
    }

    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        
        if (a == 1) {
            // cout << "------------------- 1 ------------------------" << endl;
            for (int j = 0; j < h; j++) {
                for (int k = 0; k < x; k++) {
                    // printf("(x, y) = (%d, %d)\n", k+1, j+1);
                    cood[j][k] = true;
                }
            }
        } else if (a == 2) {
            // cout << "------------------- 2 ------------------------" << endl;
            for (int j = 0; j < h; j++) {
                for (int k = x; k < w; k++) {
                    // printf("(x, y) = (%d, %d)\n", k+1, j+1);
                    cood[j][k] = true;
                }
            }
        } else if (a == 3) {
            // cout << "------------------- 3 ------------------------" << endl;
            for (int j = 0; j < y; j++) {
                for (int k = 0; k < w; k++) {
                    // printf("(x, y) = (%d, %d)\n", k+1, j+1);
                    cood[j][k] = true;
                }
            }
        } else if (a == 4) {
            // cout << "------------------- 4 ------------------------" << endl;
            for (int j = y; j < h; j++) {
                for (int k = 0; k < w; k++) {
                    // printf("(x, y) = (%d, %d)\n", k+1, j+1);
                    cood[j][k] = true;
                }
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (cood[i][j]) cnt++;
        }
    }

    cout << h*w - cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  map<char, bool> validChar = {
    {'A', true},
    {'C', true},
    {'G', true},
    {'T', true}
  };

  string s;
  cin >> s;
  int max_v = 0;
  rep(i, 0, s.size()) {
    if(!validChar[s[i]]) continue;
    int tmp = 1;
    rep(j, i + 1, s.size()) {
      if(!validChar[s[j]]) break;
      ++tmp;
    }
    chmax(max_v, tmp);
  }
  cout << max_v << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b; cin >> x >> a >> b;
    if (abs(x - a) < abs(b - x)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
    
}




Measured memory_bytes: 256
#!/usr/bin/env python3
#AOJ A

while 1:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    taro = [int(input()) for _ in range(n)]
    hanako = [int(input()) for _ in range(m)]
    change = []
    for i in range(n):
        for j in range(m):
            taro[i],hanako[j] = hanako[j],taro[i]
            if sum(taro) == sum(hanako):
                change.append([hanako[j],taro[i],taro[i]+hanako[j]])
            taro[i],hanako[j] = hanako[j],taro[i]
    #print(change)
    change = sorted(change, key = lambda x:x[2])
    if len(change) == 0:
        print(-1)
    else:
        print(change[0][0],change[0][1])


Measured memory_bytes: 6508
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  int count=0;
  cin >> S;
  for(int i=0; i<3; i++){
    if(S.at(i)==S.at(i+1))
      count++;
  }
  if(count==0)
    cout << "Good" << endl;
  else
    cout << "Bad" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// D - All Your Paths are Different Lengths

using namespace std;

vector<pair<pair<int,int>,int>> edges;

int main() {
    int L,N,i;

    scanf("%d",&L);

    N = log2(L) + 1;

    for (i = 1;i < N;i++) {
        edges.push_back({{i,i + 1},0});
        edges.push_back({{i,i + 1},1 << (i - 1)});
    }

    i = (1 << (N - 1));
    while (i < L) {
        edges.push_back({{log2(L - i) + 1,N},i});
        i += (1 << (int) (log2(L - i)));
    }

    printf("%d %d\n",N,edges.size());
    for (pair<pair<int,int>,int> p : edges)
        printf("%d %d %d\n",p.first.first,p.first.second,p.second);

    return 0;
}


Measured memory_bytes: 256
n, W = map(int,input().split())
dp = [0]+[W+1]*(10**5)
maxv=0
for i in range(n):
  w,v= map(int,input().split())
  for j in range(10**5-v,-1,-1):
  	cw=w+dp[j]
  	if cw<=W:
  		dp[j+v]=min(dp[j+v],cw)
  		maxv=max(maxv,j+v)
print(maxv)

Measured memory_bytes: 69716
n = int(input())
a = list(map(int,input().split()))
l = len(a)
b = [a[i]-(i+1) for i in range(n)]
b = sorted(b)
mid = b[l//2]
sum = 0
for i in range(n):
    sum+=abs(a[i]-(mid+(i+1)))
print(sum)


Measured memory_bytes: 26020
#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pb push_back
#define log(x,b) (log(b)/log(x))
#define rep(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int mod=1e9+7;
int32_t main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int g=__gcd(a,b);
    if(c%g==0)puts("YES");
    else puts("NO");

    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <climits> 



int main()
{
    long N;
    std::cin >> N;
    long A[100];
    for(long i=0; i<N; i++){
        std::cin >> A[i];
    }

    bool flag=true;
    for(long i=0; i<N; i++){
        if(A[i]%2==0){
            if(A[i]%3!=0 && A[i]%5!=0){
                flag=false;
                break;
            }
        }
    }
    if(flag){
        std::cout << "APPROVED" << std::endl;
    }else{
        std::cout << "DENIED" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
int N, A[3][3], b[10];
 bool appear[3][3];
 int main() {
 for(int i = 0; i < 3; i++) {
 for(int j = 0; j < 3; j++) cin >> A[i][j];
 }
 cin >> N;
 for(int i = 0; i < N; i++) cin >> b[i];
 for(int i = 0; i < N; i++) {
 for(int j = 0; j < N; j++) {
 appear[i][j] = false;
 for(int k = 0; k < N; k++) {
 if(A[i][j] == b[k]) appear[i][j] = true;
 }
 }
 }
 string ANS = "No";
 for(int i = 0; i < 3; i++) {
 if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
 }
 for(int i = 0; i < 3; i++) {
 if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
 }
 if(appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
 if(appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
 cout << ANS << endl;
 return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n, a = 0, b = 0, c = 0;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a') a++;
    if (s[i] == 'b') b++;
    if (s[i] == 'c') c++;
  }
  
  set<int> S;
  S.insert(a);
  S.insert(b);
  S.insert(c);
  
  if (S.size() > 2) cout << "NO" << endl;
  if (S.size() == 1) cout << "YES" << endl;
  if (S.size() == 2) {
    vector<int> v;
    for (auto ite = S.begin(); ite != S.end(); ite++) {
      v.push_back(*ite);
    }
    sort(v.begin(),v.end());
    if (v[1]-v[0] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}


Measured memory_bytes: 512
import heapq

n, m = map(int, input().split())
num = sorted([list(map(int, input().split())) for i in range(n)], key = lambda x: x[0])

s = []
j = 0
count = 0
heapq.heapify(s)

for i in range(1, m + 1):
  while (j < n and num[j][0] <= i):
    heapq.heappush(s, num[j][1] * (-1))
    j += 1
  if(len(s)):
    count += heapq.heappop(s) * (-1)

print(count)


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

int main() {
    int n,cnt=0;
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    rep(i,n-1) {
        if (p[i]==i+1) {
            swap(p[i],p[i+1]);
            cnt++;
        }
    }
    if (p[n-1]==n) cnt++;
    cout<<cnt<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG other_contests/soundhound_2018/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;
#define INF (1e16)

/*
方針
- sからのdijkstra(円で計算)
- tからのdijkstra(スヌークで計算)
をそれぞれ作る O((E + V)logV)
その後，n個の駅のどこで両替をするか線形に探索．最適解を出力． O(V)
V = 10^5，E = 10^5なら終わる
*/

int n, m, s, t;

vector<vector<vector<int>>> g;
// i駅から行けるj番目の路線の行き先がk = 0，料金がk = 1(円)，k = 2(snook)

vector<ll> yen;
vector<ll> snook;

void dijkstra(){
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    q.push(make_pair(0, s));
    vector<int> visited(n + 1);
    for(int i = 1; i <= n; i++){
        visited[i] = 0;
    }

    while(!q.empty()){
        pair<ll, int> p = q.top();
        q.pop();
        int k = p.second;
        visited[k] = 1;
        rep(i, g[k].size()){
            if(visited[g[k][i][0]] == 1) continue;

            if(yen[g[k][i][0]] > yen[k] + g[k][i][1]){
                yen[g[k][i][0]] = yen[k] + g[k][i][1];
                q.push(make_pair(yen[g[k][i][0]], g[k][i][0]));
            }
        }
    }
}

void dijkstra2(){
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    q.push(make_pair(0, t));
    vector<int> visited(n + 1);
    for(int i = 1; i <= n; i++){
        visited[i] = 0;
    }

    while(!q.empty()){
        pair<ll, int> p = q.top();
        q.pop();
        int k = p.second;
        visited[k] = 1;
        rep(i, g[k].size()){
            if(visited[g[k][i][0]] == 1) continue;

            if(snook[g[k][i][0]] > snook[k] + g[k][i][2]){
                snook[g[k][i][0]] = snook[k] + g[k][i][2];
                q.push(make_pair(snook[g[k][i][0]], g[k][i][0]));
            }
        }
    }
}

int main(){
    cin >> n >> m >> s >> t;
    g.resize(n + 1);
    yen.resize(n + 1);
    snook.resize(n + 1);
    for(int i = 1; i <= n; i++){
        yen[i] = INF;
        snook[i] = INF;
    }
    yen[s] = 0;
    snook[t] = 0;
    rep(i, m){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        vector<int> vec1{v, a, b};
        g[u].push_back(vec1);
        vector<int> vec2{u, a, b};
        g[v].push_back(vec2);
    }
    
    dijkstra();
    dijkstra2();

    vector<ll> ans(n);
    ans[n - 1] = yen[n] + snook[n];
    for(int i = n - 2; i >= 0; i--){
        if(yen[i + 1] + snook[i + 1] < ans[i + 1]){
            ans[i] = yen[i + 1] + snook[i + 1];
        }else{
            ans[i] = ans[i + 1];
        }
    }
    ll tmp = 1e15;
    rep(i, n){
        cout << tmp - ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 19448
n=int(input())
S=list(input())
C=[0]*3
for i in range(n):
  if S[i]=="R":
    C[0]+=1
  elif S[i]=="G":
    C[1]+=1
  else:
    C[2]+=1
b=C[0]*C[1]*C[2]
a=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=j*2-i
    if k>=n:
      continue
    if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
      a=a+1
print(b-a)

Measured memory_bytes: 9188
#include<stdio.h>
#define N 250

typedef struct{
  int key;
  int par;
  int left;
  int right;
}node;

void ndset(int,int);

node T[N];

int main(){
  int n,i;

  scanf("%d",&n);

  for(i=0; i<n; i++) T[i].par = -1;

  for(i=0; i<n; i++) scanf("%d",&T[i].key);
  for(i=0; i<n; i++){
    if(i != 0) T[i].par = (i+1)/2-1;
    if(2*(i+1)-1 < n) T[i].left = 2*(i+1)-1;
    else T[i].left = -1;
    if(2*(i+1) < n) T[i].right = 2*(i+1);
    else T[i].right = -1;
  }

  for(i=0; i<n; i++){
    printf("node %d: key = %d, ", i+1, T[i].key);
    if(T[i].par != -1) printf("parent key = %d, ",T[T[i].par].key);
    if(T[i].left != -1) printf("left key = %d, ",T[T[i].left].key);
    if(T[i].right != -1) printf("right key = %d, ",T[T[i].right].key);
    printf("\n");
  }

  return 0;
}

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

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;

		// エラトステネスの篩
		int MAX = 1000000;
		int num = (MAX - 3) / 2;
		int[] prime = new int[MAX + 1];
		int count = 1;
		int[] total = new int[10000 + 1];
		total[1] = 2;

		for (int i = 0; i < num; i++) {
			if (prime[i] == 0) {
				int primeNum = i + i + 3;
				count++;
				total[count] = total[count - 1] + primeNum;
				for (int j = i + primeNum; j <= MAX; j += primeNum)
					prime[j] = 1;
				if(count == 10000) break;
			}
		}
		
		try {
			while ((line = br.readLine()) != null) {
				line = line.trim();
				if (line.equals("0"))
					break;
				int N = Integer.parseInt(line);
				
				System.out.println(total[N]);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 24660
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;

int main(){
    int n  ;
    cin >> n ;
    vector<string> s(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> s.at(i) ;
    }
    sort(s.begin() ,s.end() ) ;
    vector<string> ans(0) ;
    int max = 0 ;
    int now = 1 ;
    for (size_t i = 0; i < n-1; i++)
    {
        if (s.at(i) == s.at(i+1))
        {
            now ++ ;
        }else
        {
            if (now < max)
            {
                //なんもない
            }else if (now == max)
            {
                ans.push_back(s.at(i)) ;
            }else
            {
                ans.clear() ;
                ans.push_back(s.at(i)) ;
                max = now ;
            }
            now = 1 ;
            
            
        }
        
        
    }
    if (now == max)
    {
        ans.push_back(s.at(n-1)) ;
    }else if (now > max)
    {
        ans.clear() ;
        ans.push_back(s.at(n-1)) ;
    }
    
    
    for (size_t i = 0; i < ans.size(); i++)
    {
        cout << ans.at(i) << endl ;
    }
    
    
}    

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

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

  for (int i = 0; i * 10000 <= Y && i <= N; i++) {
    for (int j = 0; i * 10000 + j * 5000 <= Y && i + j <= N; j++) {
      int k = N - i - j;
      if (1000 * k == Y - i * 10000 - j * 5000) {
	cout << i << ' ' << j << ' ' << k << endl;
	return 0;
      }
    }
  }

  cout << -1 << ' ' << -1 << ' ' << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<int> cnt(26, 0);
  while (n--) {
    string p; cin >> p;
    ++cnt[p.front() - 'A'];
  }
  int ans = 0;
  while (true) {
    vector<pair<int, int> > v;
    REP(i, 26) {
      if (cnt[i] > 0) v.emplace_back(cnt[i], i);
    }
    if (v.size() < k) break;
    ++ans;
    sort(ALL(v));
    reverse(ALL(v));
    REP(i, k) --cnt[v[i].second];
  }
  cout << ans << '\n';
  return 0;
}


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

const int64_t M = 1'000'000'007;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);

    int n;
    cin >> n;
    int a[21];
    for(int i=0;i<n;i++){
        a[i] = 0;
        for(int j=0;j<n;j++){
            int x;
            cin >> x;
            a[i] |= x<<j;
        }
    }

    static uint32_t dp[1<<21][22];
    for(int j=0;j<=n;j++){
        for(uint ptn=0;ptn<(1<<n);ptn++){
            if(j == 0){
                dp[ptn][j] = 1;
                continue;
            }
            dp[ptn][j] = 0;
            uint mask = ptn & a[j-1];
            mask |= 1<<n;
            for(uint k=(mask & -mask);k<(1<<n);k=(mask & -mask)){
                dp[ptn][j] += dp[ptn & ~k][j-1];
                dp[ptn][j] %= M;
                mask &= ~k;
            }
        }
    }

    cout << dp[(1<<n)-1][n] << endl;
    
    return 0;
}


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

int main(){
  int k;
  cin >> k;
  int a, b;
  cin >> a >> b;
  
  int cnt=0;
  int x =a/k;
  int ans=k*x, i=0;
  while(b >= ans){
    i++;
    if(ans >= a and ans <= b){
      cnt++;
      break;
    }
    ans += k*i;
  }
  if(cnt > 0) cout << "OK" << endl;
  else cout << "NG" << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>

using namespace std;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    uint32_t N;
	int64_t *A, *B;
    cin >> N;
    A = new int64_t[N];
    B = new int64_t[N];
    B[0] = 0;

    for(uint32_t i = 0;i < N;++i)cin >> A[i];
    for(uint32_t i = 0;i < N;++i){
        if(i & 0x01)
            B[0] -= A[i];
        else
            B[0] += A[i];
    }
    for(uint32_t i = 1;i < N;++i){
        B[i] = 2 * A[i - 1] - B[i - 1];
    }
    for(uint32_t i = 0;i < N;i++){
        cout << B[i] <<" ";
    }

	return 0;
}



Measured memory_bytes: 2944
#include<iostream>
#include<algorithm>
using namespace std;
int a[10001],ans=0,n;
int main(){
    cin>>n;
    n=n*2;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i+=2){
        ans+=a[i];
    } 
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
    ll N, K;
    cin >> N >> K;
    cout << min(N % K, abs(N % K - K)) << endl;
}


Measured memory_bytes: 3588