akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
long long dp[3100][3100];
int n;
long long a[3100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		dp[i][i]=a[i];
	for(int q=1;q<=n-1;q++){
		for(int i=1;i<=n-q;i++){
			int j=i+q;
			dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 73984
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int f[200002]={};
ll d[200002]={};
ll d2[200002]={};
int main() {

	ll n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;

	ll t=0;
	rep(i,s.size()){
		if(s[i]=='x')f[i]=1;
		d[i]=d[i-1];
		if(d[i]==k||s[i]=='x')continue;
		if(t>i)f[i]=1;
		else{
			d[i]++;
			t=i+c+1;
		}
	}

	ll t2=s.size();
	rrep(i,s.size()){
		d2[i]=d2[i+1];
		if(d2[i]==k||s[i]=='x')continue;
		if(t2<i)f[i]=1;
		else{
			d2[i]++;
			t2=i-c-1;
		}

	}
	if(d2[1]<k)cout<<"1"<<endl;
	rep(i,s.size()-1){
		if(d[i]+d2[i+2]<k&&f[i+1]==0)cout<<i+2<<endl;
	}
	return 0;
}


Measured memory_bytes: 4996
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
int n, lim = 1e6, mu[1000007], pm[200007], v1[1000007], v2[1000007], tot[1000007], cnt, res;
bool is[1000007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int fpow(int a, int x)
{
	int res = 1;
	while (x)
	{
		if (x & 1)res = 1LL * res * a % mod;
		a = 1LL * a * a % mod;
		x >>= 1;
	}
	return res;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
		tot[read()]++;
	for (int i = 1; i <= lim; i++)
		res = (res - 1LL * i * tot[i] % mod + mod) % mod;
	for (int i = 1; i <= lim; i++)
		for (int j = 1; i * j <= lim; j++)
			v2[i] = (v2[i] + 1LL * j * tot[i * j] % mod) % mod;
	mu[1] = 1;
	for (int i = 2; i <= lim; i++)
	{
		if (!is[i])pm[++cnt] = i, mu[i] = -1;
		for (int j = 1; j <= cnt && i * pm[j] <= lim; j++)
		{
			is[i * pm[j]] = 1;
			if (i % pm[j] == 0)break;
			mu[i * pm[j]] = -mu[i];
		}
	}
	for (int i = 1; i <= lim; i++)
		for (int j = i; j <= lim; j += i)
			v1[j] = (v1[j] + 1LL * (mu[i] + mod) % mod * i % mod) % mod;
	for (int i = 1; i <= lim; i++)
		res = (res + 1LL * i * v1[i] % mod * v2[i] % mod * v2[i] % mod) % mod;
	res = 499122177LL * res % mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 20452
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;

inline int upb(int n)
{
  /*
  int ret=0;
  while(n>0) ret++, n/=2;
  return ret;
  */
  return 32-__builtin_clz(n);
}

int main()
{
  vector<bool> close(1<<(5*5), false);
  vector<int> cls(1000000);
  int cls_cnt=0;

  for (int n; cin>>n, !(n==0); ){

    vector<vector<int> > pats(n*n+1);
    vector<vector<int> > tmp(n, vector<int>(n, 0));

    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	for (int k=i; k<n; k++){
	  for (int l=j; l<n; l++){
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=1;
	    int bd=0;
	    for (int a=0; a<n; a++){
	      for (int b=0; b<n; b++){
		bd=(bd<<1)|tmp[a][b];
	      }
	    }
	    pats[upb(bd)].push_back(bd);
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=0;
	  }
	}
      }
    }

    int bd=0;
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	int t; cin>>t;
	bd=(bd<<1)|t;
      }
    }

    queue<int> mm;
    mm.push(bd);
    close[bd]=true;
    cls[cls_cnt++]=bd;
    while(!mm.empty()){
      int dep=mm.front()>>25;
      int cbd=mm.front()&0x1ffffff;
      mm.pop();
      //int ub=upb(cbd);
      int ub=32-__builtin_clz(cbd);
      const vector<int> &ps=pats[ub];
      int sz=ps.size();
      for (int i=0; i<sz; i++){
	int nbd=cbd^ps[i];
	if (nbd==0){
	  for (int i=0; i<=dep; i++)
	    cout<<"myon";
	  cout<<endl;
	  goto _exit;
	}
	//cout<<"*** "<<nbd<<endl;
	if (close[nbd]) continue;
	close[nbd]=true;
	cls[cls_cnt++]=nbd;
	mm.push(((dep+1)<<25)|nbd);
      }
    }
  _exit:;
    for (int i=0; i<cls_cnt; i++)
      close[cls[i]]=false;
    cls_cnt=0;
  }
  return 0;
}

Measured memory_bytes: 9232
S = input()

success = False
if S[0] == 'A':
    if 'C' in S[2:-1]:
        ix = S.index('C')
        for i in range(1, len(S)):
            if i != ix:
                if S[i].islower():
                    pass
                else:
                    break
        else:
            success = True
if success:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 40236
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int count = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt() - 1;
        }
        for (int i = 0; i < n; i++) {
            if (a[a[i]] == i) {
                count++;
            }
        }
        System.out.println(count / 2);
    }
}

Measured memory_bytes: 49128
#include <bits/stdc++.h>
#define ll long long

#define TASKNAME ""

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e5 + 7;
const double EPS = 1e-8;
const int LOGN = 30;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
    #endif // MY
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    h = min(h, 2 * q);
    s = min(s, 2 * h);
    d = min(d, 2 * s);
    ll ans = n / 2 * d;
    if (n % 2) {
        ans += s;
    }
    cout << ans;
}


Measured memory_bytes: 764
#ABC116C-GrandGarden.py

N = int(input())
H = input().split()
h = []
r, l = 0, 0
times = 0

for i in range(N):
    h.append(int(H[i]))

h.append(0)

def decidePosition(h):
    m = len(h)
    n = len(h)
    flag = 0
    for i in range(len(h)):
        if h[i] != 0 and flag == 0:
            m = i
            flag = 1
        elif h[i] == 0 and flag == 1:
            n = i
            break
    return m, n

while r != len(h):
    r, l = decidePosition(h)
    for i in range(l-r):
        i += r
        h[i] = h[i] - 1
    times += 1

print(times-1)


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>D(N);
  for(int i=0;i<N;i++)cin>>D[i];
  map<int,int>md;
  for(auto it:D)md[it]++;

  int M;
  cin>>M;
  vector<int>T(M);
  for(int i=0;i<M;i++)cin>>T[i];
  map<int,int>mt;
  for(auto it:T)mt[it]++;

  bool ok=true;
  for(auto it:mt){
    if(it.second>md[it.first])ok=false;
  }

  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384


template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

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

void solve(int n,int m,int p){
	int x,y;
	vvi h(n,vi(n));
	vector<vvi> b(n,vvi(n,vi(n)));
	int col=1;
	bool draw=true;
	rep(q,p){
		cin>>x>>y;
		x--;y--;
		b[h[x][y]][x][y]=col;
		h[x][y]++;
		rep(i,n)rep(j,n)rep(k,n){
			rep(l,13){
				int cnt=0,ii=i,jj=j,kk=k;
				while(draw&&ii>=0&&jj>=0&&kk>=0&&ii<n&&jj<n&&kk<n&&b[ii][jj][kk]==col){
					cnt++;
					ii+=dx[l];jj+=dy[l];kk+=dz[l];
					if(cnt>=m){
						cout<<((q+1)%2==0?"White":"Black")<<" "<<q+1<<endl;
						draw = false;
					}
				}
			}
		}
		col*=-1;
	}
	if(draw)cout<<"Draw"<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,p;
	while(cin>>n>>m>>p,n)solve(n,m,p);
}



Measured memory_bytes: 3156
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();

            var N = cin.nextInt();
            var K = cin.nextInt();

            Console.WriteLine(N-K+1);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

int gcd(int a, int b)
{
	int r = a % b;
	while(r)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

vi T;
void makeTable()
{
	vi prime(1e6 + 1,1);
	prime[2] = prime[3] = 1;
	for(int i = 2; i <= 1e6; i++)
	{
		if(prime[i]) T.pb(i);
		for(int j = 0; j < T.size() && i*T[j] <= 1e6; j++)
		{
			prime[i*T[j]] = 0;
			if(i % T[j] == 0) break;
		}
	}
}

int main()
{
	fastIO;
	int n, m; cin >> n;
	vi vis(1e6 + 5,0);
	for(int i = 0; i < n; i++) cin >> m, vis[m]++;

	makeTable();
	bool flag = true;
	for(auto x : T)
	{
		int cnt = 0;
		for(int i = x; i <= 1e6; i += x)
			cnt += vis[i];

		if(cnt > 1) flag = false;
		if(cnt == n)
		{
			cout << "not coprime" << endl;
			return 0;
		}
	}

	if(flag) cout << "pairwise coprime" << endl;
	else cout << "setwise coprime" << endl;

	return 0;
}

Measured memory_bytes: 11708
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
string s;
int cntR[4001];
int cntG[4001];
int cntB[4001];

signed main() {
	int i, j;
	
	cin >> n >> s;
	
	rep(i, n) {
		if (s[i] == 'R') cntR[i + 1]++;
		if (s[i] == 'G') cntG[i + 1]++;
		if (s[i] == 'B') cntB[i + 1]++;
	}
	rep(i, n) {
		cntR[i + 1] += cntR[i];
		cntG[i + 1] += cntG[i];
		cntB[i + 1] += cntB[i];
	}
	
	int ans = 0;
	rep(i, n) {
		for (j = i + 1; j < n; j++) {
			if (s[i] == s[j]) continue;
			
			char c;
			if (s[i] != 'R' && s[j] != 'R') c = 'R';
			if (s[i] != 'G' && s[j] != 'G') c = 'G';
			if (s[i] != 'B' && s[j] != 'B') c = 'B';
			
			int res;
			if (c == 'R') {
				res = cntR[n] - cntR[j + 1];
			}
			if (c == 'G') {
				res = cntG[n] - cntG[j + 1];
			}
			if (c == 'B') {
				res = cntB[n] - cntB[j + 1];
			}
			if (2 * j - i < n && s[2 * j - i] == c) res--;
			ans += res;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3720
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,m;
  cin >> n >> m;
  int a = m - n;
  int sum =0;
  rep(i,a+1) sum += i;
  cout << sum - m<<endl;
  
  }


Measured memory_bytes: 256
import math

n=int(input())
for i in range(n):
    deta=[float(i) for i in input().split()]
    h1=math.sqrt((deta[2]-deta[0])**2+(deta[3]-deta[1])**2)
    h2=math.sqrt((deta[4]-deta[2])**2+(deta[5]-deta[3])**2)
    h3=math.sqrt((deta[0]-deta[4])**2+(deta[1]-deta[5])**2)
    sub=(h1+h2+h3)/2
    s=math.sqrt(sub*(sub-h1)*(sub-h2)*(sub-h3))
    sum=((h1*h2*h3)/s)/4
    a=2*deta[2]-2*deta[0]
    b=2*deta[3]-2*deta[1]
    c=-(deta[0]**2+deta[1]**2-(deta[2]**2)-(deta[3]**2))
    d=2*deta[4]-2*deta[2]
    e=2*deta[5]-2*deta[3]
    f=-(deta[2]**2+deta[3]**2-(deta[4]**2)-(deta[5]**2))
    
    x=(e*c-b*f)/(a*e-b*d)
    y=(a*f-c*d)/(a*e-b*d)
    print("{0:.3f} {1:.3f} {2:.3f}".format(x,y,sum))

Measured memory_bytes: 7816
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll>t(n);
	vector<ll>a(n);
	for (int i = 0; i < n; ++i)cin >> t[i] >> a[i];
	for (int i = 0; i < n-1; ++i) {
		if (t[i] > t[i + 1] || a[i] > a[i + 1]) {
			ll cul1 = t[i] / t[i + 1];
			if (t[i] % t[i + 1] != 0)cul1++;
			ll cul2 = a[i] / a[i + 1];
			if (a[i] % a[i + 1] != 0)cul2++;
			ll cul = max(cul1, cul2);
			t[i + 1] *= cul; a[i + 1] *= cul;
			}
	}
	cout << t[n - 1] + a[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn
 
object Main {
  def main(args: Array[String]){
    val ss = StdIn.readLine().toInt
    @annotation.tailrec
	def f(t: Int, r: Int, n: Int): (Int, Int) = {
		if (r >= t) f(t, r - t, n + 1) else (n, r)
	}
	val (hh, ss2) = f(3600, ss,  0)
	val (mm, ss3) = f(60,   ss2, 0)
    println(f"${hh}%d:${mm}%d:${ss3}%d")
  }
}


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

int main(){
    int a,b;
    cin>>a>>b;
    
    if ((b-1)%(a-1) == 0){
        cout<< (b-1)/(a-1) << endl;
    }else{
        cout<< (b-1)/(a-1)+1 << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n,0);
    rep(i,n){
        std::cin >> a[i];
        a[i]--;
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        if(i==a[a[i]]) ans++;
    }
    std::cout << ans/2 << "\n";
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

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

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
using boost::multiprecision::cpp_int;

constexpr int N_MAX = 12;
constexpr int FULL = (1ull<<N_MAX) -1;
constexpr int M_MAX = 1001;
int N, M;

vi A;
vi B;
vi C;
ll dp[M_MAX][(1ull<<N_MAX)+10] = {0};


int main(int argc, char** argv) {
  cin >> N >> M;
  A.resize(M);
  B.resize(M);
  C.resize(M);

  for (int i=0; i<M_MAX; i++) {
    for (int j=0; j<int(1ull<<N_MAX)+10; j++) {
      dp[i][j] = (j==0) ? 0 : LINF;
    }
  }

  // key
  for (int i=0; i<M; i++) {
    cin >> A[i] >> B[i];

    ull x = 0;
    for (int j=0; j<B[i]; j++) {
      int c;
      cin >> c;
      c--; // 0-indexed
      x = x | 1ull<<c;
    }
    C[i] = x;
  }

  int full = int(1ull<<N)-1;
//cerr << "full " << full << endl;

  for (int i=0; i<M; i++) {
//cerr << "i " << i << ", full " << dp[i][full] << endl;

    for (ull j=0; j<(1ull<<N); j++) {
      dp[i+1][j] = min({dp[i+1][j], dp[i][j]});

      if (dp[i][j] == LINF) continue;

      ull nextJ = j | C[i];
      if (nextJ == j) {
	continue;
      }

//cerr << j << " -> " << nextJ << ": " << dp[i+1][nextJ] << endl;
      dp[i+1][nextJ] = min({dp[i+1][nextJ], dp[i][j] + A[i]});
//cerr << j << " -> " << nextJ << ": " << dp[i+1][nextJ] << endl;
    }
  }


  if (dp[M][full] == LINF) {
    cout << -1 << endl;
  } else {
    cout << dp[M][full] << endl;
  }

  return 0;
}


Measured memory_bytes: 32384
#include <iostream>                                             
using namespace std;                                            
                                                                
int main() {                                                    
  int a, b;                                                     
  cin >> a >> b;                                                
  int S = a*b;                                                  
  int R = 2*(a+b);                                              
  cout << S << " " << R << endl;                                
  return 0;                                                     
}                        

Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <set>
#include <queue>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int mod = 998244353;
	
int countMod3Renzoku(string s) {
	int i, j, k, l, m, m3 = 0;

	rep(i, s.length()) m3 += (s[i] - 'a');
	m3 %= 3;
	
	static int dp[200001][3][3][2] = {0};	//dp[cnt][mod3][lastChar][flag]
	
	rep(i, 3) dp[1][i][i][0] = 1;
	for (i = 1; i < s.length(); i++) {
		rep(j, 3) {
			rep(k, 3) {
				rep(l, 2) {
					rep(m, 3) {
						dp[i + 1][(j + m) % 3][m][l | (k == m)] += dp[i][j][k][l];
						dp[i + 1][(j + m) % 3][m][l | (k == m)] %= mod;
					}
				}
			}
		}
	}
	
	int ret = 0;
	rep(i, 3) { ret += dp[s.length()][m3][i][1]; ret %= mod; }
	return ret;
}

int allSearch(string s) {
	set<string> dict;
	queue<string> que;
	
	que.push(s);
	dict.insert(s);
	
	while (!que.empty()) {
		string t = que.front(); que.pop();
		int i, j;
		rep(i, (int)t.length() - 1) {
			if (t[i] != t[i + 1]) {
				rep(j, 3) if (j + 'a' != t[i] && j + 'a' != t[i + 1]) break;
				char repl = j + 'a';
				string u = t;
				u[i] = repl;
				u[i + 1] = repl;
				if (dict.find(u) == dict.end()) {
					que.push(u);
					dict.insert(u);
				}
			}
		}
	}
	return dict.size();
}

signed main() {
	string s;
	cin >> s;
	
	int i;
	rep(i, s.length() - 1) if (s[i] != s[i + 1]) break;
	
	if (i == s.length() - 1) { cout << 1 << endl; }
	else if (s.length() <= 3) { cout << allSearch(s) << endl; }
	else {
		int res = countMod3Renzoku(s);
		rep(i, s.length() - 1) if (s[i] == s[i + 1]) break;
		if (i == s.length() - 1) res++;
		res %= mod;
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 28796
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,ans=0;
  cin >> n >> k;
  if(k==0) {
    cout << n*n << endl;
    return 0;
  }
  for(int i=k+1; i<=n; i++) {
    ans+=n/i*(i-k)+max(0LL,n%i-k+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a = 0;
  string s;
  in(s);
  rep(i, s.size()){
    rep2(j, i + 1, s.size()){
      if(s[i] == s[j])
        a++;
    }
  }
  if(a)
    out("no");
  else
    out("yes");
  memi;
}

Measured memory_bytes: 256
// 基本のinclude
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

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

    rep (i, 9){
        if (n / (i+1) < 10 && n / (i+1) > 0 && n == ((i+1) * (n / (i+1)))){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL dp[2][100001];

void solve(long long N, std::vector<long long> A){
    dp[0][0] = A[0];
    dp[1][0] = A[0] * -1;
    REP1(i, N) {
        dp[0][i] = max(dp[0][i-1] + A[i], dp[1][i-1] + A[i] * -1);
        dp[1][i] = max(dp[1][i-1] + A[i], dp[0][i-1] + A[i] * -1);
    }

    cout << dp[0][N-1] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = 1e5+5, MOD = 1e9+7;

int bad[MAXN],dp[MAXN];

int f(int x) {
	if (dp[x] != -1) return dp[x] % MOD;
	if (bad[x]) return dp[x] = 0;
	return dp[x] = (f(x-1) % MOD + f(x-2) % MOD) % MOD;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N,M; cin >> N >> M;
    for (int i = 0; i < M; i++)  {int x; cin >> x; bad[x] = 1;}
    memset(dp,-1,sizeof(dp));
    dp[0] = 1;
    cout << f(N);
    return 0;
}


Measured memory_bytes: 4096
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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

int main(void){
    int n;
    string s;
    int r = 0;
    int l = 0;
    int nowr = 0;
    int nowl = 0;

    cin >> n;
    cin >> s;

    FOR(i,0,s.size()-1){
        if(s[i]=='('){
            l++;
        }else{
            r++;
        }
    }
    FOR(i,0,s.size()-1){
        if(s[i]=='('){
            nowl++;
        }else{
            nowr++;
            if(nowl>0){
                nowl--;
                nowr--;
            }
        }
    }
    FOR(i,1,nowr){
        cout << "(";
    }
    cout << s;
    FOR(i,1,nowl){
        cout << ")";
    }
    cout << endl;
}

Measured memory_bytes: 256
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007
const int N = 3e5+5;

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

long long phi[max1], result[max1],F[max1];
// Precomputation of phi[] numbers. Refer below link
// for details : https://goo.gl/LUqdtY
void computeTotient()
{
    // Refer https://goo.gl/LUqdtY
    phi[1] = 1;
    for (int i=2; i<max1; i++)
    {
        if (!phi[i])
        {
            phi[i] = i-1;
            for (int j = (i<<1); j<max1; j+=i)
            {
                if (!phi[j])
                    phi[j] = j;

                phi[j] = (phi[j]/i)*(i-1);
            }
        }
    }
    for(int i=1;i<=100000;i++)
{
	for(int j=i;j<=100000;j+=i)
	{  int p=j/i;
	F[j]+=(i*phi[p])%mod;
         F[j]%=mod;

          }
}
}

int main()
{

   string s;
   cin>>s;
   for(int i=0;i<3;i++){cout<<s[i];}

}


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



int main() {
    string s, t;
    cin >> s >> t;
    
    int num = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) num++;
    }
    cout << num << endl;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
using namespace std;
namespace io{
	const int Sz=1<<13;
	char ibuf[Sz],*ips=ibuf+Sz-1;
	inline int getchar(){
		if(++ips==ibuf+Sz)fread(ips=ibuf,1,Sz,stdin);
		return *ips;
	}
	char obuf[Sz],*ops=obuf;
	inline void flush(){
		fwrite(obuf,1,ops-obuf,stdout);
		ops=obuf;fflush(stdout);
	}
	inline void putchar(int c){
		if(ops==obuf+Sz)flush();
		*ops=c,ops++;
	}
	void gets(char *s){
		int c=getchar();
		while(c<=32)c=getchar();
		while(c>32)*s=c,++s,c=getchar();
		*s=0;
	}
	void puts(const char *s){
		while(*s)putchar(*s),++s;
	}
}
#define getchar io::getchar
#define putchar io::putchar
#define gets io::gets
#define puts io::puts
int read(){
	int x=0,f=1,c=getchar();
	for(;c<48||c>57;c=getchar())
		if(c=='-')f=-f;
	for(;c>=48&&c<=57;c=getchar())
		x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(ll x){
	int stk[20],tp=0;
	if(!x)putchar(48);
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)stk[tp++]=(x-x/10*10)^48;
	for(;tp;)putchar(stk[--tp]);
}
struct Flusher{~Flusher(){io::flush();}}flusher;
// ------------------------- Template End ------------------------- //
const int N=5005;
int n,A,B;
int p[N],ps[N];
ll dp[N][N],mndp[N][N];
const ll inf=0x3f3f3f3f3f3f3f3f;
void chkmin(ll &x,ll y){if(y<x)x=y;}
int main(){
	n=read(),A=read(),B=read();
	for(int i=0;i<n;++i)p[i]=read(),ps[p[i]]=i;
	memset(dp,0x3f,sizeof dp);dp[0][0]=0;
	memset(mndp,0x3f,sizeof mndp);
	for(int i=0;i<=n;++i)mndp[0][i]=0;
	for(int i=1;i<=n;++i)for(int j=0;j<=n;++j){
		chkmin(dp[i][j],mndp[i-1][j]+(ps[i]==j?0:(ps[i]<j?A:B)));
		if(j)mndp[i][j]=mndp[i][j-1];chkmin(mndp[i][j],dp[i][j]);
	}
	write(mndp[n][n]);putchar('\n');
	return 0;
}



Measured memory_bytes: 391680
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

ll gcd(ll a, ll b) {
    if(a%b==0)
        return b;
    else
        return gcd(b, a%b);
}

int main(void) {
    ll t, i;
    cin >> t;
    ll a[t], b[t], c[t], d[t];

    for(i=0; i<t; i++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    for(i=0; i<t; i++) {
        if(b[i]>a[i]) {
            printf("No\n");
            continue;
        }else if(b[i]>d[i]) {
            printf("No\n");
            continue;
        }else if(c[i]>=b[i]) {
            printf("Yes\n");
            continue;
        }
        ll g=gcd(b[i], d[i]);
        if(c[i]>=b[i]-g+a[i]%g) {
            printf("Yes\n");
        }else {
            printf("No\n");
        }
        
    }

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                int[] x = new int[n];
                int[] q = new int[n];
                for(int i = 0 ; i < n ; i++){
                        x[i] = sc.nextInt();
                        q[i] = x[i];
                }
                sc.close();
                Arrays.sort(q);
                double a = (q[n / 2 - 1] + q[n / 2]) / 2.0;
                for(int i = 0 ; i < n ; i++){
                        if(x[i] < a) System.out.println(q[n / 2]);
                        else System.out.println(q[n / 2 - 1]);
                }
        }
}

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

bool match(char c, char d){
  if(c==d || c=='?') return true;
  else return false;
}

int main(){
  string s,t;
  cin >> s >> t;
  vector<string> vec;

  for (int i = 0; i < (int)s.size(); i++)
  {
    string ss = s;
    bool flg=false;
    if(match(s[i],t[0])){
      for (int j = 0; j < (int)t.size(); j++)
      {
        if(i+j==(int)s.size()) break;
        if(!match(s[i+j],t[j])) break;
        ss[i+j]=t[j];
        if(j==(int)t.size()-1) flg=true;
      }
      if(flg) vec.push_back(ss);
    }
  }
  if(vec.size()==0){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for(int i = 0; i < (int)vec.size(); i++){
    for (int j = 0; j < (int)s.size(); j++)
    {
      if(vec[i][j]=='?'){ 
        vec[i][j]='a';
      }
    }
  }
  sort(vec.begin(),vec.end());
  cout << vec[0] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int a[4];
int b[4];
int i,j;
int hit=0,blow=0;

int main()
{
    while(scanf("%d",&a[0]) != -1)
    {
        for(i = 1;i < 4;i++)
        {
            scanf("%d",&a[i]);
        }
        for(j = 0;j < 4;j++)
        {
            scanf("%d",&b[j]);
        }
        for(i = 0;i < 4;i++)
        {
            if(a[i] == b[i])
            {
                hit++;
                a[i]=10;
                b[i]=10;
            }
            if(a[i] != 10)
            {
                for(j = 0;j < 4;j++)
                {
                    if(a[i] == b[j])
                    {
                        blow++;
                    }
                }
            }
        }
        printf("%d %d\n",hit,blow);
        hit = 0;
        blow = 0;

    }
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main(){
 int n;
 scanf("%d",&n);
 long long ans=0;
 for(int i=1;i<=n;i++){
 if(i%3!=0 && i%5!=0)ans+=i;
 }
 printf("%lld\n",ans);
 }

Measured memory_bytes: 3804
N, M = map(int, input().split())
cakes = tuple(tuple(map(int, input().split())) for _ in range(N))
def make_function(i):
    return lambda t: sum(t[j] * (-1) ** ((i >> j) & 1) for j in range(3))
functions = [make_function(i) for i in range(8)]
print(max(map(sum, (sorted((function(cake) for cake in cakes), reverse=True)[:M] for function in functions))))

Measured memory_bytes: 3260
using System ;

namespace Program{
 class Program{
  static void Main(String []args){
   long N = long.Parse(Console.ReadLine()) ;
   long []ABCDE = new long[5];
   long min = long.MaxValue; 
   for(int i = 0 ; i< 5 ;i++){
	   ABCDE[i] = long.Parse(Console.ReadLine()) ;
       if( min > ABCDE[i] ) min = ABCDE[i];
   }
   
   long result = 5 ;
   result += N / min - 1 ;
   if( N % min != 0 ) result++;
   Console.WriteLine(result);
    
  }
 }
}

Measured memory_bytes: 13140
n = int(input())
s_1 = input()
s_2 = input()
i = 0
count = 1
while i < n:
  if s_1[i] == s_2[i]:
    if i == 0:
      count *= 3
    elif s_1[i-1] == s_2[i - 1]:
      count *= 2
    i += 1
  else:
    if i == 0:
      count *= 6
    elif s_1[i-1] == s_2[i-1]:
      count *= 2
    else:
      count *= 3
    i += 2
    
print(count % (10**9 + 7))
  
    

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

using namespace std;
using ll = long long;

vector<int> st, ed;
vector<int> color;
vector<vector<int>> tree, children;
vector<int> postorder;

void collectInfo(int v, int p) {
	 st[v] = ed[v] = postorder.size();
	for (int ch : tree[v]) {
		if (ch == p) continue;
		children[v].push_back(ch);
		collectInfo(ch, v);
		ed[v] = ed[ch];
	}
	ed[v] = postorder.size();
	postorder.push_back(v);
}

ll pairsInSet(ll x) {
	return x * (x - 1) / 2 + x;
}

int subtreeSize(int i) {
	return ed[i] - st[i] + 1;
}

int main() {
	int n; scanf("%d", &n);
	color = st = ed = vector<int>(n, -1);
	tree = children = vector<vector<int>>(n);
	for (int i = 0; i < n; ++i) scanf("%d", &color[i]);
	for (int i = 0; i < n; ++i) color[i]--;
	for (int i = 0; i < n - 1; ++i) {
		int a, b; scanf("%d %d", &a, &b);
		tree[--a].push_back(--b);
		tree[b].push_back(a);
	}
	collectInfo(0, -1);
	vector<ll> ans(n, pairsInSet(n));
	vector<set<int>> colorants(n); // INDICES INTO POSTORDER
	for (int v : postorder) {
		// get the set of kid vertices with the same color as this one
//		printf("visiting %d\n", v);
//		printf("interval %d %d\n", st[v], ed[v]);
		vector<int> kidsToCheck;
//		printf("%lu active colorants\n", colorants[color[v]].size());
		while (!colorants[color[v]].empty() && *colorants[color[v]].rbegin() >= st[v]) {
			kidsToCheck.push_back(*colorants[color[v]].rbegin());
			colorants[color[v]].erase(kidsToCheck.back());
		}
		reverse(begin(kidsToCheck), end(kidsToCheck));
		for (int &x : kidsToCheck) x = postorder[x]; // now ktc is actually the vertex
		int currentKTC = 0;
		for (int ch : children[v]) {
			ll treeSize = subtreeSize(ch);
			while (currentKTC < kidsToCheck.size() && ed[kidsToCheck[currentKTC]] <= ed[ch]) {
//				printf("%d cancelling %d\n", kidsToCheck[currentKTC], v);
				treeSize -= subtreeSize(kidsToCheck[currentKTC]);
				++currentKTC;
			}
			ans[color[v]] -= pairsInSet(treeSize);
		}
		colorants[color[v]].insert(ed[v]);
	}
	for (int c = 0; c < n; ++c) {
		ll tlcs = n;
		for (int place : colorants[c]) {
			tlcs -= subtreeSize(postorder[place]);
		}
		ans[c] -= pairsInSet(tlcs);
	}
	for (ll x : ans) printf("%lld\n", x);
	return 0;
}


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

int main(){

    int n;
    cin>>n;

    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;







    return 0;
}

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

int main()
{
    string arr;
    cin>>arr;
    int a=0,b=0;
    for(int i=0;i<arr.size();i++)
    {
        if(arr[i]=='A')
        {
            a=i;
            break;
        }
    }
    for(int i=arr.size()-1;i>=0;i--)
    {
        if(arr[i]=='Z')
        {
            b=i;
            break;
        }
    }
    cout<<b-a+1<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>

int main(void)
{
    int n,d,i,j,w=0,l;
    double k;
    int r;

    scanf("%d %d ",&n,&d);

    int a[n][d];
    for(i=0;i<n;i++)
    {
        for(j=0;j<d;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(l=0;l<n-1;l++){
  for(i=l+1;i<n;i++)
    {

        k=0;

        for(j=0;j<d;j++)
        {

           k=k+((a[l][j]-a[i][j])*(a[l][j]-a[i][j]));

        }
        r=sqrt(k);
       if(r*r==k)
        w++;
    }}

    printf("%d",w);

    return 0;
}


Measured memory_bytes: 128
def a_XOR_Circle
    bin_digits = Array.new(1000000000.to_s(2).length+1, 0)

    n = gets.chomp.to_i
    gets.chomp.split(/\s/).map{|x|
        idx = 1
        x.to_i.to_s(2).reverse.each_char do |c|
            bin_digits[idx] += 1 if c == '1'
            idx += 1
        end
    }

    bin_digits.delete_at(0)
    bin_digits.each do |d|
        if d.odd?
            puts 'No'
            exit
        end
    end

    puts 'Yes'
end

a_XOR_Circle


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

int print(char *s, int a, int b){
  for(int i = a; i <= b; i++){
	printf("%c", s[i]);
  }
  printf("\n");
  return 0;
}

char *reverse(char *str, int a, int b){
    char temp[1001];
    int j = 0;
    strcpy(temp, str);

    for(int i = a; i <= b; i++){
        temp[j] = str[i];
        j++;
    }

    j = 0;
    for(int i = b; i >= a; i--){
        str[i] = temp[j];
        j++;
    }

    return str;
}

char *replace(char *s, int a, int b, char *p){
  for(int i = a; i <= b; i++){
	s[i] = *p;
	p++;
  }
  return s;
}

int main(){
  char str[1001];
  int q, a, b;
  char cmd[10];
  char p[1001];

  scanf("%s", str);
  scanf("%d", &q);
  for(int i = 0; i < q; i++){
	scanf("%s", cmd);
	if(!strcmp(cmd,"print")){
	  scanf("%d", &a);
	  scanf("%d", &b);
	  print(str, a, b);
	}else if(!strcmp(cmd,"reverse")){
	  scanf("%d", &a);
	  scanf("%d", &b);
	  reverse(str, a, b);
	}else if(!strcmp(cmd,"replace")){
	  scanf("%d", &a);
	  scanf("%d", &b);
	  scanf("%s", p);
	  replace(str, a, b, p);
	}else{
	  printf("ERROR\n");
	}
  }

  return 0;
}


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

int main () {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  
  bool flag = true;
  map<int, int> count_map;
  rep(i, N) {
    count_map[A[i]] += 1;
    
    if (count_map[A[i]] >= 2) {
      flag = false;
      break;
    }
  }
  
  if (flag) {cout << "YES" << endl;}
  else {cout << "NO" << endl;}
}

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


int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> vec(N, vector<int>(D));
  rep(i, N) {
    rep(j, D) {
      cin >> vec[i][j];
    }
  }
  int ans = 0;
  rep(i, N) {
    rep(j, N) {
      int dd = 0;
      rep(k, D) {
        dd += pow((vec[i][k] - vec[j][k]), 2);
      }
      float d = sqrt(dd);
      if(d - int(d) == 0) ans++;
    }
  }
  ans -= N;
  ans /= 2;
  cout << ans << endl;
  
}


Measured memory_bytes: 256
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] D = new int[N];
        for (int i = 0; i < N; i++) {
            D[i] = sc.nextInt();
        }
        Arrays.sort(D);

        int[] T = new int[N+2];
        T[0] = 0;
        T[N+1] = 24;
        for (int i = 1; i <= N; i++) {
            T[i] = i%2 == 1 ? D[i-1] : 24-D[i-1];
        }
        Arrays.sort(T);

        int min = 24;
        for (int i = 0; i < N+1; i++) {
            min = Math.min(min,T[i+1]-T[i]);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 23764
import sys
input = sys.stdin.readline
from collections import Counter
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix

N,K,L = map(int,input().split())

PQ = [[int(x) for x in input().split()] for _ in range(K)]
RS = [[int(x) for x in input().split()] for _ in range(L)]

P,Q = zip(*PQ)
R,S = zip(*RS)

g1 = csr_matrix(([1]*K,(P,Q)),(N+1,N+1))
g2 = csr_matrix(([1]*L,(R,S)),(N+1,N+1))

_,comp1 = connected_components(g1,directed = False,return_labels = True)
_,comp2 = connected_components(g2,directed = False,return_labels = True)

comp_pair = comp1.astype('int64') * (N+1) + comp2
c = Counter(comp_pair)

answer = [c[comp_pair[i]] for i in range(1,N+1)]
print(*answer)

Measured memory_bytes: 80584
n=int(input())
list1=list(map(int,input().split()))
import fractions
ans=list1[0]
for i in range(1, n):
    ans = ans * list1[i] // fractions.gcd(ans, list1[i])
sum1=0
for i in list1:
    sum1+=ans//i
print(sum1%(10**9+7))

Measured memory_bytes: 5612
# coding: utf-8

s = input()
n = len(s)
m = n // 2

if n%2 == 0:
    x = '01'*m
    y = '10'*m
else:
    x = '01'*m + '0'
    y = '10'*m + '1'

l = [0,0]
for i in range(n):
    if s[i] != x[i]:
        l[0] += 1
    if s[i] != y[i]:
        l[1] += 1

print(min(l))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 2e5+1;
const int mod = 1e9+7;
int subtr[upperlimit];
bool visited[upperlimit];
vi adj[upperlimit];
void dfs(int node){
	visited[node]=true;
	subtr[node]=1;
	for(int i = 0; i < adj[node].size(); i++){
		if(! visited[adj[node][i]]){
			dfs(adj[node][i]);
			subtr[node]+=subtr[adj[node][i]];
		}
	}
}
int main() {
	int n,a,b;
	sd(n);
	ll ans=0;
	for(int i = 1; i < n; i++){
		sd(a);sd(b);
		adj[a].pb(b);adj[b].pb(a);
	}
	dfs(1);
	for(int i = 1; i <= n; i++){
		ll calc=powmod(2,n-1,mod)-1;
		for(int j = 0; j < adj[i].size(); j++){
			if(subtr[adj[i][j]]<subtr[i]) calc-=powmod(2,subtr[adj[i][j]],mod)-1;
			else calc-=powmod(2,n-subtr[i],mod)-1;
			if(calc<0) calc+=mod;
		}
		ans+=calc;ans%=mod;
	}
	ans*=powmod(2,mod-1-n,mod);ans%=mod;
	plld(ans);
	return 0;
}

Measured memory_bytes: 18816
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0, w = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'R') {
      r++;
    } else {
      w++;
    }
  }
  int cr = 0, cw = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'W' && i < r) {
      cw++;
    } else if(s[i] == 'R' && i >= n - w) {
      cr++;
    }
  }
  int ans = max(cw, cr);
  cout << min({r, w, ans}) << endl;
  return 0;
}

Measured memory_bytes: 3676