akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace b120B {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = input[0];
            var b = input[1];
            var k = input[2];

            for (int i = Math.Min(a,b); i > 0; i--) {
                if (a % i == 0 && b % i == 0) {
//                    Console.WriteLine(i);
                    k--;
                    if (k == 0) {
                        Console.WriteLine(i);
                        return;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 13268
import sys
input=sys.stdin.readline
s=input()[:-1]
ans=0
while s:
    a=s[0]
    b=s[-1]
    if a==b:
        s=s[1:-1]
        continue
    elif a=="x":
        s=s[1:]
        ans+=1
        continue
    elif b=="x":
        s=s[:-1]
        ans+=1
        continue
    else:
        print(-1)
        exit()

print(ans)


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
string s[3];

int main() {
	cin >> n;
	inc(j, 3) { cin >> s[j]; }
	
	int ans = 0;
	inc(i, n) {
		set<char> se;
		inc(j, 3) { se.insert(s[j][i]); }
		ans += se.size() - 1;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
use proconio::input;

#[allow(unused_mut)]
fn main() {
    input! {
        n: usize
    }
    let mut res = 0;
    for i in 0..n + 1 {
        if get_digit(i) % 2 == 1 {
            res += 1;
        }
    }
    println!("{}", res);
}

fn get_digit(n: usize) -> usize {
    let mut n = n;
    let mut count = 0;
    while n != 0 {
        n /= 10;
        count += 1;
    }
    count
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N; cin >> N;
  pair<ll, ll>p[N];
  rep(i, N){
    ll a, b;
    cin >> a >> b;
    p[i] = {b, a};
  }
  sort(p, p+N);
  bool can=true; ll tmp=0;
  rep(i, N){
    tmp += p[i].second;
    if(tmp>p[i].first) can=false;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
 
}

Measured memory_bytes: 3456
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<vector<lld> > dp(3001,vector<lld>(3001,0)),par(3001,vector<lld>(3001,0));
int main()
{
     ios;
     string s,t;
     cin>>s>>t;
     lld n1=s.size(),n2=t.size();
     rep(i,1,n1)
     {
         dp[i]=dp[i-1];
         rep(j,1,n2)
         {
             if(s[i-1]==t[j-1])
             {
                 if(dp[i][j]<dp[i-1][j-1]+1)
                 {
                     dp[i][j]=dp[i-1][j-1]+1LL;
                     par[i][j]=2;
                 }
             }
             else
             {
                 if(dp[i][j]<dp[i][j-1])
                 {
                     dp[i][j]=dp[i][j-1];
                     par[i][j]=1;
                 }
             }
         }
     }
     lld i=n1,j=n2;
     string ans="";
     while(i&&j)
     {
         //cout<<i<<" "<<j<<" "<<par[i][j]<<endl;
         if(par[i][j]==0)
         {
             i--;
         }
         else if(par[i][j]==1)
         {
             j--;
         }
         else
         {
             i--;
             j--;
             ans+=s[i];
         }
     }
     reverse(all(ans));
     cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 141184
#include<set>
#include<iostream>
#include<ctime>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<functional>
#include<string.h>
#include<limits.h>
#define int long long
using namespace std;

int a[100005];
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == i + 1) {
			ans++;
			swap(a[i], a[i + 1]);
		}
	}
	if (a[n - 1] == n)ans++;
	cout << ans << endl;
}

Measured memory_bytes: 1024
/**
 * C - Good Sequence
 * https://atcoder.jp/contests/abc082/tasks/arc087_a
 **/
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    vector<int> map(100001, 0);
    int ans = 0;
    for(int i=0; i<N; i++) {
        int tmp;
        cin >> tmp;
        if(tmp>N) {
            ans++;
        } else {
            map[tmp]++;
        }
    }
    for(int i=1; i<N+1; i++) {
        if(map[i]==0) {
            continue;
        } else if(map[i]>i) {
            ans += map[i]-i;
        } else if(map[i]<i) {
            ans += map[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> a(N); for (int i = 0; i < N; ++i) cin >>a[i];
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n;
    cin>>n;
    vector<P>ab(n);
    rep(i,n)cin>>ab[i].second>>ab[i].first;
    sort(ab.begin(),ab.end(),greater<>());
    int memo=LLONG_MAX;
    rep(i,n){
        memo=min(memo,ab[i].first);
        memo-=ab[i].second;
    }
    if(memo<0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


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

#define N (1<<18)
#define ll long long
#define ld long double
#define M 1000000007
#define INF 0x5ADFACE5
#define LINF 0x51DEEFFEC7C0DECALL
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second

using namespace std;

int main() {
	int n, c, k;
	cin>>n>>c>>k;
	int v[n];
	for (int i = 0; i < n; i++) cin>>v[i];
	sort(v, v + n);
	int ans = 1;
	int l = c - 1;
	int b = v[0];
	for (int i = 1; i < n; i++) {
		if (!l) {
			ans++;
			l = c - 1;
			b = v[i];
		} else if (b + k < v[i]) {	
			ans++;
			l = c - 1;
			b = v[i];
		} else l--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    int N;
    cin >> N;
    vector<int> d(N, -1);
    vector<vector<pair<int, int>>> a(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        a[u].push_back(make_pair(v, w));
        a[v].push_back(make_pair(u, w));
    }
    queue<int> q;
    q.push(0);
    d[0] = 0;
    while (q.size()) {
        int p = q.front();
        q.pop();
        for (auto x:a[p]) {
            if (d[x.first] != -1)continue;
            d[x.first] = (d[p] + x.second) & 1;
            q.push(x.first);
        }
    }
    for (auto x:d) {
        cout << x << endl;
    }
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, x, y; cin>>n>>x>>y;
    map<ll,ll> mp;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            ll val= j-i;
            val=min(val,abs(x-i)+1+abs(y-j));
            val=min(val,abs(y-i)+1+abs(x-j));
            mp[val]++;
        }
    }
    for(int i=1;i<=n-1;i++) cout<<mp[i]<<endl;
}

Measured memory_bytes: 384
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;

class Main{
    public static void main(String[] args){
	int count = 0;
	int N;
	InputStream inputStream = System.in;
	InputReader input = new InputReader(inputStream);
	N = input.nextInt();
	int[] num = new int[N];
	for(int i = 0;i < N;i++){
	    num[i] = input.nextInt();
	}
	for (int i = 0; i < N - 1; i++) {
	    for(int j = N-1;j > i;j--){
		if(num[j - 1] > num[j]){
		    int temp = num[j - 1];
		    num[j - 1] = num[j];
		    num[j] = temp;
		    count++;
		}
	    }
	}
	
	print(num);
	System.out.println(count);
    }
    static void print(int[] num){
	        for (int i = 0; i < num.length; i++) {
            if (i != 0) {
                System.out.print(" ");
            }
            System.out.print(num[i]);
        }
        System.out.println();
    }
}


class InputReader{
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    //InputReaderクラスのコンストラクタ
    public InputReader(InputStream stream){
	reader = new BufferedReader(new InputStreamReader(stream),32768);
	tokenizer = null;	
    }
    public String next(){
	while (tokenizer == null || !tokenizer.hasMoreTokens()){
	    try{
		tokenizer = new StringTokenizer(reader.readLine());	    
	    }catch(IOException e){
		throw new RuntimeException(e);
	    }
	}
	return tokenizer.nextToken();
    }
    public int nextInt(){
	return Integer.parseInt(next());
    }
    
}



Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int A,B;
    cin >> A >> B;
    cout << A*B << endl;
}

Measured memory_bytes: 3636
n,m  = map(int, input().split())

todai = []
heights = list(map(int, input().split()))

for i in range(n):
    todai.append([heights[i]])

for i in range(m):
    a, b = map(int, input().split())
    todai[a-1].append(heights[b-1])
    todai[b-1].append(heights[a-1])

good = 0
for i in range(n):
    if len(todai[i]) == 1:
        good += 1
    else:
        for j in range(1, len(todai[i])):
            if todai[i][0] <= todai[i][j]:
                break
            else:
                if j == len(todai[i])-1:
                    good += 1

print(good)


Measured memory_bytes: 25952
def enq(a,x)
  f =->(x){x.is_a?(Array) ? x[0] : x}
  a = [a]  if a[i=-1]
  while a[i].is_a? Array
    return a.unshift x  if x <= (a=a[i])[0]
    return a << x  if x >= a[-1]
    i = a.bsearch_index {|y| x <= f[y]}
    i -= 1  if x < f[a[i]]
  end
  return a.insert(i+1, x)  if a.size-i < 4
  i > 3 ? a[i] = [a[i],x] : a.unshift(*a.shift(i+1),x)
end
def deq(a)
  return a.shift  if !a[1]
  l,a = a,n  while (n=a[0]).is_a? Array
  if (r=a[1]).is_a? Array; a[0] = deq r; a[1] = r[0] if !r[1]; n
  else (l||[])[0] = r if !a[2]; a.shift end
end
N,M,*A = $<.read.split.map{|x| -x.to_i}
A.sort!
(-M).times { break if A[0]==0; enq A, -(-(deq A)/2) }
p A.flatten.inject(0,:-)

Measured memory_bytes: 17408
def main():
    n, m, c = map(int, input().split())
    b = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        a = list(map(int, input().split()))
        tmp = 0
        for j in range(m):
            tmp += a[j] * b[j]
        tmp += c
        if tmp > 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if A[i] < B[i]:
        cnt += A[i]
        rem = B[i] - A[i]
        if A[i+1] > rem:
            A[i+1] -= rem
            cnt += rem
        else:
            cnt += A[i+1]
            A[i+1] = 0
    else:
        cnt += B[i]
print(cnt)

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

int main() {
  int a, b;
  string p;
  cin >> a >> p >> b;

  if (p == "+") {
    cout << a + b << endl;
  }
  
  else if (p == "-") {
    cout << a - b << endl;
  }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define mod 998244353
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tc(t) int t; cin >> t; while (t--)
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define ps(x,y)   fixed<<setprecision(y)<<x
using namespace std;

struct segtree {

	vector<ll> sums;
	int size;
	void init(int n) {

		size = 1;
		while (size < n)size *= 2;
		sums.assign(2 * size, 0ll);
	}
	void set(int i, int v, int x, int lx, int rx)
	{
		if (rx - lx == 1) {

			sums[x] = v;
			return;
		}
		int m = (lx + rx) / 2;
		if (i < m) {

			set(i, v, 2 * x + 1, lx, m);
		}
		else {
			set(i, v, 2 * x + 2, m, rx);
		}
		sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
	}

	void set(int i, int v) {

		set(i, v, 0, 0, size);
	}

	ll sum(int l, int r, int x, int lx, int rx) {

		if (lx >= r || l >= rx)return 0;
		if (lx >= l && rx <= r )return sums[x];

		int m = (lx + rx) / 2;
		ll s1 = sum(l, r, 2 * x + 1, lx, m);
		ll s2 = sum(l, r, 2 * x + 2, m, rx);

		return (s1 + s2);

	}

	ll sum(int l, int r) {

		return sum(l, r, 0, 0, size);
	}


};

void solve()
{
	int n, k;
	cin >> n >> k;
	segtree st;
	st.init(n + 5);
	vector<pair<int, int>>vec;
	vector<ll>dp(n + 1, 0);
	for (int i = 0; i < k; i++) {

		int l, r;
		cin >> l >> r;
		vec.push_back({l, r});
	}
	st.set(n, 1);
	dp[n] = 1;
	for (int i = n - 1; i >= 1; i--) {

		ll res = 0;
		for (int j = 0; j < (int)vec.size(); j++) {

			int l, r;
			l = vec[j].fi + i;
			r = vec[j].se + i;
			ll temp = st.sum(l, r + 1);
			res += temp;
			res = (res + mod) % mod;
		}
		dp[i] = res;
		st.set(i, res);
	}
	cout << dp[1] << endl;

}
int main()
{
	IOS
	solve();
	return 0;
}

Measured memory_bytes: 9008
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,sum=0,temp=0,ans=INT_MAX;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    for(i=0;i<(n-1);i++){
        temp+=arr[i];
        ans=min(ans,abs((sum-temp)-temp));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int table[10] = {0};
    table[a]++;
    table[b]++;
    table[c]++;
    table[d]++;
    int flg = 0;
    if (table[1] == 0) flg = 1;
    if (table[4] == 0) flg = 1;
    if (table[7] == 0) flg = 1;
    if (table[9] == 0) flg = 1;
    if (flg == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
const ll INF=LLONG_MAX,MOD=1e9+7;
const int L=17,N=1<<L;

ll n,a[101];

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	ll all=1,odd=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==1){
			all*=3;
		}else{
			all*=3;
			odd*=2;
		}
	}
	cout<<all-odd<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int N = 5000;
#define ll unsigned long long
int cmp(int a,int b){
	return a>b;
}	
int gcd(int x, int y)
{
    while(y^=x^=y^=x%=y);
    return x;
}

int gcd(int x,int y,int z){
	return gcd(gcd(x,y),z);
} 
int main(){
	int  n;
	cin >> n;
	string s;
	cin >> s;
	int r[4005],g[4005],b[4005];
	ll x=0,y=0,z=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R') {
			r[x]=i+1;
			x++;
		}else if(s[i]=='G') {
			g[y]=i+1;
			y++;
		}else{
			b[z]=i+1;
			z++;
		}
	}
//	int t=0;
//	for(int i=2;i<n;i++){
//		if(s[i]!=s[i-1] && s[i]!=s[i-2] && s[i-1]!=s[i-2]){
//			cout << i << endl;
//			t++;
//		}
//	
//	}
	
	ll sum=x*y*z;
//	ll sum=0;
//	int m=0;
//	for(int i=0;i<x;i++){
//		for(int j=0;j<y;j++){
//			for(int k=0;k<z;k++){
//				if(r[i]*2 != g[j]+b[k]  &&   g[j]*2 != r[i]+b[k] &&b[k]*2 != g[j]+r[i]){
//					sum++;
//				}else{
//					m++;
//				}
//			}
//		}
//	}

	ll m=0;
	for(int i=1;i<n;i++){
		for(int j=0;j<i;j++){
			int k = 2*i-j;
			if(k<n&&s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k]){
				m++;
				//cout << i <<" "<< j <<" "<< k<<endl;
			}
		}
	} 
	//sum =1333*1333*1334;
	//cout <<  x <<"x---"<< y<<"y---" << z<<"z---"<<endl;
	//cout << sum << "  "<< m<<endl;
	cout << sum - m<<endl;
	return 0;
}
//:922 337 203 685 477 580 7




Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
  #define pb push_back
#define f first
#define s second
  #define MAXN 100005
using namespace std;
int arr[MAXN];
int main()
{
	std::ios::sync_with_stdio(false);
	string s;
	cin>>s;
	ll b=0;
	ll ans=0;
	for(int i=0; i<s.length(); i++) {
		if(s[i]=='B') {
			b++;
		}
		else  {
			ans+=b;
		
		}
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp

	最長増加部分列（LIS: Longest Increasing Subsequence ）
	
	dp[i]:=最後が ai であるような最長の増加部分列の長さ

	最後が ai であるような増加部分列は

	ai のみからなる列
	j < i かつ aj < ai であるような aj で終わる増加部分列の後ろに ai を付け足した列

	dp[i] = max{1, dp[j] + 1 (j < i かつ aj < ai ) }

	計算量：O(N^2)

	もうひとつ。

	dp[i]:=長さがi+1であるような増加部分列における最終要素の最小値(存在しない場合はINF）

	計算量：O(N*log N )

	参考：蟻本 p65
*/
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 100000;
const int INF = (int)1e9 + 1;
int N;
int a[MAX_N+1];
int dp[MAX_N+1];

/*
int solve (void ){
	rep (i, N ) dp[i] = 1;

	rep (i, N ){
		for (int j = 0; j < i; j++ ){
			if (a[j] < a[i] ) dp[i] = max (dp[i], dp[j] + 1 );
		} // end for
	} // end rep

	return dp[N-1];
}
*/

int solve (void ){
	rep (i, N ) dp[i] = INF;

	rep (i, N ) *lower_bound (dp, dp+N, a[i] ) = a[i];

	int res = lower_bound (dp, dp+N, INF ) - dp;

	return res;
}

int main()
{
	memset (a, 0, sizeof (a ) );

	ios_base::sync_with_stdio(0);
	cin >> N;
	rep (i, N ) cin >> a[i];

	int res = solve ();	
	cout << res << endl;
		
	return 0;
}

Measured memory_bytes: 1988
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/ped_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//#define ordered_set ped<ll , null_type, less<ll>, rb_ped_tag, ped_order_statistics_node_update>

typedef long long ll;
vector<ll> adj[100005];
map<pair<ll,ll>,ll> col;
void dfs(ll src,ll prev,ll par)
{
    ll j=1;
    fr(i,0,adj[src].size())
    {
        if(adj[src][i]!=par)
        {
            if(j==prev)
                j++;
            col[{src,adj[src][i]}]=j;
            col[{adj[src][i],src}]=j;
            dfs(adj[src][i],j,src);
            j++;
        }
    }
}

int main()
{
   run;
   ll n;
   cin>>n;
   map<ll,ll> m;
   map<ll,pair<ll,ll> >  op;
   ll ma=0;
   fr(i,1,n)
   {
       ll a,b;
       cin>>a>>b;
       op[i]={a,b};
       adj[a].pb(b);
       adj[b].pb(a);
       m[a]++;
       m[b]++;
       ma=max(ma,m[a]);
       ma=max(ma,m[b]);

   }
   dfs(1,0,-1);
   cout<<ma<<endl;
   fr(i,1,n)
   {
       auto it=op[i];
       cout<<col[it]<<endl;
   }







    return 0;
}


Measured memory_bytes: 31488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        char [] s = sc.next().toCharArray();
        if (s[2]==s[3] && s[4]==s[5]) out.println("Yes");
        else out.println("No");
        out.flush();
        out.close();
    }


    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        boolean ready() throws IOException {
            return br.ready();
        }

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

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

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

        int nextChar() throws IOException {
            return next().charAt(0);
        }

        int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

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

    }
}


Measured memory_bytes: 22996
from sys import stdin
r = stdin.readline

def fact(n):
    ans = 1
    for i in range(1,n+1): ans*=i
    return ans

def main():
    n, m = map(int, r().strip().split())
    print((fact(n)//(2*fact(n-2)))+(fact(m)//(2*fact(m-2))))

main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

bool eqPii(const Pii& p, const Pii& q) {
    return p.first == q.first && p.second == q.second;
}

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

    int M, T, P, R;
    while (cin >> M >> T >> P >> R, M) {
        VV score(T, V(P, 0));
        VV done(T, V(P, 0));
        rep(i, R) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--; p--;
            score[t][p] += (j == 0 ? m : 20);
            if (j == 0) done[t][p] = 1;
        }

        V ac(T);
        rep(t, T) {
            ac[t] = accumulate(all(done[t]), 0);
        }

        V pena(T, 0);
        rep(t, T) {
            rep(p, P) {
                if (done[t][p]) pena[t] += score[t][p];
            }
        }

        vector<pair<Pii, int>> v;
        rep(t, T) {
            v.emplace_back(make_pair(Pii(-ac[t], pena[t]), -(t + 1)));
        }
        sort(all(v));

        rep(i, T) {
            cout << -v[i].second;
            if (i + 1 == T) continue;
            if (i + 1 < T && eqPii(v[i].first, v[i + 1].first)) {
                cout << "=";
            } else {
                cout << ",";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 1000
ll N,V,ans=0;
ll a[MAX_N];
ll b[MAX_N];
ll c[MAX_N];
ll d[MAX_N];
map<ll,ll> t;
 
int main(){
  scanf("%lld %lld",&N,&V);
  for(int i=0;i<N;i++)scanf("%lld",&a[i]);
  for(int i=0;i<N;i++)scanf("%lld",&b[i]);
  for(int i=0;i<N;i++)scanf("%lld",&c[i]);
  for(int i=0;i<N;i++)scanf("%lld",&d[i]);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      t[ a[i]+b[j] ]++;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      ans+=t[V-c[i]-d[j]];
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128208
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	a := []int{}
	for i := 0; i < n; i++ {
		a = append(a, stdin.ReadInt())
	}

	for _, v := range a {
		if v%2 == 0 && !(v%3 == 0 || v%5 == 0) {
			stdout.Println("DENIED")
			return
		}
	}
	stdout.Println("APPROVED")
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}


Measured memory_bytes: 640
#include<stdio.h>
int mothernum, mother[100000];
int binary(int aim)
{
 int Start, End, Center;
   Start  = 0;
   End    = mothernum;

   while(Start < End){
     Center = (End + Start) / 2;
     if(mother[Center] > aim){
       End   = Center;
     } else if(mother[Center] < aim){
       Start = Center + 1;
     } else if(mother[Center] == aim){
       return 1;
     }
   }

 return 0;

}
int main()
{
 int  kidsnum, kids[50000], i, Count=0,flag;
 
 scanf("%d", &mothernum);
 for (i = 0; i < mothernum; i++) {
   scanf("%d", &mother[i]);
 }
  
 scanf("%d", &kidsnum);
 for(i = 0; i < kidsnum; i++) {
   scanf("%d", &kids[i]);
 }

 for(i = 0; i< kidsnum; i++){
   flag = binary(kids[i]);
   if(flag==1){
     Count++;
   }
 }
 
 printf("%d\n",Count);

 return 0;
}

Measured memory_bytes: 2276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 1e9 + 5;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

const int mxs = 3002;
int main()
{
	ll dp[mxs][mxs] = {}, in[mxs] ;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> in[i];
		dp[i][i] = in[i];
	}
	for(int l = n - 1; l >= 0; l--)
		for(int r = l; r < n; r++)
		{
			if(l < r)
			{
				dp[l][r] = max(in[l] - dp[l + 1][r], in[r] - dp[l][r - 1]);
			}
		}
	cout << dp[0][n - 1] << '\n';
}


Measured memory_bytes: 70656
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while(cin>>a>>op>>b&&op!='?'){
        if(op=='+')cout<<a+b<<endl;
        if(op=='-')cout<<a-b<<endl;
        if(op=='*')cout<<a*b<<endl;
        if(op=='/')cout<<a/b<<endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int n, a[MAX];

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);

    int lim[n];
    int wall = -1;
    rep(i, n){
        --wall;
        if(a[i] == 0) wall = mod;
        else if(a[i] < 0) chmin(wall, abs(a[i]) - 1);
        else{
            lim[i] = max(wall, -1);
        }
    }
    wall = -1;
    rrep(i, n){
        --wall;
        if(a[i] == 0) wall = mod;
        else if(a[i] < 0) chmin(wall, abs(a[i]) - 1);
        else{
            lim[i] = max({lim[i], wall, -1});
        }
    }

    int ans = 0;
    rep(i, n)if(a[i] > 0) ans += min(a[i], lim[i] + 1);
    printf("%d\n", ans);
}


Measured memory_bytes: 3984
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

ans=p[:X]+q[:Y]+r
ans.sort(reverse=True)
print(sum(ans[:X+Y]))

Measured memory_bytes: 23328
def input_li():
    return list(map(int, input().split()))


def input_int():
    return int(input())


def prime_factorization(n):
    table = []
    for x in range(2, int(n ** 0.5) + 1):
        while n % x == 0:
            table.append(x)
            n //= x
    if n > 1:
        table.append(n)
    return table


A, B = input_li()
A_SET = set(prime_factorization(A))
B_SET = set(prime_factorization(B))
print(len((A_SET) & set(B_SET)) + 1)


Measured memory_bytes: 63284
from collections import Counter
import numpy as np

A,B = map(int, input().split())
if A != 0:
    A = A-1

def ruiseki_XOR(N):
    if (N+1) % 2 == 0:
        if ((N+1)//2) % 2 == 0:
            return 0
        else:
            return 1
    else:
        if ((N+1)//2) % 2 == 0:
            return N
        else:
            return 1^N


a = ruiseki_XOR(A)
b = ruiseki_XOR(B)

print(a^b)

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

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

Measured memory_bytes: 3632
#include <stdio.h>

void solve(int a, int b, int c, int d, int e, int f, double *x, double *y);

int main(int argc, char* argv[])
{
	int a, b, c, d, e, f;
	while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != -1) {
		double x, y;
		solve(a, b, c, d, e, f, &x, &y);
		printf("%.3lf %.3lf\n", x, y);
	}
	return 0;
}

void solve(int a, int b, int c, int d, int e, int f, double *x, double *y)
{
	int det;
	det = a * e - b * d;
	*x = (double)(e * c - b * f)/(double)det;
	*y = (double)(- d * c + a * f)/(double)det;
	if (*x == 0.0) *x = 0.0;
	if (*y == 0.0) *y = 0.0;
}

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

typedef long long ll;

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

    int N, W;
    cin>>N>>W;

    int w[N], v[N];
    ll dp[N+1][W+1];

    for (int i=0;i<N;++i) cin>>w[i]>>v[i];

    for (int j=0;j<=W;++j) dp[0][j] = 0;
    for (int i=1;i<=N;++i) dp[i][0] = 0;

    for (int i=1;i<=N;++i){
        for (int j=0;j<=W;++j){
            
            dp[i][j] = dp[i-1][j];
            if (w[i-1]<=j) 
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
        }
    }
    ll ans = 0;
    cout<<dp[N][W]<<endl;
    
    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll v[200000+5];
  memset(v,0,sizeof(v));
  for(int i=1;i<=n;i++){
    cin>>v[i];
  }
  ll ocu[200000+5];
  memset(ocu,0,sizeof(ocu));
  for(int i=1;i<=n;i++){
    ocu[v[i]]++;
  }
  ll ans=0;
  for(int i=1;i<=n;i++){
    ans+=ocu[i]*(ocu[i]-1)/2;
  }
  for(int i=1;i<=n;i++){
    cout<<ans-(ocu[v[i]]-1)<<endl;
  }
  return 0;
}


Measured memory_bytes: 5760
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,n,s) for(int i=s;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  ll l,r;
  cin >> l >> r;
  r = min(r, l+2019);
  int ans = 2018;
  for(ll i = l; i <= r; i++) {
    for(ll j = i+1; j <= r; j++) {
      int x = i*j%2019;
      if(x == 0) {
        cout << 0 << endl;
        return 0;
      }
      ans = min(ans, x);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Map.Entry;
import java.util.*;
import java.math.*;
import org.w3c.dom.css.Counter;


public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		long k= Long.parseLong(sc.next());
		
		int[] aList=new int[n];
		long[] position=new long[n];
		
		for(int i=0;i<n;i++){
			aList[i]=sc.nextInt();
		}
		
        ArrayList<Integer> list=new ArrayList<>();
        //開始町番号
        int listNum=1;
        //移動回数
        long steps=1;
        //最初の移動が終わったところから開始！
        list.add(1);
        //位置設定：初期町
		position[0]=1;
		while(true){
            //K に到着したらやめ
            if(steps==k){
                System.out.println(aList[listNum-1]);
                break;
            }
            //ワープ先確認
			if(position[listNum-1]>1){
                //ワープ先が来訪済み
                //最後に来訪した日を取得
                long prev=position[listNum-1];
                //サイクルmod取得
                int cycleMod=(int)((k-prev+1)%(steps-prev));
				int ans=list.get((int)(prev+cycleMod-1));
				System.out.println(ans);
				break;
			}
			else {
                //来た日を記録
                position[listNum-1]=steps;
                //最新航路取得
                listNum=aList[listNum-1];
                //航路情報追加
				list.add(listNum);
				//一回移動
                steps++;
			}
		}
	}
}

Measured memory_bytes: 61616
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    constexpr int A_MAX = 1000000;
    vector<int> min_factor(A_MAX + 1);
    vector<int> q(A_MAX + 1, 1);
    vector<int> primes;
    for (int i = 2; i <= A_MAX; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
            primes.push_back(i);
        }
        int min_factor_i = min_factor[i];
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor_i) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    int N = 0;
    char c = getchar_unlocked();
    do {
        N = 10 * N + c - '0';
    } while ((c = getchar_unlocked()) >= '0');
    vector<int> a(A_MAX + 1);
    for (int i = 0; i < N; ++i) {
        int A = 0;
        c = getchar_unlocked();
        do {
            A = 10 * A + c - '0';
    	} while ((c = getchar_unlocked()) >= '0');
        ++a[A];
    }
 
    bool is_pairwise_coprime = true;
    for (int n = A_MAX; n > 1; --n) {
        int a_n = a[n];
        if (a_n) {
            if (a_n > 1) {
                if (a_n == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = false;
            }
            a[min_factor[n]] += a_n;
            a[q[n]] += a_n;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

Measured memory_bytes: 15488
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    vin a(n);rep(i,n)cin>>a[i];
    int sum=0;
    int ans=inf;
    rep2(i,-100,101){
        sum=0;
        rep(j,n)sum+=(a[j]-i)*(a[j]-i);
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define mod 100000007
#define INF 1e9
/****************************/
int n;
map<int,int> m_p;
int main()
{
	int ans=0;
	cin>>n;
	rep(i,n)
	{
		int a;
		cin>>a;
		m_p[a]++;
	}
	for(map<int,int>::iterator iter=m_p.begin();iter!=m_p.end();iter++)
	{
		int x=iter->st,y=iter->nd;
		if(y<x) ans+=y;else ans+=y-x;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>

inline void fastin(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar_unlocked();
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}

inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}

int main(){
    int n, c, k; fastin(n); fastin(c); fastin(k);
    int t[n];
    for (int i = 0; i < n; ++i) fastin(t[i]);

    std::sort(t, t + n);

    int ans = 0;
    int beg = 0;
    while (beg < n){
        int end = beg;
        while (end - beg + 1 < c && t[end + 1] - t[beg] <= k){
            ++end;
            if (end == n - 1) break;
        }
        ++ans; beg = end + 1;
    }
    fastout(ans);
    
    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <math.h>
#include <numeric>
#include <sstream>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
  int n, k, r;
  string s;

  cin >> n >> s >> k;

  r = s[k - 1];

  for (int i = 0; i < n; i++) {
    if(s[i]!=r)
		s[i]='*';
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 3e5+10;
const int inf = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const ll INF = 1000000000000000010LL;
#define X first
#define Y second

string a[maxN];
int main() {
	int n;
	scanf("%d",&n);
	unordered_map<string,int> mp;
	int flag = 0;
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		string x;
		int t;
		cin>>x;
		scanf("%d",&t);
		mp[x] = t;
		a[i] = x;
	}
	string p;
	cin>>p;
	for(int i=1;i<=n;i++)
	{
		if(flag == 1)
			ans += mp[a[i]];
		if(a[i] == p && flag == 0)
		{
			flag = 1;
		}
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include  <stdio.h>

int main()
{
	int A[5][4][11];
	int b,f,r,v;
	int k,i,j,l;
	for(k=0;k<5;k++)
	{
		for(i=0;i<4;i++)
		{
			for(j=0;j<11;j++)
			A[k][i][j]=0;
		}
	}
	scanf("%d",&l);
	for(i = 0;i < l; i++)
	{
		scanf("%d%d%d%d",&b,&f,&r,&v);
		A[b][f][r] +=v;
	}
	for(k=1;k<=4;k++)
	{
		for(i=1;i<=3;i++)
		{
			for(j=1;j<=10;j++)
			{
				printf(" %d",A[k][i][j]);
			}
			printf("\n");
		}
		if(k != 4)
		{
			printf("####################\n");
		}
	}
		return 0;
}

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

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

    static class A {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni(), m = in.ni();
            String s = in.ns(), t = in.ns();
            long gcd = IntegerUtils.gcd(n, m);
            long lcm = (long) n / gcd * m;
            boolean valid = true;
            for (int i = 0; i < gcd; i++) {
                if (s.charAt((int) (n / gcd * i)) != t.charAt((int) (m / gcd * i))) {
                    valid = false;
                    break;
                }
            }
            if (!valid)
                out.println(-1);
            else
                out.println(lcm);
        }

    }

    static class IntegerUtils {
        public static long gcd(long a, long b) {
            while (b != 0) {
                long t = b;
                b = a % b;
                a = t;
            }
            return a;
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



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

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

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

    int q;cin>>q;
    vector<int> t(q);
    rep(i,q)cin>>t[i];

    int cnt=0;
    bool flag=false;

    rep(i,q){
        rep(j,n){
            if(flag)continue;
            if(t[i]==s[j]){
                cnt++;
                flag=true;
            }
        }
        flag=false;
    }
    cout<<cnt<<endl;
 	return 0;
}


Measured memory_bytes: 3128
require "set"

table = {
  "S" => Set::new,
  "H" => Set::new,
  "C" => Set::new,
  "D" => Set::new
}

gets.to_i.times do
  suit, num = gets.split(" ")
  num = num.to_i
  table[suit] << num
end

%w(S H C D).each do |suit|
  1.upto(13) do |n|
    puts "#{suit} #{n}" unless table[suit].include?(n)
  end
end

Measured memory_bytes: 8876