akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc127/tasks/abc127_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M; cin >> N >> M;
    map<ll,ll> mp;
    for(int i = 0; i < N;i++){
        ll a; cin >> a;
        mp[a]++;
    }
    for(int i = 0; i < M;i++){
        ll b,c; cin >> b >> c;
        mp[c]+=b;
    }
    
    for(auto it = mp.rbegin(); it!=mp.rend();it++){
        res += it->first*min(N,it->second);
        N -= min(N,it->second);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 12800
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int v[100000];

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

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

	map<int, int> e_cnt, o_cnt;

	int even_n = 0;
	for (int i=0; i<n; i+=2) {
		e_cnt[v[i]]++;
		even_n++;
	}

	int odd_n = 0;
	for (int i=1; i<n; i+=2) {
		o_cnt[v[i]]++;
		odd_n++;
	}

	int e_most_num = -1;
	int e_most_cnt = 0;
	int e_2nd_most_num = -1;
	int e_2nd_most_cnt = 0;
	for (auto itr : e_cnt) {
		int num = itr.first;
		int val = itr.second;
		if (val > e_most_cnt) {
			e_2nd_most_num = e_most_num;
			e_2nd_most_cnt = e_most_cnt;
			e_most_num = num;
			e_most_cnt = val;
		} else if (val > e_2nd_most_cnt) {
			e_2nd_most_num = num;
			e_2nd_most_cnt = val;
		}
	}

	// **** debug ****
	//cout << "e_most_num=" << e_most_num << " e_2nd_most_num=" << e_2nd_most_num << endl;
	//cout << "e_most_cnt=" << e_most_cnt << " e_2nd_most_cnt=" << e_2nd_most_cnt << endl;

	int o_most_num = -1;
	int o_most_cnt = 0;
	int o_2nd_most_num = -1;
	int o_2nd_most_cnt = 0;
	for (auto itr : o_cnt) {
		int num = itr.first;
		int val = itr.second;
		if (val > o_most_cnt) {
			o_2nd_most_num = o_most_num;
			o_2nd_most_cnt = o_most_cnt;
			o_most_num = num;
			o_most_cnt = val;
		} else if (val > o_2nd_most_cnt) {
			o_2nd_most_num = num;
			o_2nd_most_cnt = val;
		}
	}

	// **** debug ****
	//cout << "o_most_num=" << o_most_num << " o_2nd_most_num=" << o_2nd_most_num << endl;
	//cout << "o_most_cnt=" << o_most_cnt << " o_2nd_most_cnt=" << o_2nd_most_cnt << endl;

	int ans = INF;

	// even の most_num を採用する場合
	int ans_candidate = even_n - e_most_cnt;

	if (e_most_num == o_most_num) {
		ans_candidate += odd_n - o_2nd_most_cnt;
	} else {
		ans_candidate += odd_n - o_most_cnt;
	}

	ans = min(ans, ans_candidate);

	// odd の most_num を採用する場合
	ans_candidate = odd_n - o_most_cnt;

	if (o_most_num == e_most_num) {
		ans_candidate += even_n - e_2nd_most_cnt;
	} else {
		ans_candidate += even_n - e_most_cnt;
	}

	ans = min(ans, ans_candidate);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8564
#include <cstdio>

int main(){
    int a,b;
    char op;
    for(int n = 0; ;){
        scanf("%d %c %d",&a,&op,&b);
    if(op == '?')break;
    else if(op == '+'){printf("%d\n",a + b);}
    else if(op == '-'){printf("%d\n",a - b);}
    else if(op == '*'){printf("%d\n",a * b);}
    else if(op == '/'){printf("%d\n",a / b);}
    }
}


Measured memory_bytes: 2748
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] ARRAY = new int[N];

        int maxIndex = 0;
        int max = 0;
        for (int i=0; i<N; i++) {
            ARRAY[i] = scanner.nextInt();
            if (ARRAY[i] > max) {
                max = ARRAY[i];
                maxIndex = i;
            }
        }

        int[] MAX_ARRAY = new int[N];
        for (int i=0; i<N; i++) {
            if (i == maxIndex) {
                int max2 = 0;
                for (int k=0; k<N; k++) {
                    if (k == i) {
                        continue;
                    }
                    if (ARRAY[k] > max2) {
                        max2 = ARRAY[k];
                        MAX_ARRAY[i] = max2;
                    }
                }
                continue;
            }
            MAX_ARRAY[i] = max;
        }

        for (int i=0; i<N; i++) {
            System.out.println(MAX_ARRAY[i]);
        }
    }
}


Measured memory_bytes: 93096
#include<iostream>

using namespace std;

int main(){
	int n,k;
	while(cin>>n>>k && n && k){
		int s[200000];
		s[0]=0;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			s[i]=s[i-1]+x;
		}
		int ans=s[k];
		for(int i=0;i+k<=n;i++){
			ans=max(ans,s[i+k]-s[i]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1556
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(a,b);
  Vs PIC(a);
  VIN(PIC)
  bool flg = true;
  REP(i,a){
    REP(j,b){
      if(PIC[i][j]=='.') continue;
      bool ok = false;
      REP(k,4){
        int tx = j + dx[k];
        int ty = i + dy[k];

        if(tx < 0 || ty < 0 || tx >= b || ty >= a) continue;

        if(PIC[ty][tx]=='#') ok = true;
      }
      if(!ok) flg = false;
    }
  }
  Yes(flg);
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x := nextInts(5)
	for i := range x {
		if x[i] == 0 {
			puts(i + 1)
		}
	}
}


Measured memory_bytes: 1764
#include<stdio.h>
#include<string.h>

int main(){
  int i,j,k;
  int N,M,max=0;
  
  scanf("%d",&N);
  char B[N][20];
  for(i=0;i<N;i++)
    scanf("%s",B[i]);
  
  scanf("%d",&M);
  char R[M][20];
  for(i=0;i<M;i++)
    scanf("%s",R[i]);
  
  for(i=0;i<N;i++){
    k=0;
    for(j=0;j<N;j++){
      if(strcmp(B[i],B[j])==0)
        k++;
    }
    for(j=0;j<M;j++){
      if(strcmp(B[i],R[j])==0)
        k--;
    }
    if(max < k)
      max = k;
    
  }
  
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

void insert(vector<string> &cont, string value)
{
    auto it = lower_bound(cont.begin(), cont.end(), value, less<string>());
    cont.insert(it, value);
}

int main()
{
    string str;
    int n;
    cin >> str >> n;

    map<char, vector<int> > d;

    for(int i = 0; i < str.length(); i++) {
        d[str[i]].push_back(i);
    }

    for(auto itr = d.begin(); itr != d.end(); ++itr) {
        vector<string> s;
        //cout << "[" << itr->first << "]";
        for(int x : d[itr->first]) {
            //cout << "[" << x << "]";
            for(int i = x; i < min(x + 5, (int)str.length()); i++) {
                string substr = str.substr(x, i - x + 1);
                //cout << substr << endl;
                if(find(s.begin(), s.end(), substr) == s.end()) {
                    insert(s, substr);
                }
            }
        }
        /*
        for(string x2 : s) {
            cout << x2 << " ";
        }*/
        if(s.size() >= n) {
            cout << s[n - 1];
            return 0;
        } else {
            n -= s.size();
        }
    }

    return 0;
}


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

int main() {
 	int X;
  cin>>X;
  int sum=0;
  int quotient = 0;
  quotient = X /500;
  
  sum +=quotient*1000;
  X = X - quotient*500;
  quotient = X /5;
  sum +=quotient*5;
  cout<<sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<deque>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	string s ="";
	for (ll i = 0; i < c - a; i++) {
		s += 'R';
	}
	for (ll i = 0; i < d - b; i++) {
		s += 'U';
	}
	for (ll i = 0; i < c - a; i++) {
		s += 'L';
	}
	for (ll i = 0; i < d - b; i++) {
		s += 'D';
	}
	s += 'D';
	for (ll i = 0; i < c - a + 1; i++) {
		s += 'R';
	}
	for (ll i = 0; i < d - b + 1; i++) {
		s += 'U';
	}
	s += 'L';
	s += 'U';
	for (ll i = 0; i < c - a + 1; i++) {
		s += 'L';
	}
	for (ll i = 0; i < d - b + 1; i++) {
		s += 'D';
	}
	s += 'R';
  	cout<<s<<endl;
}
	


Measured memory_bytes: 256
#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()
#define int long long
typedef pair<int,int> P;

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

const int MAX=(1<<15);
int dp[5][MAX];

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

    dp[0][0]=1;
    for(int i=1;i*i<MAX;i++){
        for(int c=1;c<=4;c++){
            for(int j=i*i;j<MAX;j++){
                dp[c][j]+=dp[c-1][j-i*i];
            }
        }
    }
    int n;
    while(cin>>n,n){
        int ans=0;
        REP(i,5) ans+=dp[i][n];
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4080
N = int(input())
A = list(map(int, input().split()))
CNT = [0] * (N+1)

for i in A:
    CNT[i] += 1

CONB = [CNT[j]*(CNT[j]-1)//2 for j in range(len(CNT))]

SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i] + 1
    print(ans)


Measured memory_bytes: 26140
A,B,C,D = map(int, input().split())

def gcd(a, b):
    while b: a, b = b, a % b
    return a

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

#Bで割り切れれない数 = B - Bで割り切れる数
_not_Divisible_number_B = B - (B//C + B//D - B//lcm(C,D))

#A以上B以下なので
lowA =  A -1

_not_Divisible_number_A_1 = lowA - (lowA//C + lowA//D - lowA//lcm(C,D))

ans = _not_Divisible_number_B - _not_Divisible_number_A_1

print(ans)


Measured memory_bytes: 38256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

string code[256];

int main() {
	int i;
	for(i=0;i<256;i++)code[i]="2";
	code[' ']="101";
	code['\'']="000000";
	code[',']="000011";
	code['-']="10010001";
	code['.']="010001";
	code['?']="000001";
	code['A']="100101";
	code['B']="10011010";
	code['C']="0101";
	code['D']="0001";
	code['E']="110";
	code['F']="01001";
	code['G']="10011011";
	code['H']="010000";
	code['I']="0111";
	code['J']="10011000";
	code['K']="0110";
	code['L']="00100";
	code['M']="10011001";
	code['N']="10011110";
	code['O']="00101";
	code['P']="111";
	code['Q']="10011111";
	code['R']="1000";
	code['S']="00110";
	code['T']="00111";
	code['U']="10011100";
	code['V']="10011101";
	code['W']="000010";
	code['X']="10010010";
	code['Y']="10010011";
	code['Z']="10010000";
	string str,buf;
	while(getline(cin,str)){
		buf="";
		for(i=0;i<str.size();i++){
			if(isalpha(str[i])){
				buf+=(str[i]-'a'&16)?"1":"0";
				buf+=(str[i]-'a'&8)?"1":"0";
				buf+=(str[i]-'a'&4)?"1":"0";
				buf+=(str[i]-'a'&2)?"1":"0";
				buf+=(str[i]-'a'&1)?"1":"0";
			}else if(str[i]==' '){
				buf+="11010";
			}else if(str[i]=='.'){
				buf+="11011";
			}else if(str[i]==','){
				buf+="11100";
			}else if(str[i]=='-'){
				buf+="11101";
			}else if(str[i]=='\''){
				buf+="11110";
			}else if(str[i]=='?'){
				buf+="11111";
			}
		}
//cout<<buf<<endl;
		int j,k;
		for(i=0;i<buf.size();){
			for(j=1;i+j<=buf.size();j++){
				for(k=32;k<128;k++){
					if(buf.substr(i,j)==code[k]){
						cout<<(char)k;
						goto aaa;
					}
				}
			}
			break;
			aaa:;
			i+=j;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 916
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

n = int(input())
a = list(map(int, input().split()))

l = [0 for i in range(n+1)]
r = [0 for i in range(n+1)]

for i in range(1, n+1):
    l[i] = gcd(l[i-1], a[i-1])

for i in range(n)[::-1]:
    r[i] = gcd(r[i+1], a[i])

m = [0 for i in range(n)]

for i in range(n):
    m[i] = gcd(l[i], r[i+1])

print(max(m))

Measured memory_bytes: 14488
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vll count(27, 0);
  for(int i = 0; i < N; i++){
    count.at(S.at(i) - 'a' + 1)++;
  }
  ll ans = 0LL;
  vvll dp(27, vll(27, 0));
  for(int i = 0; i <= 26; i++){
    dp.at(i).at(0) = 1LL;
  }
  for(int i = 1; i <= 26; i++){
    for(int j = 1; j <= i; j++){
      dp.at(i).at(j) += dp.at(i-1).at(j-1) * count.at(i) % MOD;
      dp.at(i).at(j) %= MOD;
      if(j < i) dp.at(i).at(j) += dp.at(i-1).at(j);
      dp.at(i).at(j) %= MOD;
    }
  }
  for(int i = 1; i <= 26; i++){
    ans += dp.at(26).at(i);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
long long a[200010];
long long ans[200010];
long long sum=0,x,y;
int main()
{
    int n;
    scanf("%d",&n);
    
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    x=a[0];
    y=sum-a[0];
    ans[0]=abs(x-y);
    for (int i=1;i<n-1;i++)
    {
        x+=a[i];
        y-=a[i];
        ans[i]=abs(x-y);
    }
    sort(ans,ans+n-1);
    cout<<ans[0]<<endl;
    
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool parent[100005];
int dis[100005];
int dfs(int current)
{
	if (dis[current])
		return dis[current];
	for (int i = 0; i < adj[current].size(); ++i) {
		int next = adj[current][i];
		dis[current] = max(dis[current], 1 + dfs(next));
	}
	return dis[current];
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m, a, b;
	cin >> n >> m;
	while (m--) {
		cin >> a >> b;
		adj[b].push_back(a);
		parent[a] = true;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		if (!parent[i]) {
			dfs(i);
			ans = max(ans, dis[i]);
		}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 10880
<?php
// 重み付きUnion-Find：同じグループに属するかどうかの判定と根からの重みを保持する
class UnionFind2
{
    private $par; // par[$i]:$iの親 自分が根の場合は自身のindexとなる
    private $size; // size[$i]:$iが属するグループの頂点の数
    private $rank; // rank[$i]:$iの重み
    private $diff_weight; // diff_weight[$i]:$iの重みの差

    function __construct($n, $sum_unity = 0)
    {
        for ($i = 0; $i < $n; $i++) {
            $this->par[$i] = $i; // 最初は全てが根
            $this->size[$i] = 1; // 最初は全て1
            $this->rank[$i] = 0; // 最初は全て0
            $this->diff_weight[$i] = $sum_unity;
        }
    }

    function root($x)
    { // 根を返す
        if ($this->par[$x] === $x) return $x; // 根の場合
        $r = $this->root($this->par[$x]);
        $this->diff_weight[$x] += $this->diff_weight[$this->par[$x]]; // 全ての枝の重みの差を根との重みの差にする
        return $this->par[$x] = $r; // 全ての枝の親を根にする
    }

    function weight($x)
    {
        $this->root($x);
        return $this->diff_weight[$x];
    }

    function unite($x, $y, $w)
    { // $xと$yの木を併合
        $w += $this->weight($x);
        $w -= $this->weight($y);
        $ix = $this->root($x);
        $iy = $this->root($y);
        if ($ix === $iy) return;
        if ($this->rank[$ix] < $this->rank[$iy]) {
            list($ix, $iy) = [$iy, $ix];
            $w = -$w;
        }
        if ($this->rank[$ix] === $this->rank[$iy]) $this->rank[$ix]++;
        $this->size[$ix] += $this->size[$iy];
        $this->par[$iy] = $ix; // $yの根を$xの根に付ける
        $this->diff_weight[$iy] = $w;
    }

    function isSame($x, $y)
    { // $xと$yの根が同じか
        return $this->root($x) === $this->root($y);
    }

    function diff($x, $y)
    {
        return $this->weight($y) - $this->weight($x);
    }

    function size($x)
    {
        return $this->size[$this->root($x)];
    }
}

list($n, $m) = ints();
$tree = new UnionFind2($n);
for ($i = 0; $i < $m; $i++) {
    list($l, $r, $d) = ints();
    $l--;
    $r--;
    if ($tree->isSame($l, $r)) {
        if ($tree->diff($l, $r) !== $d) exit('No');
    } else {
        $tree->unite($l, $r, $d);
    }
}
echo 'Yes';

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 23024
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    ans = []
    for s in S:
        if s=="0":
            ans.append(0)
        elif s=="1":
            ans.append(1)
        else:
            if ans:
                ans.pop()
    print(*ans,sep="")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s, rs;
    cin >>s;
    rs = s;
    lli ans = 0;
    reverse(all(rs));
    rep(i,s.size()){
        if(s[i]!=rs[i]){
            ans++;
        }
    }
    out(ans/2);
}

Measured memory_bytes: 3612
using System;

class program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);

        if (A == 1) A += 13;
        if (B == 1) B += 13;

        if (A > B) Console.WriteLine("Alice");
        else if (A < B) Console.WriteLine("Bob");
        else Console.WriteLine("Draw");
    }
}

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

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

ll N;

int main(){
	cin>>N;
	ll n = 1;
	while(N > pow(26, n)){
		N -= pow(26, n);
		n++;
	}

	string res = "";
	N--;
	while(N > 0){
		char a = 'a' + (N % 26);
		res.push_back(a);
		N /= 26;
	}

	while(res.size() < n){
		res.push_back('a');
	}
	reverse(res.begin(), res.end());
	cout<<res<<endl;
	
	return 0;
}


Measured memory_bytes: 4104
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>

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; }

char ToUpper(char cX) { return toupper(cX); }
char Tolower(char cX) { return tolower(cX); }

const long long INF = 1LL << 60;
const long long MOD = 1000000007;

using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

vector<ll> dp;

vector<ll> d;
class Edge {
public:
	ll source, target, cost;
	Edge(ll source = 0, ll target = 0, ll cost = 0) :
		source(source), target(target), cost(cost) {}
	bool operator<(const Edge &e)const {
		return cost < e.cost;
	}
};
vector<Edge> es;
//sはスタート、Vは頂点数、Eは辺数
bool BellmanFord(ll s, ll V, ll E) {
	d = vector<ll>(V, INF);
	d[s] = 0;
	for(ll i = 0;i < V; i++){
		bool update = false;
		for (Edge e:es) {
			if (d[e.source] != INF && d[e.target] > d[e.source] + e.cost) {
				d[e.target] = d[e.source] + e.cost;
				update = true;
			}
			if (i == V - 1) {
				return false;
			}
		}
		if (!update)
			break;
	}
	return true;
}


//全辺のネガティブループチェック
bool find_negative_loop(ll V, ll E) {
	d = vector<ll>(V, 0);
	for (ll i = 0; i < V; i++) {
		for (ll j = 0; j < E; j++) {
			Edge e = es[j];
			if (d[e.target] > d[e.source] + e.cost) {
				d[e.target] = d[e.source] + e.cost;
				if (i == V - 1)
					return true;
			}
		}
	}
	return false;
}


int main()
{
	ll N, M;
	ll r;
	cin >> N >> M;
	cin >> r;

	for (ll i = 0; i < M; i++) {
		ll source, target, cost;
		cin >> source >> target >> cost;
		Edge e(source, target, cost);
		es.push_back(e);

	}
	if (BellmanFord(r,N,M)) {
		for (ll i = 0; i < N; i++) {
			if (d[i] == INF) {
				cout << "INF" << endl;
			}
			else
				cout << d[i] << endl;
		}
		return 0;
	}
	else {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 3168
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<vector>
using std::vector;

#include<algorithm>
using std::sort;

#include<map>
using std::pair;
using std::make_pair;

int main()
{
  int n;
  cin >> n;
  
  vector<pair<int, int>> a(n);
  int tmp;
  for (int i = 0; i < n; i ++)
  {
    cin >> tmp;
    a.at(i) = make_pair(tmp, i + 1);
  }
  
  sort(a.begin(), a.end());
  
  for (int i = 0; i < n; i ++)
  	cout << a.at(i).second << " ";
  
  cout << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
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;
}
int main() {
    int A, B;
    cin >> A >> B;
    if (A == 1 && B == 2) {
        cout << 3 << endl;
    }

    if (A == 1 && B == 3) {
        cout << 2 << endl;
    }
    if (A == 2 && B == 1) {
        cout << 3 << endl;
    }

    if (A == 2 && B == 3) {
        cout << 1 << endl;
    }

    if (A == 3 && B == 1) {
        cout << 2 << endl;
    }

    if (A == 3 && B == 2) {
        cout << 1 << endl;
    }
    return 0;
}

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> cnt(n+1,0);
  for(int x=1;x*x<=n;x++){
    for(int y=1;y*y<=n;y++){
      for(int z=1;z*z<=n;z++){
        ll res = x*x + y*y +z*z + x*y + y*z + z*x;
        if(res<=n) cnt[res]++;
      }
    }
  }
  rep1(i,n){
    cout << cnt[i] << endl;
  }
  return 0;
    

}


Measured memory_bytes: 3560
n = int(input())
if n == 0:
    print(2)
elif n == 1:
    print(1)
else:
    l1 = 2
    l2 = 1
    l3 = 0
    for i in range(n-1):
        l3 = l1
        l1 = l2
        l2 += l3
    print(l2)

Measured memory_bytes: 8904
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end(), greater<>());
    ll ans = 0;
    for (int i = 1; i < n; ++i) {
        ans += v[i/2];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4060
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        
        String slimes = s.next();
        
        int output = 1;
        
        for (int i = 1; i < n; i ++) {
            if (slimes.charAt(i) != slimes.charAt(i - 1)) {
                output ++;
            }
        }
        
        System.out.println(output);
    }
    
}


Measured memory_bytes: 24660
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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;
}

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

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

const unsigned long long INF = 1LL << 60;

////////////////////////////////////////////////////////////

int a, b;
char op;

int main() {
    while (true) {
        cin >> a >> op >> b;

        if (op == '?') break;

        if (op == '+') {
            cout << a + b << endl;
        }
        if (op == '-') {
            cout << a - b << endl;
        }
        if (op == '*') {
            cout << a * b << endl;
        }
        if (op == '/') {
            cout << a / b << endl;
        }
    }
}



Measured memory_bytes: 3080
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

ll power(ll a,ll n,ll m=M){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*a;
        a=a*a;
        n=n>>1;
        ans=ans%m;
        a=a%m;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll k;
    string s;
    cin >> k >> s;
    ll n = s.length();
    ll m = n + k;
    ll c = 1;
    ll ans = power(26, m);
   	ll q = 0;
   	rep(i,0,n){
   		ll r = (c * power(25, m-i)) % M;
   		c = ((c * (m - i)) % M * power(i + 1, M-2)) % M;
   		q = (q + r) % M;
   	}
   	ans = ((ans - q) % M + M) % M;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4260
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
#define MAXM 100000
#define INF 1000000000000000
struct node
{
    int next,to;
    long long w;
}e[MAXM*2+5];
struct Qr
{
    int xr,dec;
    long long lim;
};
long long T;
int cnt,m,n;
int x,y,z,flag;
long long ri=INF,le=-INF;
long long vis[2][MAXN+5];
int b[MAXN+5];
void fpush(int u,int v,long long w)
{
    e[++cnt].next=b[u];
    e[cnt].w=w;
    e[cnt].to=v;
    b[u]=cnt;
}
int Ch(int x){if(x==-1)x=0;return x;}
int main()
{
    fill(vis[0],vis[0]+MAXN+1,INF);
    fill(vis[1],vis[1]+MAXN+1,INF);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        fpush(x,y,z);fpush(y,x,z);
    }
    //dfs(1,0,1);
    queue<Qr> Q;
	Q.push((Qr){1,1,0});
	while(!Q.empty())
	{
	    Qr A=Q.front();
	    Q.pop();
	    int xr=A.xr,dec=A.dec;
	    long long lim=A.lim;
	    for(int i=b[xr];i;i=e[i].next)
        {
            int xnext=e[i].to;
            long long nlim=e[i].w-lim;
            //printf("%d %d %d\n",xnext,dec,nlim);
            //if(dec==-1)nlim=-nlim;
            int FD=Ch(dec);
            //printf("%d %d\n",xnext,FD);
            if(vis[FD][xnext]!=INF)
            {
                if(vis[FD][xnext]!=nlim){printf("0\n");return 0;}
                else continue;
            }
            vis[FD][xnext]=nlim;
            //printf("::up %d %lld\n",xnext,vis[FD][xnext]);
            if(!FD)le=max(le,-vis[FD][xnext]);
            else ri=min(ri,vis[FD][xnext]);
            Q.push((Qr){xnext,-dec,nlim});
        }
	}
    long long T=-1;
    for(int i=1;i<=n;i++)
        if(vis[0][i]!=INF&&vis[1][i]!=INF)
        {
            long long NT=(vis[1][i]-vis[0][i])/2;
            //printf("## %d %lld %lld %lld %lld %lld\n",i,vis[1][i],vis[0][i],le,ri,NT);
            if(NT<0){flag=1;break;}
            if(T==-1)T=NT;
            else if(T!=NT){flag=1;break;}
        }
    if(flag){printf("0\n");}
    if(T!=-1)
    {
        if(T>le&&T<ri)printf("1\n");
        else printf("0\n");
    }
    else printf("%lld",max((long long)0,ri-le-1));
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,n;
  cin>>k>>n;
  vector<int>house(n);
  vector<int>dis(n);
  
for(int i=0;i<n;i++){
  cin>>house.at(i);
}
  
for(int i=0;i<n-1;i++){
  dis.at(i)=house.at(i+1)-house.at(i);
}
dis.at(n-1)=k-house.at(n-1)+house.at(0);
  
sort(dis.begin(),dis.end());

cout<<k-dis.at(n-1)<<endl;

}

Measured memory_bytes: 1920
def main():
    n = int(input())
    a = list(map(int, input().split(' ')))
    a = [a[i]-i-1 for i in range(n)]
    a.sort()
    if n%2 == 0:
        num = int(n/2)
        b = int((a[num-1]+a[num])/2)
        a = [abs(a[i]-b) for i in range(n)]
    else:
        num = int(n/2)
        b = int(a[num])
        a = [abs(a[i]-b) for i in range(n)]
    print(sum(a))
main()

Measured memory_bytes: 25200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res *= a;
		a *= a;
		b >>= 1;
	}
	return res;
}

void solve() {
	ll n; cin >> n;
	string ans = "";
	ll cur = 1;
	while (n > 0) {
		ll temp = n % 26;
		if (temp == 0)temp = 26;
		n -= temp;
		n /= 26;
		ans += char(temp + 'a' - 1);
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

}

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

using namespace std;

#define debug(x) cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) for (auto i : v) cerr << i << " "; cerr << endl;

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);

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

    long long n;

    cin >> n;

    vector<long long> v(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            v[j]++;
        }
    }

    long long ans = 0;

    for (int i = 1; i <= n; i++) {
        ans += i * v[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 81300
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
}

int main() {
	cpp();
	ll n;
	cin >> n;
	vector<ll> v(n);
	for (ll i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<ll> dp(n);
	dp[1] = abs(v[1] - v[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(abs(v[i] - v[i - 2]) + dp[i - 2], abs(v[i] - v[i - 1]) + dp[i - 1]);
	}
	cout << dp[n - 1] << endl;
	return 0;
}







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

int main(){
    int n;
    cin>>n;
    string s;
    ll r=0;
    ll g=0;
    ll b=0;
    cin>>s;
    rep(i, n){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }
    ll ans=r*g*b;
    for(ll i=0;i<n-2;i++){
        for(ll j=i+1;j<n-1;j++){
            if(s[j]==s[i]) continue;
            ll k=2*j-i;
            if(s[k]!=s[i]&&s[k]!=s[j]&&k<n) ans--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <string>
#include <map>
using namespace std;
int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	int a[n][m];
	int x;
	for (int i=0; i < n; i++) {
		for (int j=0; j < m; j++) {
			scanf("%d", &x);
			a[i][j] = x;
		}
	}
	int b[m];
	for (int i=0; i < m; i++) {
		scanf("%d", &x);
		b[i] = x;
	}
	for (int i=0; i < n; i++) {
		int sum;
		sum = 0;
		for (int j=0; j < m; j++) {
			int s;
			s = a[i][j]*b[j];
			sum += s;
		}
		printf("%d\n", sum);
	}
	// printf("\n");
}


Measured memory_bytes: 2752
#include <iostream>
#include <cstring>
#include <vector>
#include <cctype>
#include <cstdio>
using namespace std;
#define rep(i, n) for( int i = 0; i < n; i++ )
typedef vector<int> vec;

int main(){
    char c;
    int alpha[26] = { 0 };
    while( cin >> c ){
        alpha[tolower(c)-'a']++;
    }
    rep(i, 26) cout << (char)('a'+i) << " : " << alpha[i] << endl;
}

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

int main() {
    int n , x , y;
    cin>>n>>x>>y;
    vector<vector<int>>g(n + 1);
    for(int i = 1; i < n; ++i){
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);
    vector<int>ans(n + 1);
    for(int i = 1 ; i  <= n; ++i){
        vector<int>dist(n + 1 , -1);
        queue<int>q;
        q.push(i);
        dist[i] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(int& u : g[v]){
                if(dist[u] == -1){
                    dist[u] = dist[v] + 1;
                    q.push(u);
                }
            }
        }
        for(int k = i + 1; k <= n; ++k){
            ans[dist[k]]++;
        }
    }
    for(int i = 1; i < n; ++i){
        cout<<ans[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 384
public class Main{
  static int f = 10001;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, a, b, c, x, y, t, i;

    for(;;){
      n = sc.nextInt(); a = sc.nextInt(); b = sc.nextInt();
      c = sc.nextInt(); x = sc.nextInt();
      if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0)break;
      t = -1;
      for(i = 0;i < n;i++){
        y = sc.nextInt();
        for(t++;t < f;t++){
          if(x == y)break;
          x = (a * x + b) % c;
        }
        x = (a * x + b) % c;
      }
      if(t < f)out.println(t);
      else out.println("-1");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 31700
#include <bits/stdc++.h>
#define lim 3500
using namespace std;

int n,m,a[lim],b[lim],c[lim][lim],d[lim],k,row,col;
int main()
{
    string s,x;
    cin >> s >> x;
    n = s.size();;
    m = x.size();
    for (int i=1;i<=n;i++) a[i] = s[i - 1] - 'a';
    for (int i=1;i<=m;i++) b[i] = x[i - 1] - 'a';
    for (int i=0;i<=m;i++)
        for (int j=0;j<=n;j++)
            if (i==0 || j==0) c[i][j]=0;
            else if (b[i]==a[j]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i-1][j],c[i][j-1]);
    row=m;
    col=n;
    while (row>=1 && col>=1)
        if (b[row]==a[col])
        {
            k++;
            d[k]=b[row];
            row--;
            col--;
        }
        else if (c[row-1][col]>c[row][col-1]) row--;
        else col--;
    for (int i=k;i>=1;i--) cout<<(char)('a' + d[i]);
    return 0;
}

Measured memory_bytes: 43264
N = int(input())
n = len(str(N))
if n == 1:
    print(N)
else:
    M = [9,0] * (n//2)
    M.pop()
    M = map(str,M)
    M = int(''.join(M))
    if n % 2 == 0:
        print(M)
    else:
        M = M+N-10**(n-1)+1
        print(M)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long S = scan.nextLong();
        long x = 1;
        long y = S;
        if (S <= 1000000000) {
            System.out.println("0 0 0 " + x + " " + y + " 0");
            return;
        }
        x = 1000000000;
        y = 1;
        long m = S/x;
        if (S % x != 0) {
            m += 1;
        }
        long l = m * x - S;
        System.out.println("0 0 " + x + " " + y + " " + l + " " + m);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	string s,s0,s1,ans="~";
	cin>>s>>s1;
	s0=s;
	if(s.size()<s1.size())
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	for(int t=s.size()-s1.size();t>=0;t--)
    {
    	bool ok=1;
    	for(int i=t;i<t+s1.size();i++)
    	{
    		if(s[i]==s1[i-t]||s[i]=='?')
    		{
    			s0[i]=s1[i-t];
			}
			else
			{
				ok=0;
				break;
			}
		}
		if(ok)
		{
			for(int i=0;i<s.size();i++)
			{
				if(s0[i]=='?')
				{
					s0[i]='a';
				}
			}
			ans=min(ans,s0);
		}
		s0=s;
	}
	if(ans=="~")
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void){
    int X,Y,Z;
    int tmp;
    scanf("%d%d%d",&X,&Y,&Z);
    tmp=X;
    X=Y;
    Y=tmp;
    tmp=X;
    X=Z;
    Z=tmp;
    printf("%d %d %d\n",X,Y,Z);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void) {
    int height,width,tile[101][101],i,j;
    char floor[101][101];
    while (1) {
        scanf("%d %d\n",&height,&width);
        if (height==0&&width==0) break;
        for (i=0; i<height; i++) {
            for (j=0; j<width; j++) tile[i][j]=0;
        }
        for (i=0; i<height; i++) {
            for (j=0; j<width; j++) {
                if (j!=width-1) {
                    scanf("%c",&floor[i][j]);
                } else {
                    scanf("%c\n",&floor[i][j]);
                }
            }
        }
       i=0,j=0;
        while (floor[i][j]!='.'&&tile[i][j]!=1) {
            tile[i][j]=1;
            if (floor[i][j]=='>') {
                j++;
            } else if (floor[i][j]=='<') {
                j--;
            } else if (floor[i][j]=='^') {
                i--;
            } else {
                i++;
            }
        }
        if (tile[i][j]==0) {
            printf("%d %d\n",j,i);
        } else {
            printf("LOOP\n");
        }
    }
    return 0;
}

Measured memory_bytes: 664
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        System.out.println((H-h)*(W-w));

    }
}

Measured memory_bytes: 22612
// 計数ソート (p.168 ~ p.172)

#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main() {
  unsigned short *A, *B;

  int C[VMAX + 1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ) {
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ) {
    if ( i > 1 ) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 9640
Imports System.Collections.Generic

Module Main

    Sub Main()

        Dim n As Integer = 0
        Dim val As New Dictionary(Of String, Integer)

        '入力値取得
        n = Integer.Parse(Console.ReadLine())
        For i As Integer = 1 To n
            val(Console.ReadLine) = 1
        Next

        '処理結果出力
        Console.WriteLine(val.Count)

    End Sub

End Module

Measured memory_bytes: 13152