akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 998244353  
#define M 998244353  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  

long long qpow(long long a, long long n) {
    long long ret = 1;
    a = (a % M + M) % M;
    for (; n; n >>= 1) {
        if (n & 1) ret = (ret * a) % M;
        a = (a * a) % M;
    }
    return ret;
}

int n;
vector<string> vs, l, r;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        vs.push_back(s);
    }
    priority_queue<pii> va, vb;
    ll nsum = 0;
    for (auto &s : vs) {
        pii a(0,0);
        for (int i = 0; i < s.size(); ++i) {
            a.fi += s[i] == '(' ? 1:-1;
            a.se = min(a.se, a.fi);
        }
        if (a.se >= 0) nsum += a.fi; 
        else if (a.fi >= 0) va.push((pii){a.se, a.fi});
        else vb.push((pii){a.fi-a.se, -a.se});
    }
    while (!va.empty()) {
        pii p = va.top(); va.pop();
        if (nsum + p.fi <= 0) {cout << "No" << endl; return 0;}
        nsum += p.se;
    }
    while (!vb.empty()) {
        pii p = vb.top(); vb.pop();
        if (nsum - p.se < 0) {cout << "No" << endl; return 0;}
        nsum += p.fi - p.se;
    }
    if (nsum == 0) cout << "Yes"  << endl;
    else cout << "No"  << endl;
    return 0;
}


Measured memory_bytes: 42596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<P> v[3334];

ll gcd(ll a, ll b){
	return ((b)?gcd(b,a%b):a);
}

bool comp(P a, P b){
	return ((a.first==b.first)?(a.second<b.second):(a.first<b.first));
}

int main(void){
	int n,k,i,j,c;
	ll x[3334],y[3334],p,q,r;
	bool flag = false;
	cin >> n >> k; --k;
	for(i=0; i<n; ++i){
		cin >> x[i] >> y[i];
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			p = x[j]-x[i];
			q = y[j]-y[i];
			if(p<0){
				p = -p;
				q = -q;
			}
			r = gcd(abs(p),abs(q));
			p /= r;
			q /= r;
			v[i].push_back(P(p,q));
		}
		sort(v[i].begin(),v[i].end(),comp);
		for(j=1; j<n; ++j){
			c = (int)(upper_bound(v[i].begin(),v[i].end(),v[i][j-1],comp)-lower_bound(v[i].begin(),v[i].end(),v[i][j-1],comp));
			if(c >= k){
				flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	}
	cout << (flag?1:0) << endl;
	return 0;
}



Measured memory_bytes: 155636
H, W, A, B = map(int, input().split())
ans = [0]*H
for i in range(H):
  if i < B:
    ans[i] = "0"*A + "1"*(W-A)
  else:
    ans[i] = "1"*A + "0"*(W-A)
print(*ans, sep="\n")

Measured memory_bytes: 4980
n = gets.strip.to_i
a = gets.split.map(&:to_i)
puts a.join(" ")

for i in 1..(n - 1)
    v = a[i]
    j = i -1
    while j >= 0 && a[j] >v
    a[j+1] = a[j]
    j -= 1
    end
    a[j+1] = v
    puts a.join(" ")
end

Measured memory_bytes: 8812
// abc175_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    int ans = 0;
    int tmp = 0;
    REP(i, 3){
        if (S[i] == 'R'){
            tmp++;
        } else {
            ans = max(tmp, ans);
            tmp = 0;
        }
    }
    ans = max(tmp, ans);

    print(ans);

    return 0;
}


Measured memory_bytes: 3616
odd_easy = ['R', 'U', 'D']
even_easy = ['L', 'U', 'D', nil]

S = gets.chomp.split('')

odd = S.each_slice(2).map { |s| s.first }
even = S.each_slice(2).map { |s| s.last if s.size >= 2 }

odd = odd.reject { |s| odd_easy.include?(s) }
even = even.reject { |s| even_easy.include?(s) }

if odd.empty? && even.empty?; puts 'Yes';
else; puts 'No'; end;

Measured memory_bytes: 1788
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	int n, a[100000], next = 0, count = 0;
	bool isturned[100000] = {}, ispossible;
	scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]);

	while (true) {
		if (a[next] == 2) {
			ispossible = true;
			break;
		}
		else if (isturned[next]) {
			ispossible = false;
			break;
		}
		else {
			isturned[next] = true;
			next = a[next] - 1;
			++count;
		}
	}

	if (ispossible) {
		printf("%d\n", count + 1);
	}
	else {
		printf("-1\n");
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t a, b, k;
    cin >> a >> b >> k;

    a -= k;
    if (a < 0) {
        b -= -a;
        a = 0;
        if (b < 0) {
            b = 0;
        }
    }

    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
//Monday-Saturday Prime Factors
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
vector<ll> prime;

int main(){
  prime.push_back(6);
  ll p=8;
  while(p<=300000){
    bool flag=true;
    for(ll i=0; i<prime.size() && p>=prime[i]*prime[i]; i++){
      if(p%prime[i]==0){flag=false; break;}
    }
    if(flag)prime.push_back(p);
    if(p%7==1)p+=5;
    else p+=2;
  }

  ll x;
  while(cin>>x, x!=1){
    cout<<x<<":";
    for(ll i=0; i<prime.size(); i++){
      if(x%prime[i]==0)
	cout<<" "<<prime[i];
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;

const int N = 100010;



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + s[1] - '0';
    int b = (s[2] - '0') * 10 + s[3] - '0';
    if (a <= 12 && a > 0) {
        if (b <= 12 && b > 0) {
            cout << "AMBIGUOUS\n";
        } else {
            cout << "MMYY\n";
        }
    } else {
        if (b <= 12 && b > 0) {
            cout << "YYMM\n";
        } else {
            cout << "NA\n";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  string S;
  cin >> N >> S;

  ll l = 0;
  ll r = count_if(S.begin(), S.end(), [](const auto& s) {
    return s == 'E';
  });

  ll ans = kMod * 10;
  REP(i, 0, N) {
    if (S[i] == 'E') {
      r--;
    }
    ans = min(ans, l + r);
    if (S[i] == 'W') {
      l++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       map <ll,ll> mp;
       ll i,j,k,n;
       for(i=1;i<=100;i++)
        for(j=1;j<=100;j++)
         for(k=1;k<=100;k++)
          mp[i*i+j*j+k*k+i*j+i*k+j*k]++;
       cin>>n;   
       for(i=1;i<=n;i++)
        cout<<mp[i]<<"\n";
   }
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N+1);
  for (int i = 1; i <= N; i++) cin >> A.at(i);
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (i == A.at(A.at(i))) cnt++;
  }
  cout << cnt / 2 << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if(C >= A && C <= B){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std;

int minJumpsCost(vector<int>& input)
{
	vector<int> dp(input.size(), 0);
	dp[0] = 0;
	dp[1] = abs(input[0] - input[1]);
	for (int i = 2; i < int(dp.size()); ++i)
	{
		dp[i] = min(abs(input[i] - input[i - 1]) + dp[i - 1], abs(input[i] - input[i - 2]) + dp[i - 2]);
	}
	return dp[input.size() - 1];
}

int main()
{
	int N;
	cin >> N;
    vector<int> input;
		while (int(input.size()) < N)
		{
			int num;
			cin >> num;
			input.push_back(num);

		}
	if (N == 1)
	{
		cout << 0;
	}
	else {
		cout << minJumpsCost(input);
	}
	return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <numeric>
#include <vector>
#define STL_Container typename

using data_t = std::vector<unsigned>;

template <STL_Container T>
typename T::value_type sum(T c){
	return std::accumulate(c.cbegin(),c.cend(),typename T::value_type());
}

bool core(const unsigned target, const unsigned sum, const std::size_t top, const data_t& vals){
	if(sum == target) return true;
	if(sum > target) return false;
	for(unsigned i=top; i<vals.size(); ++i){
		if(core(target,sum+vals[i],i+1,vals)) return true;
	}
	return false;
}

bool solve(const unsigned target, const data_t& vals){
	if(sum(vals) < target) return false;
	for(unsigned i=0; i<vals.size(); ++i){
		if(core(target,0,i,vals)) return true;
	}
	return false;
}

int main(){

	unsigned n;
	std::cin >> n;

	data_t vec(n);

	for(auto& v : vec){
		std::cin >> v;
	}

	unsigned n2;
	std::cin >> n2;

	for(unsigned i=0;i<n2;++i){
		unsigned buf;
		std::cin >> buf;
		std::cout << (solve(buf,vec) ? "yes":"no") << std::endl;
	}

}

Measured memory_bytes: 3132
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[10100];
int ren[10100];
int main(){
	int a,b;
	scanf("%d%d%s",&a,&b,in);
	if(b>=14){
		std::sort(in,in+a);
		for(int i=0;i<a;i++)printf("%c",in[0]);printf("\n");
		return 0;
	}
	string now=in;
	for(int i=0;i<a;i++)in[a+i]=in[a-1-i];
	for(int i=a*2-1;i>=0;i--){
		if(i==a*2-1||in[i]!=in[i+1])ren[i]=1;
		else ren[i]=ren[i+1]+1;
	}
	char bc='z';
	int br=0;
	string S=in;
	for(int i=0;i<=a;i++){
		if(bc>in[i]||(bc==in[i]&&ren[i]>br)){
			bc=in[i];br=ren[i];
		}
	}
	for(int i=0;i<=a;i++){
		if(bc==in[i]&&ren[i]==br){
			now=min(now,S.substr(i,a));
		}
	}
	long long ad=0;
	for(int i=1;i<b;i++){
		ad+=br;
		br*=2;
	}
	for(int i=0;i<a;i++){
		if(i<ad)printf("%c",bc);
		else printf("%c",now[i-ad]);
	}
	printf("\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
//int	2,147,483,647
//1億    10^8 この辺が限界
//bit 演算

int main(){
    std::string str;
    std::cin >> str;

    vector<int> array(4);

    for(int i=0;i<str.size();i++)
    {
        array[i] = static_cast<int>(str[i]) - '0';
    }

    int bitUpper= 1 << 3;

    const int flag_0 = 1<<0;
    const int flag_1 = 1<<1;
    const int flag_2 = 1<<2;

    for(int i=0;i<bitUpper;i++)
    {
        int sum=array[0];
        sum += (i & flag_0) ? array[1] : (-1)*array[1]; 
        sum += (i & flag_1) ? array[2] : (-1)*array[2]; 
        sum += (i & flag_2) ? array[3] : (-1)*array[3]; 

        if(sum == 7)
        {
            cout << array[0];
            if(i & flag_0){
                cout << "+";
            }else{
                cout << "-";
            }
            cout << array[1];
            if(i & flag_1){
                cout << "+";
            }else{
                cout << "-";
            }
            cout << array[2];
            if(i & flag_2){
                cout << "+";
            }else{
                cout << "-";
            }
            cout << array[3] << "=7";
            break;
        }
    }

    return 0;
}




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

class edge{
public:
	int u, v ;
	edge(){
	}
	edge(int u, int v){
		this->u = u ;
		this->v = v ;
	}
} ;

class cmp{
public:
	bool operator () (const edge &e1, const edge &e2){
		return (min(e1.u, e1.v) < min(e2.u, e2.v)) ;
	}
} ;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n ;

	vector<int> ar(n) ;
	for(auto &i : ar)
		cin >> i ;
	sort(ar.begin(), ar.end()) ;

	priority_queue<edge, vector<edge>, cmp> pq ;

	LL ans = 0LL ;
	pq.push( edge(ar.back(), ar.back()) ) ;
	ar.pop_back() ;

	while(!ar.empty()){
		int u = pq.top().u ;
		int v = pq.top().v ;
		pq.pop() ;

		ans += min(u, v) ;

		pq.push( edge(u, ar.back()) ) ;
		pq.push( edge(ar.back(), v) ) ;
		ar.pop_back() ;
	}

	cout << ans << endl ;

	return 0;
}

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


int main(){
  int n,m,c;
  cin >> n >> m >> c;
  int ans=0;
  vector<int>b(m);
  rep(i,m) cin >> b[i];
  rep(i,n){
      int sum=0;
      rep(j,m){
        int a;
        cin >>a;
        sum+=a*b[j];
      }
      if(sum+c>0) ans++;
     }
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define INF 1000000

int main()
{
    int n, max_time;
    scanf("%d%d", &n, &max_time);

    int min_cost = INF;
    for (int i = 0; i < n; i += 1) {
        int cost, time;
        scanf("%d%d", &cost, &time);
        if (time <= max_time && cost < min_cost) {
            min_cost = cost;
        }
    }

    if (min_cost < INF) {
        printf("%d\n", min_cost);
    } else {
        printf("TLE\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, c;
	cin >> n >> c;
	int grid[n][n];
	int d[c][c];
	rep(i,c)rep(j,c){
		cin >> d[i][j];
	}
	rep(i,n)rep(j,n){
		cin >> grid[i][j];
		grid[i][j]--;
	}
	int color[3][c];
	rep(i,3)rep(j,c) color[i][j]=0;
	rep(i,n)rep(j,n){
		color[(i+j)%3][grid[i][j]]++;
	}
	ll ans = INF;
	vector<vector<pair<ll,int>>> v(3); 
	rep(i,3){
		rep(j,c){
			ll now = 0;
			rep(k,c){
				now += color[i][k]*d[k][j];
			}
			pair<ll, int> e = make_pair(now, j);
			v[i].push_back(e);
		}
	}
	rep(i,3) sort(v[i].begin(), v[i].end());
	rep(i,3)rep(j,3)rep(k,3){
		if(v[0][i].second==v[1][j].second||v[1][j].second==v[2][k].second||v[2][k].second==v[0][i].second) continue;
		chmin(ans, v[0][i].first+v[1][j].first+v[2][k].first);
	}
	cout << ans << endl;

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int ans = -1;
    for (int pivot = 1; pivot < n; pivot++)
    {
        vector<char> left;
        vector<char> right;
        for (int l = 0; l < pivot; l++)
        {
            left.push_back(s[l]);
        }
        for (int r = pivot; r < n; r++)
        {
            right.push_back(s[r]);
        }
        sort(left.begin(), left.end());
        sort(right.begin(), right.end());
        left.erase(unique(left.begin(), left.end()), left.end());
        right.erase(unique(right.begin(), right.end()), right.end());

        vector<char> tmp;
        set_intersection(left.begin(), left.end(), right.begin(), right.end(), back_inserter(tmp));
        ans = max(ans, int(tmp.size()));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:print("Yes");exit()
if s[0] == s[2] and s[1] == s[3] and s[0] != s[3]:print("Yes");exit()
if s[0] == s[3] and s[1] == s[2] and s[0] != s[2]:print("Yes");exit()
print("No")


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int main( void )
{
	int n;
	int i;
	int *val;
	int min;
	int max;
	long sum = 0;

	scanf( "%d", &n );

	val = (int*)malloc( sizeof(int) * n );
	if( val == NULL ){
		exit( 1 );
	}

	for( i = 0; i < n; i++ ){
		scanf("%d", val + i);
		sum += val[ i ];
	}

	min = val[ 0 ];
	max = val[ 0 ];

	for( i = 0; i < n; i++ ){
		if( val[ i ] < min ){
			min = val[ i ];
		}
		if( max < val[ i ] ){
			max = val[ i ];
		}
	}

	printf("%d %d %ld\n", min, max, sum);

	free( val );

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  ll sum = 0;

  for (int i = 0;i<n;i++) cin >> d[i];

  for (int i = 0;i < n - 1;i++) {
    for (int j = i;j < n-1;j++) {
      sum += d[i] * d[j + 1];
    }
  }

  cout << sum;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC046D{
    public class Program{
        public static void Main(string[] args){
            var cs = "gp";
            var S = Console.ReadLine().Select((c, i) => i % 2 - cs.IndexOf(c)).ToArray();
            Console.WriteLine(S.Sum());
        }
    }
}

Measured memory_bytes: 4696
#include <iostream>
#include <cmath>

using namespace std;

int const NMAX = 1e5;
int const INF = 2e9;

int nStones;
int dp[NMAX+1][3];
int h[1+NMAX]; //this is an indication that your array is starting from index 1

int costOfHop(int from, int to) {
  return abs(h[from]-h[to]);
}

int main() {
  cin >> nStones;
  for(int i=1; i<=nStones; i++) {
    cin >> h[i];  //stones are 1..nStones
  }

  /*
    dp[i][j] = minimum cost of getting to ith stone, where last hop had length j
  */
  //Bottom-up: we process the most complex solved (we know is optimal) subproblem.
  //Top-down:  we solve the least complex subproblem for which we have prerequisites.
  dp[1][1] = 0; //the initial case is an abstract case
  dp[1][2] = 0;
  dp[2][1] = min(dp[1][1], dp[1][2]) + costOfHop(1, 2);
  dp[2][2] = INF; 
  for(int i=3; i<=nStones; i++) { //you start from an UNSOLVED problem in top-down
    dp[i][1] = min(dp[i-1][1], dp[i-1][2]) +  costOfHop(i-1, i);
    dp[i][2] = min(dp[i-2][1], dp[i-2][2]) +  costOfHop(i-2, i);
  }
  cout << min(dp[nStones][1], dp[nStones][2]);
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main {
    static int[] par; // 親の番号
    static int[] ws;  // 親との重みの差
    
    public static void WeightedUnionFind(int n){
        par = new int[n];
        ws  = new int[n];
        for(int i = 0; i < n; i++){ par[i] = -1; }
    }
    
    public static int find(int x){
        if(par[x] < 0){
            return x;
        }else{
            final int parent = find(par[x]);
            ws[x] += ws[par[x]];
            return par[x] = parent;
        }
    }
    
    public static int weight(int x){
        find(x); 
        return ws[x];
    }
    
    public static boolean union(int x, int y, int w){ // x <-(w)- y (x + w = y)
        w += weight(x); 
        w -= weight(y);
        x = find(x); y = find(y);
        
        if(x != y){
            if(par[y] < par[x]) {  // 多い方が根になるようにスワップする.
                int tmp = x; x = y; y = tmp; w = -w;
            }
            par[x] += par[y]; par[y] = x;
            ws[y] = w;
            return true;
        }else{
            return false;
        }
    }
    
    public static boolean same(int x, int y){
        return find(x) == find(y);
    }
    
    public static Integer diff(int x, int y){ // x - y を求める. 比較不能ならnull.
        if(!same(x, y)){ return null; }
        return weight(x) - weight(y);
    }
    // size()はUnionFindと同じなので省略.

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        WeightedUnionFind(n);

        int flag = 0;
        for (int i=0;i<q;i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            int z = sc.nextInt();
            // System.out.println("z: " + z + " diff(y, x): " + diff(y, x));
            if (diff(y, x)!=null) {
                // System.out.println(z);
                if (diff(y, x)!=z) {
                    flag=1;
                }
            }
            union(x, y, z);
            // System.out.println(union(x, y, z));
            // if (!union(x, y, z)) {
                // flag=1;
            // }
        }
        if (flag==0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

using namespace std;

const int INF = 1e9 + 19;
const int maxSize = 1e5 + 17;


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

    long long k, a, b;
    cin >> k >> a >> b;

    if(b <= a || a - 1 + 2 > k)
        cout << k + 1 << '\n';
    else
    {
        long long answer = b;
        k -= (a - 1 + 2);

        if(k & 1)
        {
            answer += (k / 2) * (b - a);
            ++answer;
        }
        else
        {
            answer += (k / 2) * (b - a);
        }

        cout << max(answer, k + (a - 1 + 2) + 1) << '\n';

    }
}






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

int n,m,R;
vector<int> r(9);
vector<vector<ll>> graph(201, vector<ll>(201,INT_MAX));
int a,b; ll c;
vector<bool> isUsed(8, false);
ll ans;

void dfs(int depth, int from, ll dist){
    if(depth == R){ // 順列を一つ生成終了
        ans = min(ans, dist);
        return ;
    }
    rep(i,R){
        if(!isUsed[i]){
            isUsed[i] = true;
            if(from == -1) dfs(depth+1,i,0); // 最初だけ例外
            else dfs(depth+1, i, dist + graph[r[from]][r[i]]);
            isUsed[i] = false;
        }
    }
}

int main(){
    cin >> n >> m >> R;
    rep(i,R){
        cin >> r[i];
        r[i]--;
    }
    ans = INT_MAX;
    rep(i,m){
        cin >> a >> b >> c;
        --a; --b;
        graph[a][b] = graph[b][a] = c; 
    }
    // warshal-floyd
    rep(i,n) graph[i][i] = 0;
    rep(i,n) rep(j,n) rep(k,n) graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
    
    dfs(0,-1,0);
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<int> a;
    int sum=0;
    a.push_back(0);
    for(int i=1;i<N;++i){
        if(s[i-1]=='A'&&s[i]=='C'){
            sum++;
        }
        a.push_back(sum);
        
    }
    for(int i=0;i<Q;++i){
        int l,r;
        cin >> l >> r;
        l--;
        r--;
        cout << a[r]-a[l] <<endl;
    }
    return 0;
    
}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 3e3 + 5, inf = 1e18, mod = 1e9 + 7;

int n, a[N], dp[N][N];

int go(int L, int R){
    if(L > R)
        return 0;

    int &ans = dp[L][R];
    if(~ans)
        return ans;
    
    int c1 = a[L] - go(L + 1, R);
    int c2 = a[R] - go(L, R - 1);

    return ans = max(c1, c2);
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  

    memset(dp, -1, sizeof(dp));
    cin >> n;   
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    cout << go(1, n);
}

Measured memory_bytes: 70912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <cstdio>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10
const int MAX_N =10000000;


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

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

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll func(ll a,ll b,ll& ans_x,ll& ans_y){
    if(b == 0){
        ans_x = 1;
        ans_y = 0;
        return a;
    }else{
        ll ret = func(b,(a%b),ans_y,ans_x);
        ans_y -= (a/b)*ans_x;
        return ret;
    }
}

ll par[MAX_N],ranking[MAX_N];

void init(ll n){
    rep(i,n){
        par[i]=i;
        ranking[i]=0;
    }
}

ll find(ll x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}

void unite(ll x,ll y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    
    if(ranking[x]<ranking[y]) par[x]=y;
    else{
        par[y]=x;
        if(ranking[x]==ranking[y]) ranking[x]++;
    }
}

bool same(ll x,ll y){
    return find(x)==find(y);
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<1000-n%1000<<endl;
    return 0;
}


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

hito = [list(map(int, input().split())) for i in range(n)]
point = [list(map(int, input().split())) for j in range(m)]

for k in range(n):
    min_ten = abs(point[0][0]-hito[k][0])+abs(point[0][1]-hito[k][1])
    min_num = 1
    for p in range(1, m):
        kyori = abs(point[p][0]-hito[k][0])+abs(point[p][1]-hito[k][1])
        if kyori < min_ten:
            min_ten = kyori
            min_num = p+1
    print(min_num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second

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

    int n;cin>>n;

    bool allzero=true;

    map<int,int> m;
    for(int i=0;i<n;i++)
    {
        int a;cin>>a;
        m[a]++;
        if(a!=0)allzero=false;
    }

    if(allzero){puts("Yes");return 0;}

    bool ans=false;
    if(n%3==0)
    {
        if(m.size()==3)
        {
            pair<int,int> p[3];
            int pos=0;
            for(auto mm:m){p[pos]=mm;pos++;}
            if(p[0].se==p[1].se&&p[1].se==p[2].se)
            {
                int a=p[0].fi,b=p[1].fi,c=p[2].fi;
                int xo=a^b^c;
                ans=xo==0;
            }
        }
        else if(m.size()==2)
        {
            pair<int,int> p[2];
            int pos=0;
            for(auto mm:m){p[pos]=mm;pos++;}
            ans=(p[0].se==p[1].se*2&&p[1].fi==0)||(p[1].se==p[0].se*2&&p[0].fi==0);
        }
    }

    puts(ans?"Yes":"No");

    return 0;
}


Measured memory_bytes: 7164
A,B = list(map(int,input().split()))
N={1:300000,2:200000,3:100000}
if A ==1 and B==1:
    print(1000000)
else:
    try:
        A=N[A]
    except KeyError:
        A=0
    try:
        B=N[B]
    except KeyError:
        B=0
    print(A+B)

Measured memory_bytes: 3060
using System;
using System.IO;

class Solver
{
    public static void Main()
    {
        var scn = new Scanner(Console.In);
        var n = scn.NextInt();
        var q = scn.NextInt();
        var uf = new UnionFind(n);
        for (int i = 0; i < q; i++)
        {
            var p = scn.NextInt();
            var a = scn.NextInt();
            var b = scn.NextInt();
            if (p == 0)
            {
                uf.Union(a, b);
            }
            else
            {
                Console.WriteLine(uf.Same(a, b) ? 1 : 0);
            }
        }
    }
}


class UnionFind
{
    int[] parents;
    int[] sizes;
    public UnionFind(int n)
    {
        parents = new int[n];
        sizes = new int[n];
        for (int  i = 0; i < n; i++)
        {
            parents[i] = i;
            sizes[i] = 1;
        }
    }
    public void Union(int a, int b)
    {
        int pa = GetParent(a);
        int pb = GetParent(b);
        if (pa == pb)
        {
            return;
        }
        if (sizes[pa] < sizes[pb])
        {
            pa ^= pb; pb ^= pa; pa ^= pb;
        }
        sizes[pa] +=  sizes[pb];
        parents[pb] = pa;
    }
    public bool Same(int a, int b)
    {
        return GetParent(a) == GetParent(b);
    }
    public int GetSize(int a)
    {
        return sizes[GetParent(a)];
    }
    public int GetParent(int a)
    {
        int p = parents[a];
        while (p != parents[p])
        {
            p = parents[p];
        }
        parents[a] = p;
        return p;
    }
}


class Scanner
{
    int index = 0;
    string[] tokens = new string[0];
    TextReader src = null;
    public Scanner(TextReader src)
    {
        this.src = new StringReader(src.ReadToEnd());
    }
    public string Next()
    {
        for (;;) {
            while (index < tokens.Length && tokens[index].Length == 0)
            {
                index++;
            }
            if (index < tokens.Length) {
                return tokens[index++];
            }
            while (index >= tokens.Length)
            {
                var line = src.ReadLine();
                if (line == null) {
                    return null;
                }
                tokens = line.Split(' ');
                index = 0;
            }
        }
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
}



Measured memory_bytes: 24280
import java.util.*;
 
public class Main {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
    
    String input = scanner.nextLine();
    
    if ((input.equals("hi")) || (input.equals("hihi"))|| (input.equals("hihihi"))|| (input.equals("hihihihi"))|| (input.equals("hihihihihi"))){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    //System.out.println(input);
    //scanner.close();
  }
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>

template <class T> void chmin(T&a,T&b) { a = min(a,b); }
template <class T> void chmax(T&a,T&b) { a = max(a,b); }

void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int H,W;
	string S;
	cin>>H>>W;
	REP(i,H){
		cin>>S;
		print(S);
		print(S);
	}
}



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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h, w;
  cin >> h >> w;
  string c[h];
  rep(i, h) cin >> c[i];
  rep(i, 2*h) {
    cout << c[i/2] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <sstream> //string stream its useful!
#include<string>
#include<iostream>
#include<utility> //pair
#include <vector> // vector
#include <algorithm>    // swap,sort,binary_search
#include <functional>   // std::greater
#include <map> //map
#include<set> //set
#include<queue> //queue
#include<list> //list
#include<cmath>
#include<numeric>
#include<cassert>
#include <iomanip> //cout<<setprecision
#include <regex>

typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
ll W = 1000000007;

using namespace std;
void omajinai() {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(15);
    //freopen("txt.csv","r",stdin);
}

class Main{
public:
    string S;
    
    Main(){
        cin>>S;
    }
    
    void run(){
        cout<<(regex_match(S,basic_regex<char>("(dream(er)?|erase(r)?)*"))?"YES":"NO")<<endl;
    }
};

int main(){
    omajinai();
    Main().run();
}


Measured memory_bytes: 42704
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {
	public static void main(String[] args) throws FileNotFoundException {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).run();
	}

	int N, M;
	int[] A, B;
	int[] col;
	int[][] cnt;
	ArrayList<Integer>[] g;

	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		A = new int[M];
		B = new int[M];
		col = new int[N];
		g = new ArrayList[N];
		boolean[][] connect = new boolean[N][N];
		cnt = new int[N][2];
		for (int i = 0; i < N; ++i)
			g[i] = new ArrayList<>();
		Arrays.fill(col, -1);
		for (int i = 0; i < M; ++i) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			--A[i];
			--B[i];
			connect[A[i]][B[i]] = true;
			connect[B[i]][A[i]] = true;
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i != j && !connect[i][j]) {
					g[i].add(j);
				}
			}
		}
		for (int i = 0; i < N; ++i) {
			if (col[i] == -1) {
				col[i] = 0;
				dfs(i, -1);
				++p;
			}
		}
		if (!flag) {
			System.out.println(-1);
			return;
		}
		boolean[][] ok = new boolean[1000][1000];
		ok[0][0] = true;
		for (int i = 0; i + 1 <= N; ++i) {
			for (int j = 0; j < 1000; ++j) {
				if (ok[i][j]) {
					if (ok[i + 1].length > j + cnt[i][0])
						ok[i + 1][j + cnt[i][0]] = ok[i][j];
					if (ok[i + 1].length > j + cnt[i][1])
						ok[i + 1][j + cnt[i][1]] = ok[i][j];
				}
			}
		}
		long ans = Long.MAX_VALUE / 3;
		for (int i = 0; i < ok[p].length; ++i) {
			if (ok[p][i]) {
				ans = Math.min(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
			}
		}
		System.out.println(ans);
	}

	int p = 0;
	boolean flag = true;

	void dfs(int cur, int par) {
		cnt[p][col[cur]]++;
		for (int dst : g[cur]) {
			if (dst == par)
				continue;
			if (col[dst] == -1) {
				col[dst] = col[cur] ^ 1;
				dfs(dst, cur);
			} else {
				if (col[dst] != (col[cur] ^ 1)) {
					// System.out.println(-1);
					// System.exit(-1);
					flag = false;
				}
			}
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

const int K=26;

signed main()
{
    string s,t; cin>>s>>t;
    
    vector<vector<int>> pos(K);
    for(int i=0;i<s.size();i++){
        pos[s[i]-'a'].push_back(i);
    }

    int ans=0,cur=0;
    for(int i=0;i<t.size();i++){
        if(pos[t[i]-'a'].size()==0){
            cout<<-1<<endl;
            return 0;
        }
        if(pos[t[i]-'a'].back()<cur){
            ans+=s.size()-cur;
            cur=0;
        }
        int nxt=*lower_bound(pos[t[i]-'a'].begin(),pos[t[i]-'a'].end(),cur)+1;
        ans+=nxt-cur;
        cur=nxt;
    }
    cout<<ans<<endl;

    return 0;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

const int mod = 1000000007;
bool is_prime[1000001];

map<ll,int> prime_factor(ll n) {
    map<ll,int> ret;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

ll modpow(ll a, ll b) {
    if (!b) return 1;
    if (b % 2) return (a * modpow(a, b - 1)) % mod;
    ll t = modpow(a, b / 2);
    return (t * t) % mod;
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    map<ll,int> lcm;
    for (int i = 0; i < N; ++i) {
        auto fct = prime_factor(A[i]);
        for (auto &p: fct) {
            lcm[p.first] = max(lcm[p.first], p.second);
        }
    }

    ll L = 1;
    for (auto &p: lcm) {
        L *= modpow(p.first, p.second);
        L %= mod;
    }

    ll res = 0;
    for (int i = 0; i < N; ++i) {
        res += modpow(A[i], mod-2);
        res %= mod;
    }
    res *= L;
    res %= mod;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 896
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,t,a[N],ans,lcm;
char s1[N],s2[N];
signed main(){
	n=read();m=read();
	scanf("%s",s1);scanf("%s",s2);
	lcm=n/__gcd(n,m)*m;
	int p=m-1;
	n=lcm/n;m=lcm/m;
	int pd=1;
	F(i,0,p){
		t=1+i*m;
		if ((t-1)%n==0){
			if (s2[i]!=s1[(t-1)/n]) pd=0;
		}
	}
	if (pd) wrn(lcm);
	else puts("-1");
	return 0;
}

Measured memory_bytes: 384
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define INF 0x3f3f3f3f
#define INFll 0x3f3f3f3f3f3f3f3f
#define y0 _lxybz_
#define y1 _ljmnzyzhhhoscartxdy_
typedef long double ld;
typedef long long ll;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define lo(x) ((x)&(-(x)))
#define trav(a, x) for (auto &a : x)
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
const ld Pi = 4*atan((ld)1);
template<class T> void chmin(T &a,const T&b) { a = min(a, b); }
template<class T> void chmax(T &a,const T&b) { a = max(a, b); }
namespace IO{
template<class T> inline void read(T&ret)
{
	ret=0; int f=1; char c=getchar();
	while(c<48||c>57){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	ret*=f;
}
template<class T> inline void prin(const T&ret)
{
	if(!ret){putchar(48);return;} static T o; o=ret;
	if(o<0){putchar('-');o=-o;}
	static int op[25],tt; tt=0;
	while(o){
		op[++tt]=o%10;
		o/=10;
	}
	for(int i=tt;i;--i)putchar(op[i]+48);
}
template<class T> inline void pri_(const T&ret)
{
	prin(ret);putchar(' ');
}
template<class T> inline void priE(const T&ret)
{
	prin(ret);putchar('\n');
}
}
using namespace IO;

#define N 
#define MO 
ll n,m,p,a,b,c,o;
unsigned long long g[150],f[150];
inline void _Sol_()
{
	read(a);read(b);read(c);
	if(a<b)swap(a,b);
	o=(a-b)*(a-b)-a*c-c*b;
	
	ld _a=sqrt(a),_b=sqrt(b),_c=sqrt(c) ; 
	
	if(_a+_b>_c+0.5){
		puts("No");
		return;
	}
	
	if(_a+_b<_c-0.5){
		puts("Yes");
		return;
	}
	
	
	if(o>=0){
		puts("No");
		return;
	}
	o=-o;
	p=c*c*4;
	ll _o=o;
	while(o){
		f[++n]=o%10;
		o/=10;
	}
	while(p){
		g[++m]=p%10;
		p/=10;
	}
	F(i,1,n)f[i]*=_o;
	F(i,1,m)g[i]*=a*b;
	F(i,1,n)if(f[i]>9){
		f[i+1]+=f[i]/10;
		f[i]%=10;
	}
	while(f[n+1]){
		++n;
		if(f[n]>9){
			f[n+1]+=f[n]/10;
			f[n]%=10;
		}
	}
	F(i,1,m)if(g[i]>9){
		g[i+1]+=g[i]/10;
		g[i]%=10;
	}
	while(g[m+1]){
		++m;
		if(g[m]>9){
			g[m+1]+=g[m]/10;
			g[m]%=10;
		}
	}
	if(n>m){
		puts("Yes");return;
	}
	if(n<m){
		puts("No");return;
	}
	dF(i,n,1){
		if(f[i]>g[i]){
			puts("Yes");return;
		}
		if(f[i]<g[i]){
			puts("No");return;
		}
	}
	puts("No");
}

int main()
{
	int T=1; //read(T);
	while(T--)_Sol_();
}

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

int main()
{
  uint64_t n;
  uint64_t x = 0;
  string s;

  cin >> n;

  s = to_string(n);

  for (int i = 0; i < s.length(); i++) {
    char a = s[i];
    x += atoi(&a);
  }

  if (n % x == 0)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


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

using namespace std;

int main()
{
	int n, k , c; cin >> n >> k >> c;

	string s; cin >> s;

	vector<int> prefix(n, k+5);
	vector<int> suffix(n, k+3);

	int skips = c;
	int dayNumber = 0;


	for(int i = 0; i < n and dayNumber < k; ++i)
	{
		if(skips >= c and s[i] == 'o')
		{
			prefix[i] = dayNumber + 1;
			++dayNumber;
			skips = 0;
		}
		else
		{
			++skips;
		}
	}
	
	if(dayNumber < k)
		return 0;

	skips = c;
	dayNumber = k;

	for(int i = n - 1; i >= 0 and dayNumber ; --i)
	{
		if(skips >= c and s[i] == 'o')
		{
			
			suffix[i] = dayNumber;
			--dayNumber;
			skips = 0;
		}
		else
		{
			++skips;
		}
	}

	int done = 0;
	for(int i = 0; i < n; ++i)
	{
		done = prefix[i];

	

		if(prefix[i] and suffix[i])
		{
		
			if(prefix[i] == suffix[i])
				cout << i + 1 << "\n";
		}
	}

    return 0;
}


Measured memory_bytes: 3332