akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
  char str[5];
  scanf("%s", str);
  if(str[0]==str[1] && str[1]==str[2] || str[1]==str[2] && str[2]==str[3]){
    printf("Yes\n");
  }
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n ;cin >> n ;
  #define ar array 
  vector<ar<int,3>>a(n) ;
  for(int i=0,x,y,z;i<n;i++)
    cin >> x >> y >>z ,a[i]={x,y,z} ;
  vector<vector<int>>dp(n,vector<int>(3)) ;
  //dp[i][j] -> max pts with jth activity on ith day 
  // dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j] ;
  for(int i=0;i<3;i++)
    dp[0][i]=a[0][i] ;
  for(int i=1;i<n;i++)
    for(int j=0;j<3;j++)
      dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j] ;
  cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) ;
  
}


Measured memory_bytes: 9776
public class Main {

  private static void solve() {
    long s = nl();

    // x1y2 - x2y1=s

    long sq = sqrtL(s); // x1, y2

    if (sq * sq == s) {
      System.out.println(sq + " " + 0 + " " + 0 + " " + sq + " " + 0 + " " + 0);

    } else {
      long t = sq * sq - s;

      System.out.println(sq + " " + 1 + " " + t + " " + sq + " " + 0 + " " + 0);
    }
  }


  public static long sqrtL(long N) {
    long ng = 1;
    long ok = (long) Math.sqrt(N) + 1;

    while (ok - ng > 1) {
      long mid = (ng + ok) / 2;
      if (mid * mid >= N) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    return ok;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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


int main(){
    int a[101][101], b[101], n,m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> a[i][j];
    
    for(int i=0;i<m;i++)
        cin >> b[i];
    
    for(int i=0;i<n;i++){
        int ans = 0;
        for(int j = 0;j < m;j++)
            ans += a[i][j] * b[j];
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
while True:
    a,b = map(int,input().split())
    count = 0
    if a == 0 and b == 0:
        break
    elif a < b:
        a,b = b,a
        
    while True:
        if b == 0:
            break
        a = a % b
        a,b = b,a
        count += 1
    print(a,count)


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

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define vecc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    int A[M];
    rep(i,M) cin >> A[i];
    int l=0, r=0;
    rep(i, M) if(A[i]<X) l++;
    rep(i, M) if(A[i]>X) r++;
    cout << min(l, r) << endl;
    return 0;
}

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

int main(){
  map< char , int > count;
  string str;
  while( cin>>str ){

    for(int i=0;i<(int)str.size();i++){
      if( isupper(str[i]) ){
	str[i]=tolower(str[i]);
      }
    }

    for(int i=0;i<(int)str.size();i++){
      count[ str[i] ]++;
    }
  }

  for(char ch='a';ch<='z';ch++){
    cout<<ch<<" : "<<count[ch]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3188
#line 1 "../lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "tmp.cpp"

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

  int n, k;
  cin >> n >> k;
  vi p(n);
  REP(i, n) { cin >> p[i]; }

  int ma = 0;
  REP(i, k) { ma += p[i] + 1; }
  int tmp = ma;
  REP(i, n - k) {
    tmp -= p[i];
    tmp += p[k + i];
    ma = max(ma, tmp);
  }

  coutd(10) << (double)ma / 2 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ui unsigned int
#define ll __int128
#define db double
#define ld long double
#define ull unsigned long long
#define ft first
#define sd second
#define pb(a) push_back(a)
#define PII std::pair<int,int>
#define PLL std::pair<ll,ll>
#define mp(a,b) std::make_pair(a,b)
#define ITR(a,b) for(auto a:b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=500+10,MAXM=1000000+10;
int n,vis[MAXM],prime[MAXM],cnt,p;
ll G[MAXN][MAXN];
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline bool chkmin(T &x,T y){return y<x?(x=y,true):false;}
template<typename T> inline bool chkmax(T &x,T y){return y>x?(x=y,true):false;}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void init()
{
	memset(vis,1,sizeof(vis));
	vis[0]=vis[1]=0;
	REP(i,2,MAXM-1)
	{
		if(vis[i])prime[++cnt]=i;
		for(register int j=1;j<=cnt&&i*prime[j]<MAXM;++j)
		{
			vis[i*prime[j]]=0;
			if(i%prime[j]==0)break;
		}
	}
}
int main()
{
	read(n);init();int x,y;
	REP(i,0,n+1)REP(j,0,n+1)G[i][j]=1;
	REP(i,0,n+1)if(i&1)
	{
		x=0,y=i,++p;
		while(x<=n+1&&y>=0)G[x][y]*=prime[p],x++,y--;
	}
	REP(i,1,n+1)if(i%2==n%2)
	{
		x=n+1,y=i,++p;
		while(x>=0&&y<=n+1)G[x][y]*=prime[p],x--,y++;
	}
	REP(i,0,n+1)if(i%2==n%2)
	{
		x=n+1,y=i,++p;
		while(x>=0&&y>=0)G[x][y]*=prime[p],x--,y--;
	}
	REP(i,1,n+1)if(i&1)
	{
		x=0,y=i,++p;
		while(x<=n+1&&y<=n+1)G[x][y]*=prime[p],x++,y++;
	}
	REP(i,1,n)REP(j,1,n)if((i+j)%2==0)
		G[i][j]=G[i-1][j]*G[i+1][j]+1;
	REP(i,1,n)
	{
		REP(j,1,n)write(G[i][j],' ');puts("");
	}
	return 0;
}


Measured memory_bytes: 14976
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<set>
#include<functional>
#include <cmath>
using namespace std;

#define INF 1<<21
#define MOD 1000000007
#define MAX 1000000

int main() {
  char p[MAX];
  memset(p, 1, sizeof(p));
  p[0] = 0;
  p[1] = 0;
  for (int i = 2; i <= sqrt(MAX)+1; i++) {
	if (p[i] == 1) {
	  for (int j = 2*i; j <= MAX; j += i) {
		p[j] = 0;
	  }
	}
  }

  int a, d, n;
  while (1) {
	cin >> a >> d >> n;
	if (a == 0 && d == 0 && n == 0)return 0;
	while (1) {
	  if (p[a] == 1) n--;
	  if (n == 0) {
		cout << a << endl;
		break;
	  }
	  a += d;
	}
  }
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int count=0;
    for(int i=0; ;i++)
    {
        a=a-b;
        count++;
        if(a<=0)
        {
            break;
        }
    }
    cout << count*c << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

 
#ifndef ONLINE_JUDGE
#define trace(...) _f(#__VA_ARGS_, _VA_ARGS_)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
const int N = 4e5 + 5;
const int MAX = 250000 + 5;
const int M = 3e5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e18;
const int LG = 21;
vector<int> v;
int cache[N];
int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int f(int no)
{
	if(no == 0) return 0;
	int ret = 0;
	for(int i = 0; i < v.size(); i++)
	{
		ret += v[i] * pow(2, v.size() - i - 1, no);
		ret %= no;
	}
	return ret;
}
int dp(int no)
{
	if(no == 0)
	{
		return 0;
	}
	if(cache[no] != -1)
	{
		return cache[no];
	}
	int tot = __builtin_popcount(no);
	return cache[no] = 1 + dp(no % tot);
}
void solve()
{
	int n;
	cin >> n;
	int cnt = 0;
	memset(cache, -1, sizeof(cache));
	int no = 0;
	for(int i = 0; i < n; i++)
	{
		char ch;
		cin >> ch;
		v.push_back(ch - '0');
		cnt += v.back();
		if(ch == '0') continue;
	}
	int plus = cnt + 1;
	int minus = max(cnt - 1, 0LL);
	int plusans = f(plus);
	int minusans = f(minus);
	for(int i = 0; i < n; i++)
	{
		if(v[i] == 0)
		{
			int curr = plusans + pow(2, n - i - 1, plus) + plus;
			curr %= plus;
			cout << 1 + dp(curr) << endl;
		}
		else
		{
			if(minus == 0LL)
			{
				cout << 0 << endl;
				continue;
			}
			int curr = minusans - pow(2, n - i - 1, minus) + minus;
			curr %= minus;
			cout << 1 + dp(curr) << endl;
		}
	}
}
int32_t main() 
{	
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 8396
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <iomanip>
using namespace std;

typedef long long ll;

int main()
{
    ll N,K;
    cin >> N >> K;
    vector<ll> p(N);
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]++;
    }
    ll ans=0;
    for(int i=0; i<K; i++){
        ans+=p[i];
    }
    ll now=ans;
    for(int i=0; i<N-K; i++){
        now-=p[i];
        now+=p[i+K];
        if(ans<now) ans=now;
    }
    cout << setprecision(10) << ans/2.0 << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int>number;
    UnionFind(int n ) {
        init(n);
    }

    void init(int n ) {
        par.resize(n);
        number.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            number[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;
        par[y] = x;
        return true;
    }

    void set(int x,int y){
        number[x]=y;
        return;
    }

    int num(int x){
        return number[x];
    }
};


int main(){
int N,M;
cin>>N>>M;
UnionFind tree(N);

rep(i,N){
    int p;
    cin>>p;
    p--;
    tree.set(i,p);
}

rep(i,M){
    int x,y;
    cin>>x>>y;
    x--,y--;
    tree.merge(x,y);
}
int ans=0;
rep(i,N){
    if(tree.issame(tree.num(i),i))ans++;
}
cout<<ans<<endl;
 return 0;
}
/*
5 2
5 3 1 4 2
1 3
5 4

2

3 2
3 2 1
1 2
2 3

3


10 8
5 3 6 8 7 10 9 1 2 4
3 1
4 1
5 9
2 5
6 5
3 5
8 9
7 9

8

5 1
1 2 3 4 5
1 5

5

*/

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    
    char m[N];
    for(int i=0; i<N; i++){
        m[i]=s[i];
    }
    
    int w[N]={};
    int e[N]={};
    w[0]=0;
    e[N-1]=0;
    for(int i=1; i<N; i++){
        w[i]=w[i-1];
        if(m[i-1]=='W'){
            w[i]++;
        }
    }
    for(int i=N-2; i>=0; i--){
        e[i]=e[i+1];
        if(m[i+1]=='E'){
            e[i]++;
        }
    }
    
    int ans=N;
    for(int i=0; i<N; i++){
        ans=min(ans, e[i]+w[i]);
    }
    
    cout<<ans<<endl;
    
 
    return 0;
}




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

#define ll long long

using namespace std;

int main(void){
    string S;
    cin >> S;
    int r = 0, l = 0;
    int pos = 0;
    vector<int> ans(S.length());
    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'R') r++;
        else l++;
        if(i == S.length() - 1 || S[i] == 'L' && S[i + 1] == 'R'){
            ans[pos] = (r + 1) / 2 + l / 2;
            ans[pos + 1] = r / 2 + (l + 1) / 2;
            r = l = 0;
        }
        if(S[i] == 'R'  && S[i + 1] == 'L') pos = i;
    }
    for(int i = 0; i < S.length() - 1; i++) cout << ans[i] << " ";
    cout << ans[S.length() - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
from collections import Counter
s = input()
MOD = 2019

s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)


for i in ref_cnt.values():
    ans += (i - 1) * (i - 2) // 2

if 0 in ref:
    ans += ref_cnt[0]

print(ans)

Measured memory_bytes: 16748
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        n: i32,
        c: i32,
        stc: [[i32;3];n]
    }
    let t_max = 100000;

    stc.sort_by(|a, b| a[0].cmp(&b[0]));
    let mut c_map: HashMap<i32, Vec<Vec<i32>>> = HashMap::new();
    for i in stc {
        if c_map.contains_key(&i[2]) {
            c_map.get_mut(&i[2]).unwrap().push(vec![i[0], i[1]]);
        } else {
            c_map.insert(i[2], vec![vec![i[0], i[1]]]);
        }
    }
    let mut merged_c_map: HashMap<i32, Vec<Vec<i32>>> = HashMap::new();
    for channel in c_map.keys() {
        let mut src = VecDeque::from(c_map[channel].clone());
        let mut dst: Vec<Vec<i32>> = Vec::new();
        while src.len() > 0 {
            let mut t = src.pop_front().unwrap();
            while src.len() > 0 {
                let nx = src.pop_front().unwrap();
                if nx[0] == t[1] {
                    t[1] = nx[1];
                } else {
                    src.push_front(nx);
                    break;
                }
            }
            dst.push(t);
        }
        merged_c_map.insert(*channel, dst);
    }

    let mut diffs = vec![0; (t_max + 2) as usize];
    for channel in merged_c_map.keys() {
        for i in &merged_c_map[channel] {
            diffs[(i[0]) as usize] += 1;
            diffs[(i[1] + 1) as usize] -= 1;
        }
    }

    let mut res = vec![0; (t_max + 2) as usize];
    res[0] = diffs[0];
    for i in 1..(t_max + 1) as usize {
        let d = diffs[i];
        res[i] = res[i - 1] + d;
        // println!("i={}, d={}, res`{}", i, d, res[i]);
    }

    println!("{}", *(res.iter().max().unwrap()));
}

#[macro_export(local_inner_maccros)]
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_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[macro_export(lcal_inner_macros)]
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")
    };
}


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

int joi, ioi;

int Q(int q, char m){
    if(q == 0){
        if(m == 'J') return 1;
        if(m == 'I') return 2;
    }
    if(q == 1){
        if(m == 'O') return 3;
        if(m == 'I') return 2;
        if(m == 'J') return 1;
    }
    if(q == 2){
        if(m == 'O') return 4;
        if(m == 'I') return 2;
        if(m == 'J') return 1;
    }
    if(q == 3){
        if(m == 'J') return 1;
        if(m == 'I') {
            joi++;
            return 2;
        }
    }
    if(q == 4){
        if(m == 'J') return 1;
        if(m == 'I'){
            ioi++;
            return 2;
        }
    }
    return 0;
}

int main(){
    string in;
    int q;
    while(cin >> in){
        joi = ioi = q = 0;
        for(int i = 0;i<in.length();i++){
            q = Q(q, in[i]);
        }
        cout << joi << endl << ioi << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007;

int iro[8];
int main(){
    int n;
    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        if(x<3200)iro[x/400]++;
        else iro[8]++;
    }
    int ans=0;
    rep(i,0,8)if(iro[i]>0)ans++;
    if(ans==0)cout<<'1'<<' '<<iro[8]<<endl;
    else cout<<ans<<' '<<ans+iro[8]<<endl;
    return 0;
}

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

int main(void) {
  int N, i;
  cin >> N >> i;

  cout << N - i + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7,p=924844033; bool fl[N];
int n,k,lim,r[N],len[N],siz[N],ans[N],sum[N]; vector<int>v[N]; long long fac[N],ifac[N];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline long long pows(long long u,int v){
	long long ans=1; while(v>0) {if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;} return ans;
}
inline void find(int u){
	fl[u]=1,siz[u]=1;
	for(int i=0;i<len[u];i++){
		int x=v[u][i]; if(!fl[x]) find(x),ans[siz[x]]--,siz[u]+=siz[x];
	}
	ans[n-siz[u]]--,ans[n]++;
}
inline void NTT(int *s,int x){
    for(int i=0;i<lim;i++) if(r[i]<i) swap(s[i],s[r[i]]);
    for(int d=1;d<lim;d=d<<1){
        int w=pows(x,(p-1)/(d<<1));
        for(int i=0,r=d<<1;i<lim;i+=r){
            long long wn=1;
            for(int j=0;j<d;j++,wn=(wn*w)%p){
                int a=s[i+j],b=(s[i+j+d]*wn)%p;
                s[i+j]=(a+b)%p,s[i+j+d]=(a-b+p)%p;
            }
        }
    }
}
int main(){
	n=read(); int u,t; fac[0]=ifac[0]=1;
	for(int i=1;i<n;i++) u=read(),t=read(),v[u].push_back(t),v[t].push_back(u),len[u]++,len[t]++; find(1);
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%p,ifac[i]=pows(fac[i],p-2);
	for(int i=0;i<=n;i++) ans[i]=(ans[i]+p)*fac[i]%p;
	for(int i=0;i<=n;i++) sum[n-i]=ifac[i]; k=0,lim=1;
	while(lim<=(n<<1)) lim=lim<<1,k++;
	for(int i=0;i<lim;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(k-1));
	NTT(ans,5),NTT(sum,5);
	for(int i=0;i<lim;i++) ans[i]=1ll*ans[i]*sum[i]%p; NTT(ans,pows(5,p-2));
	for(int i=1;i<=n;i++) printf("%d\n",ans[n+i]*ifac[i]%p*pows(lim,p-2)%p);
	return 0;
}

Measured memory_bytes: 64384
n=int(input())
a=list(map(int,input().split()))
b=max(a)
ansmax=-1
ans=-1
for i in range(n):
  if min(b-a[i],a[i]) > ansmax and b!=a[i]:
    ansmax=min(b-a[i],a[i]) 
    ans=a[i]
print(str(b)+' '+str(ans))

Measured memory_bytes: 14428
n = int(input())
numl = [[0]*9 for _ in range(9)]
for i in range(n):
  s = str(i+1)
  if s[-1]=="0":
    continue
  numl[int(s[0])-1][int(s[-1])-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += numl[i][j] * numl[j][i]
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(x); cout<<#x<<"="<<x<<endl;
#define debug2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long
using namespace std;


int32_t main()
{
    slowanddetermined
    int n,k;
    cin>>n>>k;

    if(k>n)cout<<min(n,abs(n-k));
    else{

        int ans=min(n%k,k-n%k);
        cout<<ans;
    }



    return 0;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
    init();

	int N; cin >> N;
	vector<ll>A(N + 1);
	rep(i, 0, N + 1)cin >> A[i];
	vector<ll>B(N);
	rep(i, 0, N)cin >> B[i];
	ll ans = 0;
	rep(i, 0, N) {
		ans += min(A[i], B[i]);
		B[i] -= A[i];
		if (B[i] > 0) {
			ans += min(B[i], A[i + 1]);
			A[i + 1] = max(0LL, A[i + 1] - B[i]);
		}
	}
	cout << ans << "\n";

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i, n) cin >> t.at(i) >> x.at(i) >> y.at(i);

    int xi = 0, yi = 0, ti = 0;
    rep(i, n) {
        int dx = abs(x.at(i) - xi);
        int dy = abs(y.at(i) - yi);
        int dt = t.at(i) - ti;
        if(dt < dx + dy || (dt - dx - dy)%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
        xi = x.at(i);
        yi = y.at(i);
        ti = t.at(i);
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
N = int(input())
Alist = list(map(int, input().split()))
boss = {}
for i in Alist:
    if i not in boss:
        boss[i] = 1
    else:
        boss[i] += 1
for j in range(1,N+1):
    if j in boss:
        print(boss[j])
    else:
        print(0)

Measured memory_bytes: 33456
#include <stdio.h>

int main()
{
    int a,b[55],sum=0,p=0;
    scanf("%d",&a);
    for(int i=0;i<a;i++)
    {
        scanf("%d",&b[i]);
    }
    for(int j=0;j<a;j++)
    {
        p+=b[j];
    }
    for(int m=0;m<a-1;m++)
    {
        p-=b[m];
        sum+=b[m]*p;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 1732
using System;

namespace myApp
{
    class Program
    {
        static readonly int PROCESS_MAX = 100005; 
        struct Process {
            public string name;
            public int time;
        }
        static Process[] processes = new Process[PROCESS_MAX];
        static int head, tail;

        static void Enqueue(Process process) {
            processes[tail] = process;
            if ((tail + 1) == PROCESS_MAX) {
                tail = 0;
            } else {
                tail++;
            }
        }
        static Process Dequeue() {
            var result = processes[head];
            if (head + 1 == PROCESS_MAX) {
                head = 0;
            } else {
                head++;
            }
            return result;
        }
        static bool IsEmpty() {
            return head == tail;
        }

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var n = int.Parse(line[0]);
            var quantum = int.Parse(line[1]);
            for (int i = 0; i < n; i++) {
                var name_time = Console.ReadLine().Split(' ');
                var p = new Process();
                p.name = name_time[0];
                p.time = int.Parse(name_time[1]);
                Enqueue(p);
            }

            int elapsedTime = 0;
            // processesが空になるまで処理をする
            while (!IsEmpty()) {
                // quantumだけ処理をして、終わらなければキューに入れる
                var p = Dequeue();
                if (p.time > quantum) {
                    elapsedTime += quantum;
                    p.time -= quantum;
                    Enqueue(p);
                } else {
                    // プロセスが完了したら、名前と終了時刻を出力する
                    elapsedTime += p.time;
                    Console.WriteLine(p.name + " " + elapsedTime);
                }
            }
        }
    }
}



Measured memory_bytes: 23316
#!/usr/bin/python3

import array
from fractions import Fraction
import math
import os
import sys


def main():
    Q = read_int()
    for _ in range(Q):
        x0, y0, x1, y1, x2, y2, x3, y3 = read_ints()
        print(solve(Vec(x0, y0), Vec(x1, y1), Vec(x2, y2), Vec(x3, y3)))


PARALLEL = 2
ORTHOGONAL = 1
OTHER = 0


def solve(a, b, c, d):
    u = b - a
    v = d - c
    if u.cross(v) == 0:
        return PARALLEL
    if u.dot(v) == 0:
        return ORTHOGONAL
    return OTHER


###############################################################################
# AUXILIARY FUNCTIONS

class Vec(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        super().__init__()

    def __add__(self, other):
        return Vec(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vec(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __rmul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __truediv__(self, scalar):
        return Vec(self.x / scalar, self.y / scalar)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __imul__(self, scalar):
        self.x *= scalar
        self.y *= scalar
        return self

    def __idiv__(self, scalar):
        self.x /= scalar
        self.y /= scalar
        return self

    def __neg__(self):
        return Vec(-self.x, -self.y)

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def abs2(self):
        return self.x * self.x + self.y * self.y

    def __abs__(self):
        return math.sqrt(float(self.abs2()))

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



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

ll a[100];
               
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  string s;
  cin>>s;
  int n=(int)s.length();
  for(int i=0;i<n;i++){
    a[s[i]-'a']++;
  }
  ll ans=(ll)n*(n-1)/2+1;
  for(int i=0;i<100;i++){
    ans-=a[i]*(a[i]-1)/2;
  }
  cout<<ans<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <map>
 
using namespace std;
 
int main(){
    string s = "abcd";
    string AI;
    map<string,bool> judge;
 
    judge[s] = true;
 
    while(true){
	cout << "?" << s << endl;
	cin >> AI;
 
	if(s[s.size()-1] != AI[0] || judge[AI]){
	    cout << "!OUT" << endl;
	    break;
	}
	judge[AI] = true;
 
	s[0] = AI[AI.size()-1];
	for(int i = 1 ; i < 3 ; i++){
	    if(s[i] < 122){
		s[i]++;
		break;
	    }
	}
    }
    return 0;
}

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

using namespace std;

using ll = long long;


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


template<class T>
T sqr(T x)
{
	return x * x;
}


ll powmod(ll x, int y)
{
	return y ? (y & 1 ? x * powmod(x, y - 1) : sqr(powmod(x, y / 2))) % inf : 1;
}


ll mult(ll a, ll b)
{
	return (a * b) % inf;
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n, a, b, c;

	cin >> n >> a >> c >> b;

	a = (a * powmod(100, inf - 2)) % inf;
	b = (b * powmod(100, inf - 2)) % inf;
	c = (c * powmod(100, inf - 2)) % inf;

	ll ans = 0, bc = 1;

	for (int i = 0; i < n; i++)
	{
		ll add = mult(mult(powmod(a, n), powmod(c, i)), mult(bc, n + i)) +
		         mult(mult(powmod(c, n), powmod(a, i)), mult(bc, n + i));
		add %= inf;

		ans += add * powmod(powmod(inf + 1 - b, (inf - 2)), i + n + 1);
		ans %= inf;

		bc *= n + i;
		bc %= inf;
		bc *= powmod(i + 1, inf - 2);
		bc %= inf;
	}

	cout << ans << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4) << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	cout << setprecision(20);

	solve();
#endif

	return 0;
}


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



int main() {

  int N; cin >> N;
  vector<int> P(N);
  vector<int> Q(N);
  rep(i,N) cin >> P[i];
  rep(i,N) cin >> Q[i];
  vector<int> v(N);
  //1刻みで格納できる関数、便利
  iota(v.begin(), v.end(), 1);
  int cnt = 0;
  int a,b;
  do{
    cnt++;
    if(v == P) a = cnt;
    if(v == Q) b = cnt;
  }while(next_permutation(v.begin(),v.end()));
  
  int ans = abs(a - b); 
  cout << ans << endl;


	return 0;
}

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 1e9 + 7;

ll pow(ll x, ll m)
{

    ll re = 1, y = 1;

    for (int i = 0; i < 60; ++i)
    {
        if (m & y)
            re = re * x % mod;
        x = x * x % mod;
        y *= 2;
    }

    return re;
}

ll inv(ll x)
{

    return pow(x, mod - 2);
}

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num - rhs.num + mod) % mod;
    }
    mint operator/(const mint &rhs) const
    {
        return num * inv(rhs.num) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return *this = *this + rhs;
    }
    mint operator*=(const mint &rhs)
    {
        return *this = *this * rhs;
    }
    mint operator-=(const mint &rhs)
    {
        return *this = *this - rhs;
    }
    mint operator/=(const mint &rhs)
    {
        return *this = *this / rhs;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

int main()
{
    int n;

    std::cin >> n;

    std::vector<int> a(n);

    std::vector<mint> b(n);

    rep(i, n)
            std::cin >>
        a[i];

    for (int i = n - 2; i >= 0; --i)
        b[i] = b[i + 1] + (mint)a[i + 1];

    mint ans = 0;

    rep(i, n - 1)
    {
        ans += (mint)a[i] * b[i];
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 5632
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

std::vector<int> manacher(const std::string &s) {
    int n = s.size();
    std::vector<int> rad(n);
    int c = 0;
    for (int r = 0; r < n; ++r) {
        int l = c - (r - c);
        if (r + rad[l] < c + rad[c]) {
            rad[r] = rad[l];
        } else {
            int rr = c + rad[c];
            int rl = r - (rr - r);
            while (rl >= 0 && rr < n && s[rl] == s[rr]) ++rr, --rl;
            rad[r] = rr - r;
            c = r;
        }
    }
    return rad;
}

std::string insert_dollar(const std::string &s) {
    int n = s.size();
    std::string res(n * 2 + 1, '$');
    for (int i = 0; i < n; ++i) {
        res[i * 2 + 1] = s[i];
    }
    return res;
}

bool is_palindrome(int l, int r, const std::vector<int> &rad) {
    l = l * 2 + 1;
    r = (r - 1) * 2 + 1;
    int c = (l + r) / 2;
    return r < c + rad[c];
}
int main() {
  cin >> N >> M;
  cout << N*(N-1)/2 + M*(M-1)/2;
} 



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
int n;
long long C;
long long dist[100005];
long long a[100005],b[100005];
int mx[100005];
int v[100005];
long long d[100005];
long long mxa[100005];
long long mxb[100005];
long long ans;
int main() {
    scanf("%d",&n);
    scanf("%lld",&C);
    for (int i=1;i<=n;i++){
        scanf("%lld",&d[i]);
        dist[i]=d[i];
        scanf("%d",&v[i]);
    }
    mxa[0]=-1e18;
    for (int i=1;i<=n;i++){
        a[i]=a[i-1]+v[i]-d[i]+d[i-1];
        mxa[i]=max(mxa[i-1],a[i]);
    }
    mxb[n+1]=-1e18;
    d[n+1]=C;
    for (int i=n;i>=1;i--){
        b[i]=b[i+1]+v[i]+d[i]-d[i+1];
        mxb[i]=max(mxb[i+1],b[i]);
    }
    reverse(b+1,b+n+1);
    reverse(mxb+1,mxb+n+1);
    dist[n+1]=C;
    for (int i=0;i<=n;i++){
        ans=max(ans,a[i]-dist[i]+mxb[n-i]);
        ans=max(ans,b[i]-C+dist[n-i+1]+mxa[n-i]);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

int main() {
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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




int cntB[4005];
int cntG[4005];
int cntR[4005];

int main()
{
    FAST();

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

    int i,j,n;
    LL ans=0;
    char s[4005];
    cin >> n >> s+1;
    for(i=n;i>0;i--)
    {
        cntB[i]=cntB[i+1]+(s[i] == 'B');
        cntG[i]=cntG[i+1]+(s[i] == 'G');
        cntR[i]=cntR[i+1]+(s[i] == 'R');
    }
    for(i=1;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(s[i] != s[j])
            {
                if((s[i] == 'B'  &&  s[j] == 'G')  ||  (s[i] == 'G'  &&  s[j] == 'B'))ans+=cntR[j];
                else if((s[i] == 'B'  &&  s[j] == 'R')  ||  (s[i] == 'R'  &&  s[j] == 'B'))ans+=cntG[j];
                else ans+=cntB[j];
                if(j+(j-i) <= n  &&  s[j+(j-i)] != s[i]  &&  s[j+(j-i)] != s[j])--ans;
            }
        }
    }
    cout << ans;
    return 0;
}


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

int main() {
  int K; cin >> K;
  if (K % 2 == 0 || K % 5 == 0) cout << -1 << endl;
  else {
    int i = 1, m = 7 % K;
    while (m != 0) {
      m = (m * 10 + 7) % K;
      i++;
    }
    cout << i << endl;
  }
}

Measured memory_bytes: 3576
from operator import itemgetter

N, K = map(int, input().split())
TD = [list(map(int, input().split())) for _ in range(N)]

TD.sort(key=itemgetter(1), reverse=True)
selected = TD[:K]
dlc = sum(map(itemgetter(1), selected))
variety = set(map(itemgetter(0), selected))

used = set()
overlap = [] # ダブっているネタの美味しさのリスト
for t, d in TD[:K]:
    if t not in used:
        used.add(t)
    else:
        overlap.append(d)
answer = dlc + len(variety)**2

for t, d in TD[K:]:
    if not overlap:
        break
    if t in used:
        continue
    ov = overlap.pop()
    dlc = dlc - ov + d
    used.add(t)
    answer = max(answer, dlc + len(used)**2)

print(answer)


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

long long GCD(long long x, long long y) {
	if (y == 0) return x;
	return GCD(y, x%y);
}

int main() {
	long long A, B;
	cin >> A >> B;
	cout << (A * B) / GCD(A, B)<< endl;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 数値
		Long n = sc.nextLong();
		Long ure = 0l;

		ure += 1000 * (n / 500);
		n = n % 500;

		ure += 5 * (n / 5);

		out(ure);

	}

	/*
	 * 以下メソッド集
	 */
	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	int N;
	unordered_map<int, int> mp;

	cin >> N;
	for(int i=1; i<=N; i++){
		long long a;
		cin >> a;
		if(mp.count(a)==0){
			mp[a] = 1;
		}
		else{
			mp.erase(a);
		}
	}
	cout << mp.size() << endl;
	return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const ll INF = 1e12;

ll mult(ll x, ll y){
  if (INF / x < y) return INF;
  return min(INF, x * y);
}

void solve(){
  ll n, a;
  cin >> n >> a;
  ll ans = n;
  for (ll k = 1LL; k < 54LL; k++){
    //cerr << k << '\n';
    ll l = 0LL, r = n + 1LL;
    while (r - l > 1){
      ll s = (l + r) >> 1LL;
      //cerr << s << '\n';
      if (k > 1LL && (s+1LL) / k < 2LL){
        l = s;
        continue;
      }

      vector<ll> sz(k, s / k);
      //cerr << "HERE\n";
      for (int i = 0; i < (s % k); i++) sz[i]++;
      //cerr << "KK\n";
      ll res = 1LL;
      for (ll i : sz) res = mult(res, (ll)i);

      //cerr << res << '\n';
      if (res >= n) { ans = min(ans, s + (a) * (k-1)); r = s; }
      else l = s;
      
      //cerr << l << ' ' << r << ' ' << s << ' ' << k << '\n';
    }
  }

  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n=0;
	int k=0;
	cin>>n>>k;
	vector<int>data(n);
	for(int i=0;i<n;i++){
		data[i]=200001;
	}
	int type=0;
	for(int i=0;i<n;i++){
		int a=0;
		cin>>a;
		if(data[a-1]==200001){
			type++;
			data[a-1]=0;
		}
		data[a-1]++;
	}
	sort(data.begin(),data.end());
	int ans=0;
	for(int i=0;i<type-k;i++){
		ans+=data[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int N,ave,avesub;
    int ans = 0, anssub = 0,sum=0;
    vector<int> X(101);
    cin >> N;
  
    for (int a=0; a < N;a++){
        cin >> X.at(a);
      sum +=X.at(a);
    }

    if(N%2==1){
        ave = sum/N ;
        avesub = sum/N + 1;
    }else{
        ave = sum/N;
        avesub = sum/N + 1;
    }

    for (int b = 0; b < N;b++){
        ans += (X.at(b) - ave) * (X.at(b) - ave);
        anssub +=(X.at(b) - avesub) * (X.at(b) - avesub);
    }

    if(ans<anssub){
        cout << ans << endl;
    }else{
        cout << anssub << endl;
    }
}



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

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

	int n;
	string s;
	unsigned long long int p = 0;
	vector<string> m, a, r, c, h;
	cin >> n;
	for (int i = 0; i < n; ++i){
		cin >> s;
		if (s[0] == 'M'){
			m.push_back(s);
		}else if (s[0] == 'A'){
			a.push_back(s);
		}else if (s[0] == 'R'){
			r.push_back(s);
		}else if (s[0] == 'C'){
			c.push_back(s);
		}else if (s[0] == 'H'){
			h.push_back(s);
		}
	}
	if (!m.empty() && !a.empty() && !r.empty()){
		p += m.size()*a.size()*r.size();
	}
	if (!m.empty() && !a.empty() && !c.empty()){
		p += m.size()*a.size()*c.size();
	}
	if (!m.empty() && !a.empty() && !h.empty()){
		p += m.size()*a.size()*h.size();
	}
	if (!m.empty() && !r.empty() && !c.empty()){
		p += m.size()*r.size()*c.size();
	}
	if (!m.empty() && !r.empty() && !h.empty()){
		p += m.size()*r.size()*h.size();
	}
	if (!m.empty() && !c.empty() && !h.empty()){
		p += m.size()*c.size()*h.size();
	}
	if (!a.empty() && !r.empty() && !c.empty()){
		p += a.size()*r.size()*c.size();
	}
	if (!a.empty() && !r.empty() && !h.empty()){
		p += a.size()*r.size()*h.size();
	}
	if (!a.empty() && !c.empty() && !h.empty()){
		p += a.size()*c.size()*h.size();
	}
	if (!r.empty() && !c.empty() && !h.empty()){
		p += r.size()*c.size()*h.size();
	}
	cout << p << "\n";
	return 0;
}

Measured memory_bytes: 5748