akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)
#define FE(i,n) for(int i = 0; i <= (n); i++)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const ll infl = 9012345678901234567;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//

const int N = 100000;
vector<int> adj[N];
int a[N];
ll b[N];
ll dfs(int u, int p = -1) {
	vector<ll> V; ll sum = 0;
	for (auto &x : adj[u]) {
		if (x == p) continue;
		ll r = dfs(x, u);
		sum += r;
		V.push_back(r);
	}
	if (V.empty()) {
		return a[u];
	}
	if (a[u] > sum) {
		puts("NO"); exit(0);
	}
	else if (2 * a[u] < sum) {
		puts("NO"); exit(0);
	}
	ll A = sum - a[u];
	ll B = 2 * a[u] - sum;
	ll M = *max_element(V.begin(), V.end());
	if (2 * M > sum) {
		if (sum - M < A) {
			puts("NO"); exit(0);
		}
	}
	return B;
}
int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
#endif
	int n; ni(n);
	F(i, n)ni(a[i]);
	if (n == 2) {
		if (a[0] == a[1])puts("YES");
		else puts("NO");
		return 0;
	}
	F(i, n - 1) {
		int u, v; nii(u, v);
		u--; v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int rt = -1;
	F(i, n) {
		if (adj[i].size() > 1) {
			rt = i; break;
		}
	}
	if (dfs(rt) > 0) {
		puts("NO");
	}
	else puts("YES");
	return 0;
}


Measured memory_bytes: 15488
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<i32>().unwrap();

    let mut inum = [0i64; 5];
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();

        let fch = buf.chars().next().unwrap();
        match fch {
            'M' => inum[0] += 1,
            'A' => inum[1] += 1,
            'R' => inum[2] += 1,
            'C' => inum[3] += 1,
            'H' => inum[4] += 1,
            _ => (),
        }
    }

    if inum.iter().all(|&x| x == 0) {
        println!("0");
        return;
    }

    let n0 = inum.into_iter().filter(|&&x| x != 0)
                 .map(|&x| x).collect::<Vec<i64>>();

    let mut r = 0;
    
    let len = n0.len();
    if len == 3 {
        r = n0.iter().fold(1, |acc, &x| acc * x)
    } else if len == 4 {
        r = 0;
        for i in 0..4 {
            let mut r2 = 1;
            for j in 0..4 {
                if i != j {
                    r2 *= n0[j];
                }
            }
            r += r2;
        }
    } else if len == 5 {
        r = 0;
        for i in 0..5 {
            for j in (i + 1)..5 {
                let mut r2 = 1;
                for k in 0..5 {
                    if i != k && j != k {
                        r2 *= n0[k];
                    }
                }
                r += r2;
            }
        }
    }

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


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;

int main(){

    int i,j,k,n,sum1,sum2,min=10000;
    scanf("%d",&n);
    int w[n];
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
    }

    for(i=0;i<n;i++){
        sum1=0;
        sum2=0;      
        for(j=0;j<i;j++){
            sum1+=w[j];            
        }
        for(k=i;k<n;k++){
            sum2+=w[k];
        }
        if(min>abs(sum2-sum1)){
            min=abs(sum2-sum1);
        }

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

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); if(a && b){ return gcd(b, a % b); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    lint B[N - 1];
    cins(B, B + N - 1);
    lint ans = B[0] + B[N - 2];
    for(int i = 1; i < N - 1; i++){
        ans += min(B[i - 1], B[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long int ;
int main()
{
  ll n;
  cin>>n;
  
  set<string>r;
  
  for(int i=0;i<n;++i)
  {
      string s;
      cin>>s;
      r.insert(s);
  }
  cout<<r.size()<<endl;
}

Measured memory_bytes: 19084
package main

import (
        "fmt"
)

func solution(n int, nums []int) int {
        for i := range nums {
                n = n - nums[i]
                if n < 0 {
                        return -1
                }
        }
        return n
}

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        nums := make([]int, m)
        for i := 0; i < m; i++ {
                a := 0
                fmt.Scan(&a)
                nums = append(nums, a)
        }
        fmt.Println(solution(n, nums))
}

Measured memory_bytes: 3020
from collections import Counter

while True:
  n = int(input())
  if not n:
    break
  
  slst = list(map(int, input().split()))
  temp = [i for i in slst]
  ans = 0

  while True:
    ans += 1
    counter = Counter()
    
    for i in slst:
      counter[i] += 1
    slst = [counter[i] for i in temp]
    
    if temp == slst:
      ans -= 1
      break

    temp = [i for i in slst]
  print(ans)
  print(*slst)


Measured memory_bytes: 5992
s = input()
n = len(s)
l = [n-1 for i in range(n)]
r = [0 for i in range(n) ]
for i in range(n-2,-1,-1):
    l[i] = l[i+1]
    if s[i] == 'L':
        l[i] = i

for i in range(1,n):
    r[i] = r[i-1]
    if s[i] == 'R':
        r[i] = i

final_pos = [ -1 for i in range(n) ]

for i in range(n):
    if s[i] == 'R':
        will_go_to = l[i]
        moves_used = l[i] - i
        if moves_used % 2 == 0:
            final_pos[i] = l[i]
        else:
            final_pos[i] = l[i] - 1
    else:
        will_go_to = r[i]
        moves_used = i - r[i]
        if moves_used % 2 == 0:
            final_pos[i] = r[i]
        else:
            final_pos[i] = r[i] + 1

final = [ 0 for i in range(n) ]
for i in final_pos:
    final[i] += 1
for i in final:
    print(i,end=" ")
print()

# RRLRL
#   x    - in 2 moves after that it will rotate
#   x    - in 1 move after that it will rotate
#     x  - in 1 move after that it will roatate
#  x     - in 1 move after that it will rotate
#    x   - in 1 move after that it will rotate


# RRLLLLRLRRLL


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

using namespace std;
typedef long long ll ;
ll arr[5001] , score [5001] , vis[5001];
ll n  , k ;
const ll OO =-1e18;
ll mx;
ll cycleLen(ll idx)
{
    if(vis[idx])
        return 0;
    vis[idx]++;
    ll cnt=cycleLen(arr[idx])+1;
    return cnt;
}
ll cycleVal( ll idx , ll num , ll scsofar , ll MX)
{
    if(vis[idx])
        return 0;
    vis[idx]++;
    scsofar+=score[arr[idx]];
    num++;
    if(num<=MX)mx=max(mx , scsofar);
    ll ans=cycleVal(arr[idx] , num , scsofar , MX)+score[arr[idx]];
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k ;
    cin >> n >>k ;
    for(int i = 1 ; i <=n ;i++)
    {
        cin >> arr[i];
    }
    for(int i = 1 ; i <=n ;i++)
    {
        cin >> score[i];
    }
    ll ans=OO , len , cyc;
    pair<int,int>p;
    for(int i = 1 ; i <=n ; i++)
    {
        memset(vis , 0 , sizeof vis);
        mx=OO;
        len=cycleLen(i);
        memset(vis , 0 , sizeof vis);
        cyc=cycleVal(i , 0 , 0 , k%len );
        ll x= k/len ;
        ans=max(ans , cyc*(x)+mx);
        memset(vis , 0 , sizeof vis);
        mx=OO;
        cyc=cycleVal(i , 0 , 0 , min(k,len) );
      if(x)
        ans=max(ans , cyc*(x-1)+mx);
        ans=max(ans , mx);
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 3908
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

ll Inversion = 0;

void mergekai(vector<ll>& a, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	vector<ll> L(n1);
	vector<ll> R(n2);
	rep(i, n1){
		L.at(i) = a.at(left +i);
	}
	L.push_back(1e10);
	rep(i, n2){
		R.at(i) = a.at(mid + i);
	}
	R.push_back(1e10);
	int i = 0;
	int j = 0;
	for(int k = left; k < right; k++){
		if(L.at(i) > R.at(j)){
			a.at(k) = R.at(j);
			j++;
			Inversion += n1 -i;
		}else{
			a.at(k) = L.at(i);
			i++;
		}
	}
}

void mergesort(vector<ll>& a, int left, int right){
	if(left+1 >= right) return;
	int mid = (left+right)/2;
	mergesort(a, left, mid);
	mergesort(a, mid,right);
	mergekai(a, left, mid, right);
}

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n){
		cin >> a.at(i);
	}
	mergesort(a, 0, n);
	cout << Inversion << endl;
}



Measured memory_bytes: 7612
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
int dp[100003];
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,m;cin>>n>>m;
	vector<int> A(m);
	for(int i = 0; m > i; i++){
		cin>>A[i];
	}
	dp[0] = 1;
	int nw = 0;
	for(int i = 0; n > i; i++){
		if(nw != A.size() && A[nw] == i){
			nw++;
			continue;
		}
		dp[i+1] = (dp[i+1]+dp[i])%mod;
		dp[i+2] = (dp[i+2]+dp[i])%mod;
	}
	cout << dp[n] << endl;
}

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

class unionfind{
    private:
    std::vector<int> UF,rank;
    public:
    
    void init(int N){
        UF.clear();
        rank.clear();
        for(int i=0;i<N;i++){
            UF.push_back(i);
            rank.push_back(0);
        }
    }
    
    int root(int k){
        if(UF[k]==k){
            return k;
        }else{
            UF[k]=root(UF[k]);
            return UF[k];
        }
    }
    
    bool same(int p,int q){
        return root(p)==root(q);
    }
    
    void unite(int P,int Q){
        int p=root(P);
        int q=root(Q);
        if(p==q)return;
        if(rank[p]<rank[q])std::swap(p,q);
        UF[q]=p;
        if(rank[p]==rank[q])rank[p]++;
    }
    
};


int main(){
    
    int N,K,L;
    int p[114514],q[114514],r[114514],s[114514];
    cin >> N >> K >> L;
    map<pair<int,int>,int> MP;
    REP(i,K){
        cin >> p[i] >> q[i];
        p[i]--;q[i]--;
    }
    REP(i,L){
        cin >> r[i] >> s[i];
        r[i]--;s[i]--;
    }
    unionfind UF,UF2;
    UF.init(200000);
    UF2.init(200000);
    REP(i,L){
        UF.unite(r[i],s[i]);
    }
    REP(i,K){
        UF2.unite(p[i],q[i]);
    }
    REP(i,N){
        MP[{UF.root(i),UF2.root(i)}]++;
    }
    //REP(i,N){cout << UF[i] << " ";}cout << endl;
    //REP(i,N){cout << UF2[i] << " ";}cout << endl;
    REP(i,N){
        if(i!=0)cout << " ";
        cout << MP[{UF.root(i),UF2.root(i)}];
    }cout << endl;
    return 0;
}

Measured memory_bytes: 16788
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		if(2*s[1]-1>s[0]){
			Console.WriteLine(-1);
			return;
		}
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<s[0];i++) {
			sb.Append(i/2+s[1]+(i&1)*(s[0]>>1)+(s[0]&1)*(i&1)).Append(" ").Append(i/2+s[1]+(~i&1)*(s[0]>>1)+s[0]).Append(" ").Append(i+s[1]+s[0]*2).Append("\n");
		}
		Console.Write(sb);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 26072
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const ss = input.slice(1);
  let prevMap = {};
  let map = {};
  for (let i = 0; i < n; i++) {
    map = {};
    const s = ss[i];
    for (let j = 0; j < s.length; j++) {
      const char = s[j];
      if (i === 0) {
        map[char] = map[char] ? map[char] + 1 : 1;
        continue;
      }
      if (!prevMap[char]) continue;
      prevMap[char]--;
      map[char] = map[char] ? map[char] + 1 : 1;
    }
    prevMap = Object.assign({}, map);
  }
  const keys = Object.keys(map).sort();
  let result = "";
  for (const key of keys) {
    result += Array(map[key]).fill(key).join("");
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7884
N = int(input())
S = input()
L = len(S)
T = ''
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

for i in range(L):
  for j in range(26):
    if S[i] == alpha[j]:
      T = T + alpha[j + N]
      break

print(T)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;

int ans[200010],nex[200010],dis[200010];
struct node{
    int s,t,x;
    friend bool operator<( const node&a , const node&b ){
        return a.x<b.x;
    }
}a[200010];

int main(){
    int n,q;
    scanf( "%d%d" , &n , &q );
    for( int i=0 ; i<n ; i++ ){
        scanf( "%d%d%d" , &a[i].s , &a[i].t , &a[i].x );
        a[i].t--;
        a[i].s -= a[i].x;
        a[i].t -= a[i].x;
    }
    for( int i=0 ; i<q ; i++ ){
        scanf( "%d" , &dis[i] ); ans[i] = -1; nex[i] = i+1;
    }
    sort( a , a+n );
    for( int i=0 ; i<n ; i++ ){
        int l = a[i].s,r = a[i].t;
        int ll = lower_bound( dis , dis+q , l )-dis;
        int rr = upper_bound( dis , dis+q , r )-dis;
        for( int j=ll ; j<rr ;  ){
            if( ans[j]==-1 ) ans[j] = a[i].x;
            int t = nex[j];
            nex[j] = max( nex[j] , rr );
            j = t;
        }
    }
    for( int i=0 ; i<q ; i++ ){
        printf( "%d\n" , ans[i] );
    }
    return  0;
}


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

int main(){
  int N, K;
  cin >> N >>  K;
  vector<int> data(N, 0);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  vector<int> num(N, 0);
  for(int i = 0; i < N; i++){
    num.at(data.at(i) - 1)++;
  }
  sort(num.begin(), num.end());
  int M = 0;
  for(int i = 0; i < N;i++){
    if(num.at(i) > 0) M++;
  }
  int L = M - K;
  int count;
  for(int i = N - M; i < N - M + L;i++){
    count += num.at(i);
  }
  cout << count << endl;
}

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

int main() {

    string s;

    cin >> s;

    int n = s.size();

    int left = 0;
    int right = n - 1;

    int sum = 0;

    while(1) {
        int lCount = left;
        int rCount = right;

        while(left < n && s[left] == 'x')left++;
        while(right >= 0 && s[right] == 'x')right--;

        if(s[left] != s[right]) {
            cout << -1 << endl;
            return 0;
        }

        sum += abs((left - lCount) - (rCount - right));


        left++;
        right--;

        if(left >= right)
            break;


    }

    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 3752
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
 
class Main
{
  public static void main(String[] args) throws IOException {
    BufferedReader buf;
    buf = new BufferedReader(new InputStreamReader(System.in));
    int S = Integer.parseInt(buf.readLine());
    int h = S / 3600;
    int tmp = S - (h * 3600);
    System.out.println(h+":"+(tmp/60)+":"+(tmp-(tmp/60)*60));
  }
}

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

using namespace std;

void f(int set[][501],int m)
{
	int ss[100][100]={};

	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++)
		{
			ss[j][(m-1)-i]=set[i][j];
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++)
		{
			set[i][j]=ss[i][j];
		}
	}
}

void log(int set[][501],int m,int setcount)
{
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<m;j++)
		{
			printf("%02d ",set[i][j]); 
		}
		cout << endl;
	}

	cout << setcount << endl;
}

int main()
{
	int n,m;

	while(cin >> n >> m && n)
	{
		int flag=0;
		int setcount=0;
		int count=0;
 		int data[201][201]={};
 		int set[501][501]={};
 		int i,j,k,l;
 		int ans[150][150]={};

 		for(i=0;i<n;i++)
	 		for(j=0;j<n;j++)
	 			cin >> data[i][j];

 		for(i=0;i<m;i++)
 		{
 			for(j=0;j<m;j++)
 			{
 				cin >> set[i][j];
 				if(set[i][j]>=0)setcount++;
 			}
 		}

 		for(int z=0;z<4;z++)
 		{
 			int first=0;
	 		for(int l=0;l<n-m+1;l++)
	 		{
	 			for(int k=0;k<n-m+1;k++)
	 			{
	 				count=0;
	 				for(i=0;i<m;i++)
		 			{
			 			for(j=0;j<m;j++)
			 			{
			 				if(set[i][j]==data[i+l][j+k])count++;
			 				if(count==setcount)flag=1;
			 			}
		 			}
		 			if(count==setcount)
		 			{
		 				for(i=0;i<m;i++)
		 				{
				 			for(j=0;j<m;j++)
				 			{
				 				if(set[i][j]==data[i+l][j+k] && !first)
				 				{
				 					ans[i+l][j+k]++;
			 						first=1;
			 						break;
				 				}
				 			}
				 			if(first)break;
		 				}
		 			}
		 			if(first)break;
	 			}
	 			if(first)break;
		 	}
	 		f(set,m);
 		}
 		if(flag)
 		{
 			for(i=0;i<n;i++)
 			{
 				for(j=0;j<n;j++)
 				{
 					if(ans[i][j])
 					{
 						cout << j+1 << " " << i+1 <<endl;
 						break;
 					}
 				}
 				if(ans[i][j])break;
 			}
 		}
 		else if(!flag)cout << "NA" << endl;
	}

    return 0;
}

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

int n, c, s;

int main(){
	cin >> n;
	s = 0;
	for (int i = 1; i <= n; i+=2){
		c = 0;
		for (int j = 1; j <= i; ++j){
			c += (i % j == 0);
		}
		s += (c == 8);
	}
	cout << s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000001
vector<vector<ll>> dist;

void warshall_floyd(int n) { // nは頂点数
  for (int i = 1; i <= n; i++)      // 経由する頂点
    for (int j = 1; j <= n; j++)    // 開始頂点
      for (int k = 1; k <= n; k++){  // 終端
    	  if(i==j||j==k||i==k)continue;
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
      }
}

int main(){
	ll n,m,r;
	cin>>n>>m>>r;
	vector<ll> a(m),b(m),c(m);
	vector<ll>list(r);
	dist=vector<vector<ll>>(n+1,vector<ll>(n+1,INF));

	for(ll i=0;i<r;i++){
		cin>>list[i];
	}
	sort(list.begin(),list.end());
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i]>>c[i];
		dist[a[i]][b[i]]=c[i];
		dist[b[i]][a[i]]=c[i];
	}
	ll res=INF,tmp=0;
	warshall_floyd(n);
	//sort(list.begin(),list.end());
	do{
		tmp=0;
		for(int i=0;i<r-1;i++){
			//cout<<"i:"<<i<<" "<<list[i]<<list[i+1]<<endl;
			//cout<<dist[list[i]][list[i+1]]<<endl;
			tmp+=dist[list[i]][list[i+1]];
		}
		res=min(res,tmp);
	}while(next_permutation(list.begin(),list.end()));

	cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;

  int ans = 0;
  for(int i=1; i<=b; i++){
    long long temp = a * i;
    if( temp % b == c ){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    int a, b, c, d;
    
    cin>>a>>b>>c;
    
    d=(c-(a-b));
    
    if (d<0) d=0;
    cout<<d<<endl;
    
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            (long N, long P) = Slice<long, long>();
            var S = ReadLine();
            var Sn = new long[N];
            for (var i = 0; i < N; ++i)
                Sn[i] = S[i] - '0';
            Array.Reverse(Sn);
            var ans = 0L;
            if (P == 2 || P == 5) 
            {
                for (var i = 0; i < N; ++i)
                {
                    if (Sn[i] % P == 0)
                        ans += N - i;
                }
                WriteLine(ans);
                return;
            }

            var Pmods = new long[10000 + 1];
            Pmods[0] = 1;
            var _10p = 1L;
            var sum = 0L;
            for (var i = 0; i < N; ++i)
            {
                sum = (sum + _10p * Sn[i] % P) % P;
                ++Pmods[sum];
                _10p = _10p * 10 % P;
            }
            foreach (var p in Pmods)
                ans += p * (p - 1) / 2;
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 29888
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    ll n;
    cin >> n;

    int res = 20;

    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i)
            continue;
        ll a = i;
        ll b = n / i;

        int fa = 0;
        while (a > 0)
            a /= 10, fa++;

        int fb = 0;
        while (b > 0)
            b /= 10, fb++;

        res = min(res, max(fa, fb));
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

	if (x < 600) {
		cout << 8 << endl;
	}
	else if (x < 800) {
		cout << 7 << endl;
	}
	else if (x < 1000) {
		cout << 6 << endl;
	}
	else if (x < 1200) {
		cout << 5 << endl;
	}
	else if (x < 1400) {
		cout << 4 << endl;
	}
	else if (x < 1600) {
		cout << 3 << endl;
	}
	else if (x < 1800) {
		cout << 2 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        ArrayList<Integer> set = new ArrayList<>(num);
        for(int i=0;i<num;i++){
            set.add(sc.nextInt());
        }
        GetMinMaxSum gmms = new GetMinMaxSum();
        System.out.println(gmms.min(set) + " " + gmms.max(set) + " " + gmms.sum(set));
    }
}
class GetMinMaxSum{
    long ret = 0;
    long sum(ArrayList<Integer> list){
        ret = 0;
        for(int a : list){
            ret += a;
        }
        return ret;
    }
    long max(ArrayList<Integer> list){
        Collections.sort(list);
        ret = list.get(list.size()-1);
        return ret;
    }
    long min(ArrayList<Integer> list){
        Collections.sort(list);
        ret = list.get(0);
        return ret;
    }
}

Measured memory_bytes: 43608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int k= 1;
        while(k-->0){
            //int n= s.nextInt() ;
            long res=0;
            for(int i=0;i<3;i++){
                res+=s.nextInt();
            }
            if(res>=22)
                System.out.println("bust");
            else
                System.out.println("win");
        }
    }

    private static int binary_search(
            int arr[], int l,
            int h, int x)
    {
        while (l <= h) {
            int mid = (l + h) / 2;
            if (arr[mid] <= x)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }
    static int gcd(int a, int b)
    {
        if(b==0) {
            return a;
        }
        return gcd(b,a%b);
    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

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

}

Measured memory_bytes: 27020
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NAB = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(Math.Min(NAB[0] * NAB[1], NAB[2]));
        }
    }
}


Measured memory_bytes: 28252
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int n;
vector<int> d;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    d.resize(n);
    rep(i,0,n) cin>>d[i];
    sor(d);
    cout <<d[n/2]-d[n/2-1]<<"\n";
}

Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, x; cin>>n;
    if(n<=1000) cout<<(1000-n)<<endl;
    else if(n<=2000) cout<<(2000-n)<<endl;
    else if(n<=3000) cout<<(3000-n)<<endl;
    else if(n<=4000) cout<<(4000-n)<<endl;
    else if(n<=5000) cout<<(5000-n)<<endl;
    else if(n<=6000) cout<<(6000-n)<<endl;
    else if(n<=7000) cout<<(7000-n)<<endl;
    else if(n<=8000) cout<<(8000-n)<<endl;
    else if(n<=9000) cout<<(9000-n)<<endl;
    else if(n<=10000) cout<<(10000-n)<<endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll tot=0,ans=0,n,m;cin>>n>>m;
    pair<ll,ll> a[n];
    for(ll i=0;i<n;i++)cin>>a[i].first>>a[i].second;
    sort(a,a+n);
    for(ll i=0;i<n && tot<m ;i++){
        ans+=min(m-tot,a[i].second)*a[i].first;
        tot+=min(m-tot,a[i].second);
    }
    cout<<ans;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  int a, b;
  cin >> a >> b;
  rep(i, h){
    rep(j, w){
      bool f1 = (i < b);
      bool f2 = (j < a);
      if((f1^f2) == true) cout << 0;
      else cout << 1;
    }
    cout << endl;
  }
  return 0;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}



int main(){
	ll n, m;
	cin >> n >> m;
	
	ll ans = 0;
	if(0 <= m - 2*n){
		ans += n;
		m -= 2*n;
		if(0 < m){
			ans += m / 4;
		}
	}
	else{
		ans += m / 2;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
  public static Scanner cin;
  public static HashSet<String> m;

  public static String reverse(String s){
    return new StringBuffer(s).reverse().toString();
  }

  public static void arrange(){
    String s=cin.nextLine();
    m=new HashSet<String>();
    int i=1;
    for(;i<s.length();i++){
      String s1=s.substring(0,i),s2=s.substring(i);
      m.add(s1+s2);
      m.add(reverse(s1)+s2);
      m.add(s1+reverse(s2));
      m.add(reverse(s1)+reverse(s2));
      m.add(s2+s1);
      m.add(reverse(s2)+s1);
      m.add(s2+reverse(s1));
      m.add(reverse(s2)+reverse(s1));
    }
    System.out.println(m.size());
  }

  public static void main(String []args){
    cin=new Scanner(System.in);
    int i=0,n=cin.nextInt();
    cin.nextLine();
    for(;i<n;i++)arrange();
  }
}

Measured memory_bytes: 13000
import sys
from itertools import product

def mat2_mul(X, Y):
    Z = [ [0, 0], 
          [0, 0] ]
    for (i,j,k) in product(range(2),range(2),range(2)):
        Z[i][j] += X[i][k] * Y[k][j]
    return Z

def mat2_pow(X, n):
    if n == 0:
        return [ [1, 0],
                 [0, 1] ]
    elif n % 2:
        return mat2_mul(X, mat2_pow(X, n-1))  
    else:
        half_pow = mat2_pow(X, n/2)
        return mat2_mul(half_pow, half_pow)

def fib(n):
    if n == 0:
        return 0
    else:
        F = [ [0, 1],
              [1, 1] ]
        return mat2_pow(F, n-1)[1][1]
    
n, m = map(int,input().split())

li = [input() for _ in range(m)]

for i in range(1,len(li)):
    if int(li[i]) - int(li[i-1]) == 1:
        print(0)
        sys.exit()

ans = ["a" for i in range(n+1)]

for i in li:
    ans[int(i)] = "#"
    
ans = "".join(ans)

ans = ans.split("#")

result = 1

for i in ans:
    result *= fib(len(i))

print(result%1000000007)

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, M;
int K, A;
int t[40];


signed main(){
	cin >> N >> M;
	rep(i, 0, N){
		cin >> K;
		rep(j, 0, K){
			cin >> A;
			t[A]++;
		}
	}

	int ans = 0;
	rep(i, 0, 40)
		if(t[i] == N) ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x;
    cin >>n>>m>>x;
    vector<int> a(m);
    int i,j;
    for(i=0;i<m;i++)cin >> a.at(i);
    int r1=0;
    int r2=0;
    for(i=1;i<=x;i++){
        for(j=0;j<m;j++){
            if(a.at(j)==i){
                r1++;
            }
        }
    }
        for(i=x+1;i<n;i++){
            for(j=0;j<m;j++){
                if(a.at(j)==i){
                    r2++;
                }
        }
        }
    //cout << r1 << " " << r2 << endl;
    if(r1>=r2)cout << r2<<endl;
    else cout << r1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<x<<" "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 366666, maxn = 1666666;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
const ll mod = 7;

int n;
char s[N];
vector<int> r, g, b;
map<int, bool> visr, visg, visb;
void solve()
{
    scanf("%d %s", &n, s);
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'R') r.pb(i), visr[i] = 1;
        else if(s[i] == 'G') g.pb(i), visg[i] = 1;
        else if(s[i] == 'B')b.pb(i), visb[i] = 1;
    }
    //for(auto x:r) printf("%d\n", x);
    ll ans = 0;
    for(int j = 1; j < n-1; ++j) {
        for(int i = 0; i < j; ++i) {
            if(s[i]==s[j]) continue;
            int tmp;
            if(s[i]!='R'&&s[j]!='R') {
                tmp = upper_bound(r.begin(), r.end(), j)-r.begin();
                tmp = SZ(r)-tmp;
                if(visr[2*j-i]) tmp--;
            }
            else if(s[i]!='G'&&s[j]!='G') {
                tmp = upper_bound(g.begin(), g.end(), j)-g.begin();
                tmp = SZ(g)-tmp;
                if(visg[2*j-i]) tmp--;
            }
            else if(s[i]!='B'&&s[j]!='B') {
                tmp = upper_bound(b.begin(), b.end(), j)-b.begin();
                tmp = SZ(b)-tmp;
                if(visb[2*j-i]) tmp--;
            }
            ans+=tmp;
        }
    }
    printf("%lld\n", ans);
}


int main()
{

//    int _;scanf("%d", &_);while(_--)
//    while(~scanf("%d", &n))
    solve();
	return 0;
}


Measured memory_bytes: 4884
import java.util.Scanner;

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

        int N = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(N, D));

        sc.close();
    }

    static int solve(int N, int D) {
        return (N + D * 2) / (D * 2 + 1);
    }
}

Measured memory_bytes: 35848
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define FAIL {printf("No");exit(0);}
#define SUCC {printf("Yes");exit(0);}
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
vector<int> G[N],S;
int n,m,vis[N];
int dfs(int u,int last) {
    if(vis[u]) return vis[u];
    for(int i=0;i<G[u].size();++i)
        if(G[u][i]!=last) return vis[u]=dfs(G[u][i],u);
}

int main() {
    rd(n),rd(m);
    for(int i=1;i<=m;++i) {
        int x,y; rd(x),rd(y);
        G[x].PB(y),G[y].PB(x);
    }
    for(int i=1;i<=n;++i) if(G[i].size()&1) FAIL;
    for(int i=1;i<=n;++i) if(G[i].size()>=6) SUCC;
    for(int i=1;i<=n;++i) if(G[i].size()==4) S.PB(i);
    if(S.size()>=3) SUCC;
    if(S.size()<2) FAIL;
    int s=S[0],t=S[1];
    vis[s]=1,vis[t]=2;
    for(int i=1;i<=n;++i) if(!vis[i]) {
        if(dfs(G[i][0],i)==dfs(G[i][1],i)) SUCC;
        vis[i]=3;
    }
    FAIL;
}

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

int main()
{
  long long int x,k,d;
  cin>>x>>k>>d;
  x=abs(x);
  long long int step=x/d;
  if(step>=k)
    cout<<(x-k*d);
  else{
  long long int pos=x%d;
  k=k-step;
  if(k%2==0)
  {
   cout<<abs(pos);
  }
  else
  {
    cout<<min(abs(pos-d),abs(pos+d));
  }
  }
  return 0;
}

Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;



int main() {
	int A, B, K;
	cin >> A >> B >> K;
	REP(i, K) {
		if (i % 2 == 0) {
			if (A % 2 == 1) {
				A--;
				A = A / 2;
				B += A;
			}
			else {
				A = A / 2;
				B += A;
			}
		}
		else {
			if (B % 2 == 1) {
				B--;
				B = B / 2;
				A += B;
			}
			else {
				B = B / 2;
				A += B;
			}
		}
	}
	cout << A << " " << B << endl;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char x[1001];
	int i,z;
	do
	{
		i=0;z=0;
		scanf("%s",x);

		if (x[0] != '0')
		{
			for (i = 0; x[i] != '\0'; i++)
			{
				z += x[i]-'0';
			}
			printf("%d\n", z);
		}
	}while (x[0] != '0');
	return 0;
}

Measured memory_bytes: 536
#include "bits/stdc++.h"
using namespace std;

void solve(){
    int k;
  cin>>k;
    string a;
    cin>>a;

  
  if((int)a.size()>k){
    for(int i =0;i<k;i++){
      cout<<a[i];
    }
    cout<<"..."<<"\n";
  }
  else cout<<a<<"\n";
    
}

int main()
{

           solve();

    return 0; 
}


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

using namespace std;

int main(void)
{
    int n, x, t;
    cin >> n >> x >> t;
    if(n % x > 0){
        cout << (n / x + 1) * t << endl;
    }
    else{
        cout << n / x * t << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		int q=Integer.parseInt(sc.next());
		int a=0;
		int b=0;
		String c="";
		String f="";
		String x="";
		String y="";
		String p="";
		for(int i=0;i<q;i++){
			String request=sc.next();
			switch(request){
			case "print":
				a=Integer.parseInt(sc.next());
				b=Integer.parseInt(sc.next())+1;
				System.out.println(str.substring(a,b));
				break;
			case "reverse":
				a=Integer.parseInt(sc.next());
				b=Integer.parseInt(sc.next())+1;
				c=str.substring(a,b);
				StringBuffer sb=new StringBuffer(c);
				c=sb.reverse().toString();
				x=str.substring(0,a);
				y=str.substring(b,str.length());
				str=x+c+y;
				//System.out.println(str);
				break;
			case "replace":
				a=Integer.parseInt(sc.next());
				b=Integer.parseInt(sc.next())+1;
				p=sc.next();
				x=str.substring(0,a);
				y=str.substring(b,str.length());
				str=x+p+y;
				break;
			}
		}
	}

}



Measured memory_bytes: 29164